@dashx/react 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- "use strict";var S=Object.create;var u=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var R=Object.getPrototypeOf,U=Object.prototype.hasOwnProperty;var z=(t,a)=>{for(var r in a)u(t,r,{get:a[r],enumerable:!0})},A=(t,a,r,p)=>{if(a&&typeof a=="object"||typeof a=="function")for(let s of H(a))!U.call(t,s)&&s!==r&&u(t,s,{get:()=>a[s],enumerable:!(p=k(a,s))||p.enumerable});return t};var m=(t,a,r)=>(r=t!=null?S(R(t)):{},A(a||!t||!t.__esModule?u(r,"default",{value:t,enumerable:!0}):r,t)),M=t=>A(u({},"__esModule",{value:!0}),t);var B={};z(B,{InAppChat:()=>b,default:()=>K});module.exports=M(B);var e=require("react/jsx-runtime"),l=m(require("@radix-ui/react-scroll-area")),d=require("react"),c=require("lucide-react"),o=require("../components"),f=require("../utils/cn.js"),I=m(require("../hooks/use-auto-scroll.js")),v=m(require("../hooks/use-in-app-chat.js")),w=m(require("../hooks/use-in-app-chat-notifications.js"));const O=t=>{const a=t.renderedContent;return typeof a=="string"?a:a?.text??""},E=t=>t.aiRole?.toUpperCase()==="USER",b=({messages:t,isLoading:a,error:r,sendMessage:p,withChatHeader:s=!1,withPopoverClose:h=!1,borderless:g=!1,title:N="Chat"})=>{const[i,x]=(0,d.useState)(""),{scrollAreaRef:P,scrollToBottom:y}=(0,I.default)();(0,d.useEffect)(()=>{setTimeout(()=>y({smooth:!0}),0)},[t.length,y]);const C=()=>{i.trim()&&p(i)&&x("")},T=n=>{n.key==="Enter"&&!n.shiftKey&&(n.preventDefault(),C())};return(0,e.jsx)(o.Theme,{asChild:!0,children:(0,e.jsxs)(o.Flex,{direction:"column",className:(0,f.cn)("h-full",!g&&"border border-gray-400/40"),children:[s&&(0,e.jsxs)(o.Flex,{align:"center",justify:"between",className:"border-b border-b-gray-400/40 px-6 py-4",children:[(0,e.jsx)(o.Heading,{size:3,children:N}),h&&(0,e.jsx)(o.Popover.Close,{children:(0,e.jsx)(o.Button,{shape:"square",roundness:"full",variant:"ghost",mode:"subtle",inset:"right",children:(0,e.jsx)(c.X,{})})})]}),(0,e.jsx)(o.Flex,{direction:"column",className:"grow overflow-auto bg-gray-50",children:(0,e.jsxs)(l.Root,{ref:P,className:"h-full grow-1 p-6",children:[(0,e.jsx)(l.Viewport,{className:"h-full",children:(0,e.jsxs)(o.Flex,{direction:"column",gap:3,children:[t.map(n=>(0,e.jsx)("div",{className:(0,f.cn)("max-w-[80%] rounded-lg py-2 px-3",E(n)?"bg-accent-600 ml-auto items-end text-white":"bg-gray-200 mr-auto items-start text-gray-900"),children:(0,e.jsx)(o.Text,{as:"p",size:2,children:O(n)})},n.externalUid||n.id)),a&&(0,e.jsx)(o.Text,{as:"p",size:2,className:"mr-auto text-gray-500",children:"Loading\u2026"}),r&&(0,e.jsx)(o.Text,{as:"p",size:2,className:"bg-negative-100 text-negative-900 mx-auto rounded-lg py-2 px-3",children:r})]})}),(0,e.jsx)(l.Scrollbar,{orientation:"vertical",className:"w-1 bg-gray-200 opacity-50",children:(0,e.jsx)(l.Thumb,{className:"flex-1 rounded-2xl bg-gray-400"})}),(0,e.jsx)(l.Corner,{})]})}),(0,e.jsx)("div",{className:"shrink-0 grow-0 border-t border-t-gray-400/40",children:(0,e.jsxs)(o.Flex,{gap:2,align:"end",className:"w-full",children:[(0,e.jsx)("div",{className:"w-full [&_textarea]:!border-none [&_textarea]:!outline-none",children:(0,e.jsx)(o.TextArea,{"aria-label":"message",size:"extralarge",placeholder:"Type a message\u2026",value:i,onKeyDown:T,onChange:n=>x(n),roundness:"none",autogrow:!0})}),(0,e.jsx)("div",{className:"mr-[7px] mb-[7px]",children:(0,e.jsx)(o.Button,{shape:"square",roundness:"full",variant:"fill",size:"medium",onPress:C,isDisabled:!i.trim(),children:(0,e.jsx)(c.Send,{size:20})})})]})})]})})},F=({identityId:t,idempotencyKey:a,initialMessage:r,notifications:p=!0,...s})=>{const h=(0,w.default)({isOpen:!0,enabled:p!==!1,options:{requestPermissionOn:"manual",...typeof p=="object"?p:void 0}}),g=(0,v.default)({identityId:t,idempotencyKey:a,initialMessage:r,onInboundMessage:h.handleInboundMessage});return(0,e.jsx)(b,{...g,...s})};var K=F;
1
+ "use strict";var S=Object.create;var u=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var R=Object.getPrototypeOf,U=Object.prototype.hasOwnProperty;var z=(t,a)=>{for(var r in a)u(t,r,{get:a[r],enumerable:!0})},A=(t,a,r,p)=>{if(a&&typeof a=="object"||typeof a=="function")for(let s of H(a))!U.call(t,s)&&s!==r&&u(t,s,{get:()=>a[s],enumerable:!(p=k(a,s))||p.enumerable});return t};var m=(t,a,r)=>(r=t!=null?S(R(t)):{},A(a||!t||!t.__esModule?u(r,"default",{value:t,enumerable:!0}):r,t)),M=t=>A(u({},"__esModule",{value:!0}),t);var B={};z(B,{InAppChat:()=>b,default:()=>K});module.exports=M(B);var e=require("react/jsx-runtime"),l=m(require("@radix-ui/react-scroll-area")),d=require("react"),c=require("lucide-react"),o=require("../components"),f=require("../utils/cn.js"),I=m(require("../hooks/use-auto-scroll.js")),v=m(require("../hooks/use-in-app-chat.js")),w=m(require("../hooks/use-in-app-chat-notifications.js"));const O=t=>{const a=t.renderedContent;return typeof a=="string"?a:a?.text??""},E=t=>t.aiRole?.toUpperCase()==="USER",b=({messages:t,isLoading:a,error:r,sendMessage:p,withChatHeader:s=!1,withPopoverClose:h=!1,borderless:g=!1,title:N="Chat"})=>{const[i,x]=(0,d.useState)(""),{scrollAreaRef:P,scrollToBottom:y}=(0,I.default)();(0,d.useEffect)(()=>{setTimeout(()=>y({smooth:!0}),0)},[t.length,y]);const C=()=>{i.trim()&&p(i)&&x("")},T=n=>{n.key==="Enter"&&!n.shiftKey&&(n.preventDefault(),C())};return(0,e.jsx)(o.Theme,{asChild:!0,children:(0,e.jsxs)(o.Flex,{direction:"column",className:(0,f.cn)("h-full",!g&&"border border-gray-400/40"),children:[s&&(0,e.jsxs)(o.Flex,{align:"center",justify:"between",className:"border-b border-b-gray-400/40 px-6 py-4",children:[(0,e.jsx)(o.Heading,{size:3,children:N}),h&&(0,e.jsx)(o.Popover.Close,{children:(0,e.jsx)(o.Button,{shape:"square",roundness:"full",variant:"ghost",mode:"subtle",inset:"right",children:(0,e.jsx)(c.X,{})})})]}),(0,e.jsx)(o.Flex,{direction:"column",className:"grow overflow-auto bg-gray-50",children:(0,e.jsxs)(l.Root,{ref:P,className:"h-full grow p-6",children:[(0,e.jsx)(l.Viewport,{className:"h-full",children:(0,e.jsxs)(o.Flex,{direction:"column",gap:3,children:[t.map(n=>(0,e.jsx)("div",{className:(0,f.cn)("max-w-[80%] rounded-lg py-2 px-3",E(n)?"bg-accent-600 ml-auto items-end text-white":"bg-gray-200 mr-auto items-start text-gray-900"),children:(0,e.jsx)(o.Text,{as:"p",size:2,children:O(n)})},n.externalUid||n.id)),a&&(0,e.jsx)(o.Text,{as:"p",size:2,className:"mr-auto text-gray-500",children:"Loading\u2026"}),r&&(0,e.jsx)(o.Text,{as:"p",size:2,className:"bg-negative-100 text-negative-900 mx-auto rounded-lg py-2 px-3",children:r})]})}),(0,e.jsx)(l.Scrollbar,{orientation:"vertical",className:"w-1 bg-gray-200 opacity-50",children:(0,e.jsx)(l.Thumb,{className:"flex-1 rounded-2xl bg-gray-400"})}),(0,e.jsx)(l.Corner,{})]})}),(0,e.jsx)("div",{className:"shrink-0 grow-0 border-t border-t-gray-400/40",children:(0,e.jsxs)(o.Flex,{gap:2,align:"end",className:"w-full",children:[(0,e.jsx)("div",{className:"w-full [&_textarea]:border-none! [&_textarea]:outline-none!",children:(0,e.jsx)(o.TextArea,{"aria-label":"message",size:"extralarge",placeholder:"Type a message\u2026",value:i,onKeyDown:T,onChange:n=>x(n),roundness:"none",autogrow:!0})}),(0,e.jsx)("div",{className:"mr-[7px] mb-[7px]",children:(0,e.jsx)(o.Button,{shape:"square",roundness:"full",variant:"fill",size:"medium",onPress:C,isDisabled:!i.trim(),children:(0,e.jsx)(c.Send,{size:20})})})]})})]})})},F=({identityId:t,idempotencyKey:a,initialMessage:r,notifications:p=!0,...s})=>{const h=(0,w.default)({isOpen:!0,enabled:p!==!1,options:{requestPermissionOn:"manual",...typeof p=="object"?p:void 0}}),g=(0,v.default)({identityId:t,idempotencyKey:a,initialMessage:r,onInboundMessage:h.handleInboundMessage});return(0,e.jsx)(b,{...g,...s})};var K=F;
2
2
  //# sourceMappingURL=InAppChat.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/widgets/InAppChat.tsx"],
4
- "sourcesContent": ["import * as ScrollArea from '@radix-ui/react-scroll-area';\nimport React, { useEffect, useState } from 'react';\nimport { Send, X } from 'lucide-react';\nimport type { KeyboardEvent } from 'react';\n\nimport { Button, Flex, Heading, Popover, Text, TextArea, Theme } from '../components';\nimport { cn } from '../utils/cn.js';\nimport useAutoScroll from '../hooks/use-auto-scroll.js';\nimport useInAppChat, {\n type InAppChatMessage,\n type UseInAppChatHookProps,\n type UseInAppChatHookResponse,\n} from '../hooks/use-in-app-chat.js';\nimport useInAppChatNotifications, {\n type InAppChatNotificationOptions,\n} from '../hooks/use-in-app-chat-notifications.js';\n\ntype InAppChatProps = UseInAppChatHookResponse & {\n withChatHeader?: boolean;\n withPopoverClose?: boolean;\n borderless?: boolean;\n title?: string;\n};\n\nconst messageText = (message: InAppChatMessage): string => {\n const content = message.renderedContent;\n if (typeof content === 'string') return content;\n return content?.text ?? '';\n};\n\nconst isOutgoing = (message: InAppChatMessage): boolean => message.aiRole?.toUpperCase() === 'USER';\n\nconst InAppChat = ({\n messages,\n isLoading,\n error,\n sendMessage,\n withChatHeader = false,\n withPopoverClose = false,\n borderless = false,\n title = 'Chat',\n}: InAppChatProps) => {\n const [inputValue, setInputValue] = useState('');\n const { scrollAreaRef, scrollToBottom } = useAutoScroll();\n\n useEffect(() => {\n setTimeout(() => scrollToBottom({ smooth: true }), 0);\n }, [messages.length, scrollToBottom]);\n\n const handleSubmit = () => {\n if (!inputValue.trim()) return;\n // `sendMessage` is synchronous: it returns true the instant the message is\n // optimistically queued (network send runs in the background). Clear the\n // composer right away on success so a fast second Enter can't re-send the same\n // text as a duplicate; on false (chat not ready) keep the visitor's text.\n if (sendMessage(inputValue)) setInputValue('');\n };\n\n const handleKeyDown = (e: KeyboardEvent<HTMLTextAreaElement>) => {\n if (e.key === 'Enter' && !e.shiftKey) {\n e.preventDefault();\n handleSubmit();\n }\n };\n\n return (\n <Theme asChild>\n <Flex direction=\"column\" className={cn('h-full', !borderless && 'border border-gray-400/40')}>\n {withChatHeader && (\n <Flex align=\"center\" justify=\"between\" className=\"border-b border-b-gray-400/40 px-6 py-4\">\n <Heading size={3}>{title}</Heading>\n {withPopoverClose && (\n <Popover.Close>\n <Button shape=\"square\" roundness=\"full\" variant=\"ghost\" mode=\"subtle\" inset=\"right\">\n <X />\n </Button>\n </Popover.Close>\n )}\n </Flex>\n )}\n\n <Flex direction=\"column\" className=\"grow overflow-auto bg-gray-50\">\n <ScrollArea.Root ref={scrollAreaRef} className=\"h-full grow-1 p-6\">\n <ScrollArea.Viewport className=\"h-full\">\n <Flex direction=\"column\" gap={3}>\n {messages.map((message) => (\n <div\n key={message.externalUid || message.id}\n className={cn(\n 'max-w-[80%] rounded-lg py-2 px-3',\n isOutgoing(message)\n ? 'bg-accent-600 ml-auto items-end text-white'\n : 'bg-gray-200 mr-auto items-start text-gray-900',\n )}\n >\n <Text as=\"p\" size={2}>{messageText(message)}</Text>\n </div>\n ))}\n\n {isLoading && (\n <Text as=\"p\" size={2} className=\"mr-auto text-gray-500\">\n Loading\u2026\n </Text>\n )}\n\n {error && (\n <Text\n as=\"p\"\n size={2}\n className=\"bg-negative-100 text-negative-900 mx-auto rounded-lg py-2 px-3\"\n >\n {error}\n </Text>\n )}\n </Flex>\n </ScrollArea.Viewport>\n <ScrollArea.Scrollbar orientation=\"vertical\" className=\"w-1 bg-gray-200 opacity-50\">\n <ScrollArea.Thumb className=\"flex-1 rounded-2xl bg-gray-400\" />\n </ScrollArea.Scrollbar>\n <ScrollArea.Corner />\n </ScrollArea.Root>\n </Flex>\n\n <div className=\"shrink-0 grow-0 border-t border-t-gray-400/40\">\n <Flex gap={2} align=\"end\" className=\"w-full\">\n <div className=\"w-full [&_textarea]:!border-none [&_textarea]:!outline-none\">\n <TextArea\n aria-label=\"message\"\n size=\"extralarge\"\n placeholder=\"Type a message\u2026\"\n value={inputValue}\n onKeyDown={handleKeyDown}\n onChange={(text) => setInputValue(text)}\n roundness=\"none\"\n autogrow\n />\n </div>\n <div className=\"mr-[7px] mb-[7px]\">\n <Button\n shape=\"square\"\n roundness=\"full\"\n variant=\"fill\"\n size=\"medium\"\n onPress={handleSubmit}\n isDisabled={!inputValue.trim()}\n >\n <Send size={20} />\n </Button>\n </div>\n </Flex>\n </div>\n </Flex>\n </Theme>\n );\n};\n\ntype InAppChatWrapperProps = Omit<InAppChatProps, keyof UseInAppChatHookResponse>\n & Omit<UseInAppChatHookProps, 'enabled' | 'onInboundMessage'>\n & {\n // Foreground browser notifications for incoming agent/AI messages while the\n // chat isn't focused. `false` disables; an object customizes title/icon/body.\n // Default: enabled but silent until permission is granted (this always-visible\n // surface never auto-prompts \u2014 call `Client.requestNotificationPermission()`\n // from your own UI, or use `<InAppChatButton>` which prompts on first open).\n notifications?: boolean | InAppChatNotificationOptions;\n };\n\nconst InAppChatWrapper = ({ identityId, idempotencyKey, initialMessage, notifications = true, ...props }: InAppChatWrapperProps) => {\n // Always-visible surface: treat as \"open\" and gate notifications on tab\n // visibility/focus only. No launcher gesture exists here, so default to\n // 'manual' permission (auto-requesting would prompt on mount).\n const notifier = useInAppChatNotifications({\n isOpen: true,\n enabled: notifications !== false,\n options: {\n requestPermissionOn: 'manual',\n ...(typeof notifications === 'object' ? notifications : undefined),\n },\n });\n const chat = useInAppChat({\n identityId,\n idempotencyKey,\n initialMessage,\n onInboundMessage: notifier.handleInboundMessage,\n });\n return <InAppChat {...chat} {...props} />;\n};\n\nexport type { InAppChatProps, InAppChatWrapperProps };\n\nexport { InAppChat };\n\nexport default InAppChatWrapper;\n"],
5
- "mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,eAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GAqEU,IAAAK,EAAA,6BArEVC,EAA4B,0CAC5BC,EAA2C,iBAC3CC,EAAwB,wBAGxBC,EAAsE,yBACtEC,EAAmB,0BACnBC,EAA0B,0CAC1BC,EAIO,0CACPC,EAEO,wDASP,MAAMC,EAAeC,GAAsC,CACzD,MAAMC,EAAUD,EAAQ,gBACxB,OAAI,OAAOC,GAAY,SAAiBA,EACjCA,GAAS,MAAQ,EAC1B,EAEMC,EAAcF,GAAuCA,EAAQ,QAAQ,YAAY,IAAM,OAEvFb,EAAY,CAAC,CACjB,SAAAgB,EACA,UAAAC,EACA,MAAAC,EACA,YAAAC,EACA,eAAAC,EAAiB,GACjB,iBAAAC,EAAmB,GACnB,WAAAC,EAAa,GACb,MAAAC,EAAQ,MACV,IAAsB,CACpB,KAAM,CAACC,EAAYC,CAAa,KAAI,YAAS,EAAE,EACzC,CAAE,cAAAC,EAAe,eAAAC,CAAe,KAAI,EAAAC,SAAc,KAExD,aAAU,IAAM,CACd,WAAW,IAAMD,EAAe,CAAE,OAAQ,EAAK,CAAC,EAAG,CAAC,CACtD,EAAG,CAACX,EAAS,OAAQW,CAAc,CAAC,EAEpC,MAAME,EAAe,IAAM,CACpBL,EAAW,KAAK,GAKjBL,EAAYK,CAAU,GAAGC,EAAc,EAAE,CAC/C,EAEMK,EAAiBC,GAA0C,CAC3DA,EAAE,MAAQ,SAAW,CAACA,EAAE,WAC1BA,EAAE,eAAe,EACjBF,EAAa,EAEjB,EAEA,SACE,OAAC,SAA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EACF,KACA,OAAC,OAAI,UAAU,oBACb,mBAAC,UACC,MAAM,SACN,UAAU,OACV,QAAQ,OACR,KAAK,SACL,QAASH,EACT,WAAY,CAACL,EAAW,KAAK,EAE7B,mBAAC,QAAK,KAAM,GAAI,EAClB,EACF,GACF,EACF,GACF,EACF,CAEJ,EAaMS,EAAmB,CAAC,CAAE,WAAAC,EAAY,eAAAC,EAAgB,eAAAC,EAAgB,cAAAC,EAAgB,GAAM,GAAGC,CAAM,IAA6B,CAIlI,MAAMC,KAAW,EAAAC,SAA0B,CACzC,OAAQ,GACR,QAASH,IAAkB,GAC3B,QAAS,CACP,oBAAqB,SACrB,GAAI,OAAOA,GAAkB,SAAWA,EAAgB,MAC1D,CACF,CAAC,EACKI,KAAO,EAAAC,SAAa,CACxB,WAAAR,EACA,eAAAC,EACA,eAAAC,EACA,iBAAkBG,EAAS,oBAC7B,CAAC,EACD,SAAO,OAACvC,EAAA,CAAW,GAAGyC,EAAO,GAAGH,EAAO,CACzC,EAMA,IAAOrC,EAAQgC",
4
+ "sourcesContent": ["import * as ScrollArea from '@radix-ui/react-scroll-area';\nimport React, { useEffect, useState } from 'react';\nimport { Send, X } from 'lucide-react';\nimport type { KeyboardEvent } from 'react';\n\nimport { Button, Flex, Heading, Popover, Text, TextArea, Theme } from '../components';\nimport { cn } from '../utils/cn.js';\nimport useAutoScroll from '../hooks/use-auto-scroll.js';\nimport useInAppChat, {\n type InAppChatMessage,\n type UseInAppChatHookProps,\n type UseInAppChatHookResponse,\n} from '../hooks/use-in-app-chat.js';\nimport useInAppChatNotifications, {\n type InAppChatNotificationOptions,\n} from '../hooks/use-in-app-chat-notifications.js';\n\ntype InAppChatProps = UseInAppChatHookResponse & {\n withChatHeader?: boolean;\n withPopoverClose?: boolean;\n borderless?: boolean;\n title?: string;\n};\n\nconst messageText = (message: InAppChatMessage): string => {\n const content = message.renderedContent;\n if (typeof content === 'string') return content;\n return content?.text ?? '';\n};\n\nconst isOutgoing = (message: InAppChatMessage): boolean => message.aiRole?.toUpperCase() === 'USER';\n\nconst InAppChat = ({\n messages,\n isLoading,\n error,\n sendMessage,\n withChatHeader = false,\n withPopoverClose = false,\n borderless = false,\n title = 'Chat',\n}: InAppChatProps) => {\n const [inputValue, setInputValue] = useState('');\n const { scrollAreaRef, scrollToBottom } = useAutoScroll();\n\n useEffect(() => {\n setTimeout(() => scrollToBottom({ smooth: true }), 0);\n }, [messages.length, scrollToBottom]);\n\n const handleSubmit = () => {\n if (!inputValue.trim()) return;\n // `sendMessage` is synchronous: it returns true the instant the message is\n // optimistically queued (network send runs in the background). Clear the\n // composer right away on success so a fast second Enter can't re-send the same\n // text as a duplicate; on false (chat not ready) keep the visitor's text.\n if (sendMessage(inputValue)) setInputValue('');\n };\n\n const handleKeyDown = (e: KeyboardEvent<HTMLTextAreaElement>) => {\n if (e.key === 'Enter' && !e.shiftKey) {\n e.preventDefault();\n handleSubmit();\n }\n };\n\n return (\n <Theme asChild>\n <Flex direction=\"column\" className={cn('h-full', !borderless && 'border border-gray-400/40')}>\n {withChatHeader && (\n <Flex align=\"center\" justify=\"between\" className=\"border-b border-b-gray-400/40 px-6 py-4\">\n <Heading size={3}>{title}</Heading>\n {withPopoverClose && (\n <Popover.Close>\n <Button shape=\"square\" roundness=\"full\" variant=\"ghost\" mode=\"subtle\" inset=\"right\">\n <X />\n </Button>\n </Popover.Close>\n )}\n </Flex>\n )}\n\n <Flex direction=\"column\" className=\"grow overflow-auto bg-gray-50\">\n <ScrollArea.Root ref={scrollAreaRef} className=\"h-full grow p-6\">\n <ScrollArea.Viewport className=\"h-full\">\n <Flex direction=\"column\" gap={3}>\n {messages.map((message) => (\n <div\n key={message.externalUid || message.id}\n className={cn(\n 'max-w-[80%] rounded-lg py-2 px-3',\n isOutgoing(message)\n ? 'bg-accent-600 ml-auto items-end text-white'\n : 'bg-gray-200 mr-auto items-start text-gray-900',\n )}\n >\n <Text as=\"p\" size={2}>{messageText(message)}</Text>\n </div>\n ))}\n\n {isLoading && (\n <Text as=\"p\" size={2} className=\"mr-auto text-gray-500\">\n Loading\u2026\n </Text>\n )}\n\n {error && (\n <Text\n as=\"p\"\n size={2}\n className=\"bg-negative-100 text-negative-900 mx-auto rounded-lg py-2 px-3\"\n >\n {error}\n </Text>\n )}\n </Flex>\n </ScrollArea.Viewport>\n <ScrollArea.Scrollbar orientation=\"vertical\" className=\"w-1 bg-gray-200 opacity-50\">\n <ScrollArea.Thumb className=\"flex-1 rounded-2xl bg-gray-400\" />\n </ScrollArea.Scrollbar>\n <ScrollArea.Corner />\n </ScrollArea.Root>\n </Flex>\n\n <div className=\"shrink-0 grow-0 border-t border-t-gray-400/40\">\n <Flex gap={2} align=\"end\" className=\"w-full\">\n <div className=\"w-full [&_textarea]:border-none! [&_textarea]:outline-none!\">\n <TextArea\n aria-label=\"message\"\n size=\"extralarge\"\n placeholder=\"Type a message\u2026\"\n value={inputValue}\n onKeyDown={handleKeyDown}\n onChange={(text) => setInputValue(text)}\n roundness=\"none\"\n autogrow\n />\n </div>\n <div className=\"mr-[7px] mb-[7px]\">\n <Button\n shape=\"square\"\n roundness=\"full\"\n variant=\"fill\"\n size=\"medium\"\n onPress={handleSubmit}\n isDisabled={!inputValue.trim()}\n >\n <Send size={20} />\n </Button>\n </div>\n </Flex>\n </div>\n </Flex>\n </Theme>\n );\n};\n\ntype InAppChatWrapperProps = Omit<InAppChatProps, keyof UseInAppChatHookResponse>\n & Omit<UseInAppChatHookProps, 'enabled' | 'onInboundMessage'>\n & {\n // Foreground browser notifications for incoming agent/AI messages while the\n // chat isn't focused. `false` disables; an object customizes title/icon/body.\n // Default: enabled but silent until permission is granted (this always-visible\n // surface never auto-prompts \u2014 call `Client.requestNotificationPermission()`\n // from your own UI, or use `<InAppChatButton>` which prompts on first open).\n notifications?: boolean | InAppChatNotificationOptions;\n };\n\nconst InAppChatWrapper = ({ identityId, idempotencyKey, initialMessage, notifications = true, ...props }: InAppChatWrapperProps) => {\n // Always-visible surface: treat as \"open\" and gate notifications on tab\n // visibility/focus only. No launcher gesture exists here, so default to\n // 'manual' permission (auto-requesting would prompt on mount).\n const notifier = useInAppChatNotifications({\n isOpen: true,\n enabled: notifications !== false,\n options: {\n requestPermissionOn: 'manual',\n ...(typeof notifications === 'object' ? notifications : undefined),\n },\n });\n const chat = useInAppChat({\n identityId,\n idempotencyKey,\n initialMessage,\n onInboundMessage: notifier.handleInboundMessage,\n });\n return <InAppChat {...chat} {...props} />;\n};\n\nexport type { InAppChatProps, InAppChatWrapperProps };\n\nexport { InAppChat };\n\nexport default InAppChatWrapper;\n"],
5
+ "mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,eAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GAqEU,IAAAK,EAAA,6BArEVC,EAA4B,0CAC5BC,EAA2C,iBAC3CC,EAAwB,wBAGxBC,EAAsE,yBACtEC,EAAmB,0BACnBC,EAA0B,0CAC1BC,EAIO,0CACPC,EAEO,wDASP,MAAMC,EAAeC,GAAsC,CACzD,MAAMC,EAAUD,EAAQ,gBACxB,OAAI,OAAOC,GAAY,SAAiBA,EACjCA,GAAS,MAAQ,EAC1B,EAEMC,EAAcF,GAAuCA,EAAQ,QAAQ,YAAY,IAAM,OAEvFb,EAAY,CAAC,CACjB,SAAAgB,EACA,UAAAC,EACA,MAAAC,EACA,YAAAC,EACA,eAAAC,EAAiB,GACjB,iBAAAC,EAAmB,GACnB,WAAAC,EAAa,GACb,MAAAC,EAAQ,MACV,IAAsB,CACpB,KAAM,CAACC,EAAYC,CAAa,KAAI,YAAS,EAAE,EACzC,CAAE,cAAAC,EAAe,eAAAC,CAAe,KAAI,EAAAC,SAAc,KAExD,aAAU,IAAM,CACd,WAAW,IAAMD,EAAe,CAAE,OAAQ,EAAK,CAAC,EAAG,CAAC,CACtD,EAAG,CAACX,EAAS,OAAQW,CAAc,CAAC,EAEpC,MAAME,EAAe,IAAM,CACpBL,EAAW,KAAK,GAKjBL,EAAYK,CAAU,GAAGC,EA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,UAAU,8DACb,mBAAC,YACC,aAAW,UACX,KAAK,aACL,YAAY,uBACZ,MAAOoB,EACP,UAAWM,EACX,SAAWE,GAASP,EAAcO,CAAI,EACtC,UAAU,OACV,SAAQ,GACV,EACF,KACA,OAAC,OAAI,UAAU,oBACb,mBAAC,UACC,MAAM,SACN,UAAU,OACV,QAAQ,OACR,KAAK,SACL,QAASH,EACT,WAAY,CAACL,EAAW,KAAK,EAE7B,mBAAC,QAAK,KAAM,GAAI,EAClB,EACF,GACF,EACF,GACF,EACF,CAEJ,EAaMS,EAAmB,CAAC,CAAE,WAAAC,EAAY,eAAAC,EAAgB,eAAAC,EAAgB,cAAAC,EAAgB,GAAM,GAAGC,CAAM,IAA6B,CAIlI,MAAMC,KAAW,EAAAC,SAA0B,CACzC,OAAQ,GACR,QAASH,IAAkB,GAC3B,QAAS,CACP,oBAAqB,SACrB,GAAI,OAAOA,GAAkB,SAAWA,EAAgB,MAC1D,CACF,CAAC,EACKI,KAAO,EAAAC,SAAa,CACxB,WAAAR,EACA,eAAAC,EACA,eAAAC,EACA,iBAAkBG,EAAS,oBAC7B,CAAC,EACD,SAAO,OAACvC,EAAA,CAAW,GAAGyC,EAAO,GAAGH,EAAO,CACzC,EAMA,IAAOrC,EAAQgC",
6
6
  "names": ["InAppChat_exports", "__export", "InAppChat", "InAppChat_default", "__toCommonJS", "import_jsx_runtime", "ScrollArea", "import_react", "import_lucide_react", "import_components", "import_cn", "import_use_auto_scroll", "import_use_in_app_chat", "import_use_in_app_chat_notifications", "messageText", "message", "content", "isOutgoing", "messages", "isLoading", "error", "sendMessage", "withChatHeader", "withPopoverClose", "borderless", "title", "inputValue", "setInputValue", "scrollAreaRef", "scrollToBottom", "useAutoScroll", "handleSubmit", "handleKeyDown", "e", "text", "InAppChatWrapper", "identityId", "idempotencyKey", "initialMessage", "notifications", "props", "notifier", "useInAppChatNotifications", "chat", "useInAppChat"]
7
7
  }
@@ -0,0 +1,2 @@
1
+ declare const NotificationBell: () => import("react/jsx-runtime").JSX.Element;
2
+ export default NotificationBell;
@@ -0,0 +1,2 @@
1
+ "use strict";var l=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var m=(a,r)=>{for(var n in r)l(a,n,{get:r[n],enumerable:!0})},T=(a,r,n,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of u(r))!c.call(a,o)&&o!==n&&l(a,o,{get:()=>r[o],enumerable:!(s=g(r,o))||s.enumerable});return a};var h=a=>T(l({},"__esModule",{value:!0}),a);var f={};m(f,{default:()=>x});module.exports=h(f);var t=require("react/jsx-runtime"),d=require("date-fns"),p=require("../hooks/index.js"),e=require("../components"),i=require("../icons/index.js");const v=()=>{let{markNotificationAsRead:a,markNotificationAsUnread:r,notifications:n,unreadNotificationsCount:s}=(0,p.useInApp)();return(0,t.jsx)(e.Theme,{children:(0,t.jsxs)(e.Popover.Root,{children:[(0,t.jsxs)(e.Tooltip.Root,{children:[(0,t.jsx)(e.Tooltip.Trigger,{children:(0,t.jsx)(e.Popover.Trigger,{children:(0,t.jsx)(e.Button,{shape:"square",roundness:"full",variant:s?"fill":"ghost",children:(0,t.jsx)(i.Inbox,{})})})}),(0,t.jsx)(e.Tooltip.Content,{content:"Notification"})]}),(0,t.jsxs)(e.Popover.Content,{spacing:"large",width:"350px",height:"450px",children:[(0,t.jsx)(e.Popover.Header,{asChild:!0,children:(0,t.jsxs)(e.Flex,{justify:"between",align:"center",children:[(0,t.jsx)(e.Heading,{size:3,children:"Notifications"}),(0,t.jsx)(e.Popover.Close,{children:(0,t.jsx)(e.Button,{shape:"square",roundness:"full",variant:"ghost",mode:"subtle",inset:"right",children:(0,t.jsx)(i.X,{})})})]})}),(0,t.jsx)(e.Popover.Body,{children:(0,t.jsxs)(e.Flex,{direction:"column",gap:1,children:[n.length===0&&(0,t.jsx)(e.Flex,{justify:"center",align:"center",children:(0,t.jsx)(e.Text,{variant:"tertiary",size:2,children:"No notifications yet."})}),n.map(o=>(0,t.jsx)(e.Card,{children:(0,t.jsxs)(e.Flex,{align:"center",gap:4,justify:"between",children:[(0,t.jsxs)(e.Flex,{direction:"column",gap:1,children:[(0,t.jsx)(e.Text,{as:"p",variant:"secondary",weight:"semibold",size:2,children:o.renderedContent.body}),(0,t.jsx)(e.Text,{size:1,variant:"tertiary",children:(0,d.intlFormatDistance)(o.sentAt,new Date)})]}),(0,t.jsxs)(e.Tooltip.Root,{children:[(0,t.jsx)(e.Tooltip.Trigger,{children:(0,t.jsx)(e.Button,{shape:"square",variant:"ghost",roundness:"full",mode:o.readAt?"subtle":"distinct",onPress:()=>{o.readAt?r(o.id):a(o.id)},children:o.readAt?(0,t.jsx)(i.MailOpen,{}):(0,t.jsx)(i.Mail,{})})}),(0,t.jsx)(e.Tooltip.Content,{content:o.readAt?"Mark as unread":"Mark as read"})]})]})},o.id))]})}),(0,t.jsx)(e.Popover.Footer,{asChild:!0,children:(0,t.jsx)(e.Text,{as:"p",align:"center",color:"accent",variant:"tertiary",size:1,children:"Powered by DashX"})})]})]})})};var x=v;
2
+ //# sourceMappingURL=NotificationBell.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAiBQ,IAAAI,EAA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I,IAAM,EACrD,GACF,KACA,QAAC,UAAQ,KAAR,CACC,oBAAC,UAAQ,QAAR,CACC,mBAAC,UACC,MAAM,SACN,QAAQ,QACR,UAAU,OACV,KAAMA,EAAa,OAAS,SAAW,WACvC,QAAS,IAAM,CACTA,EAAa,OACfH,EAAyBG,EAAa,EAAE,EAExCJ,EAAuBI,EAAa,EAAE,CAE1C,EAEC,SAAAA,EAAa,UAAS,OAAC,aAAS,KAAK,OAAC,SAAK,EAC9C,EACF,KACA,OAAC,UAAQ,QAAR,CACC,QAASA,EAAa,OAAS,iBAAmB,eACpD,GACF,GACF,GAhCSA,EAAa,EAiCxB,CACD,GACH,EACF,KACA,OAAC,UAAQ,OAAR,CAAe,QAAO,GACrB,mBAAC,QAAK,GAAG,IAAI,MAAM,SAAS,MAAM,SAAS,QAAQ,WAAW,KAAM,EAAG,4BAEvE,EACF,GACF,GACF,EACF,CAEJ,EAEA,IAAOZ,EAAQO",
6
+ "names": ["NotificationBell_exports", "__export", "NotificationBell_default", "__toCommonJS", "import_jsx_runtime", "import_date_fns", "import_hooks", "import_components", "import_icons", "NotificationBell", "markNotificationAsRead", "markNotificationAsUnread", "notifications", "unreadNotificationsCount", "notification"]
7
+ }
@@ -1,2 +1,2 @@
1
- import{jsx as e,jsxs as p}from"react/jsx-runtime";import*as n from"@radix-ui/react-scroll-area";import{useEffect as v,useState as w}from"react";import{Send as N,X as P}from"lucide-react";import{Button as b,Flex as s,Heading as T,Popover as S,Text as c,TextArea as k,Theme as H}from"../components";import{cn as x}from"../utils/cn.js";import R from"../hooks/use-auto-scroll.js";import U from"../hooks/use-in-app-chat.js";import z from"../hooks/use-in-app-chat-notifications.js";const M=o=>{const a=o.renderedContent;return typeof a=="string"?a:a?.text??""},O=o=>o.aiRole?.toUpperCase()==="USER",y=({messages:o,isLoading:a,error:l,sendMessage:r,withChatHeader:u=!1,withPopoverClose:m=!1,borderless:d=!1,title:C="Chat"})=>{const[i,h]=w(""),{scrollAreaRef:A,scrollToBottom:g}=R();v(()=>{setTimeout(()=>g({smooth:!0}),0)},[o.length,g]);const f=()=>{i.trim()&&r(i)&&h("")},I=t=>{t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),f())};return e(H,{asChild:!0,children:p(s,{direction:"column",className:x("h-full",!d&&"border border-gray-400/40"),children:[u&&p(s,{align:"center",justify:"between",className:"border-b border-b-gray-400/40 px-6 py-4",children:[e(T,{size:3,children:C}),m&&e(S.Close,{children:e(b,{shape:"square",roundness:"full",variant:"ghost",mode:"subtle",inset:"right",children:e(P,{})})})]}),e(s,{direction:"column",className:"grow overflow-auto bg-gray-50",children:p(n.Root,{ref:A,className:"h-full grow-1 p-6",children:[e(n.Viewport,{className:"h-full",children:p(s,{direction:"column",gap:3,children:[o.map(t=>e("div",{className:x("max-w-[80%] rounded-lg py-2 px-3",O(t)?"bg-accent-600 ml-auto items-end text-white":"bg-gray-200 mr-auto items-start text-gray-900"),children:e(c,{as:"p",size:2,children:M(t)})},t.externalUid||t.id)),a&&e(c,{as:"p",size:2,className:"mr-auto text-gray-500",children:"Loading\u2026"}),l&&e(c,{as:"p",size:2,className:"bg-negative-100 text-negative-900 mx-auto rounded-lg py-2 px-3",children:l})]})}),e(n.Scrollbar,{orientation:"vertical",className:"w-1 bg-gray-200 opacity-50",children:e(n.Thumb,{className:"flex-1 rounded-2xl bg-gray-400"})}),e(n.Corner,{})]})}),e("div",{className:"shrink-0 grow-0 border-t border-t-gray-400/40",children:p(s,{gap:2,align:"end",className:"w-full",children:[e("div",{className:"w-full [&_textarea]:!border-none [&_textarea]:!outline-none",children:e(k,{"aria-label":"message",size:"extralarge",placeholder:"Type a message\u2026",value:i,onKeyDown:I,onChange:t=>h(t),roundness:"none",autogrow:!0})}),e("div",{className:"mr-[7px] mb-[7px]",children:e(b,{shape:"square",roundness:"full",variant:"fill",size:"medium",onPress:f,isDisabled:!i.trim(),children:e(N,{size:20})})})]})})]})})},E=({identityId:o,idempotencyKey:a,initialMessage:l,notifications:r=!0,...u})=>{const m=z({isOpen:!0,enabled:r!==!1,options:{requestPermissionOn:"manual",...typeof r=="object"?r:void 0}}),d=U({identityId:o,idempotencyKey:a,initialMessage:l,onInboundMessage:m.handleInboundMessage});return e(y,{...d,...u})};var _=E;export{y as InAppChat,_ as default};
1
+ import{jsx as e,jsxs as p}from"react/jsx-runtime";import*as n from"@radix-ui/react-scroll-area";import{useEffect as v,useState as w}from"react";import{Send as N,X as P}from"lucide-react";import{Button as b,Flex as s,Heading as T,Popover as S,Text as c,TextArea as k,Theme as H}from"../components";import{cn as x}from"../utils/cn.js";import R from"../hooks/use-auto-scroll.js";import U from"../hooks/use-in-app-chat.js";import z from"../hooks/use-in-app-chat-notifications.js";const M=o=>{const a=o.renderedContent;return typeof a=="string"?a:a?.text??""},O=o=>o.aiRole?.toUpperCase()==="USER",y=({messages:o,isLoading:a,error:l,sendMessage:r,withChatHeader:u=!1,withPopoverClose:m=!1,borderless:d=!1,title:C="Chat"})=>{const[i,h]=w(""),{scrollAreaRef:A,scrollToBottom:g}=R();v(()=>{setTimeout(()=>g({smooth:!0}),0)},[o.length,g]);const f=()=>{i.trim()&&r(i)&&h("")},I=t=>{t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),f())};return e(H,{asChild:!0,children:p(s,{direction:"column",className:x("h-full",!d&&"border border-gray-400/40"),children:[u&&p(s,{align:"center",justify:"between",className:"border-b border-b-gray-400/40 px-6 py-4",children:[e(T,{size:3,children:C}),m&&e(S.Close,{children:e(b,{shape:"square",roundness:"full",variant:"ghost",mode:"subtle",inset:"right",children:e(P,{})})})]}),e(s,{direction:"column",className:"grow overflow-auto bg-gray-50",children:p(n.Root,{ref:A,className:"h-full grow p-6",children:[e(n.Viewport,{className:"h-full",children:p(s,{direction:"column",gap:3,children:[o.map(t=>e("div",{className:x("max-w-[80%] rounded-lg py-2 px-3",O(t)?"bg-accent-600 ml-auto items-end text-white":"bg-gray-200 mr-auto items-start text-gray-900"),children:e(c,{as:"p",size:2,children:M(t)})},t.externalUid||t.id)),a&&e(c,{as:"p",size:2,className:"mr-auto text-gray-500",children:"Loading\u2026"}),l&&e(c,{as:"p",size:2,className:"bg-negative-100 text-negative-900 mx-auto rounded-lg py-2 px-3",children:l})]})}),e(n.Scrollbar,{orientation:"vertical",className:"w-1 bg-gray-200 opacity-50",children:e(n.Thumb,{className:"flex-1 rounded-2xl bg-gray-400"})}),e(n.Corner,{})]})}),e("div",{className:"shrink-0 grow-0 border-t border-t-gray-400/40",children:p(s,{gap:2,align:"end",className:"w-full",children:[e("div",{className:"w-full [&_textarea]:border-none! [&_textarea]:outline-none!",children:e(k,{"aria-label":"message",size:"extralarge",placeholder:"Type a message\u2026",value:i,onKeyDown:I,onChange:t=>h(t),roundness:"none",autogrow:!0})}),e("div",{className:"mr-[7px] mb-[7px]",children:e(b,{shape:"square",roundness:"full",variant:"fill",size:"medium",onPress:f,isDisabled:!i.trim(),children:e(N,{size:20})})})]})})]})})},E=({identityId:o,idempotencyKey:a,initialMessage:l,notifications:r=!0,...u})=>{const m=z({isOpen:!0,enabled:r!==!1,options:{requestPermissionOn:"manual",...typeof r=="object"?r:void 0}}),d=U({identityId:o,idempotencyKey:a,initialMessage:l,onInboundMessage:m.handleInboundMessage});return e(y,{...d,...u})};var _=E;export{y as InAppChat,_ as default};
2
2
  //# sourceMappingURL=InAppChat.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/widgets/InAppChat.tsx"],
4
- "sourcesContent": ["import * as ScrollArea from '@radix-ui/react-scroll-area';\nimport React, { useEffect, useState } from 'react';\nimport { Send, X } from 'lucide-react';\nimport type { KeyboardEvent } from 'react';\n\nimport { Button, Flex, Heading, Popover, Text, TextArea, Theme } from '../components';\nimport { cn } from '../utils/cn.js';\nimport useAutoScroll from '../hooks/use-auto-scroll.js';\nimport useInAppChat, {\n type InAppChatMessage,\n type UseInAppChatHookProps,\n type UseInAppChatHookResponse,\n} from '../hooks/use-in-app-chat.js';\nimport useInAppChatNotifications, {\n type InAppChatNotificationOptions,\n} from '../hooks/use-in-app-chat-notifications.js';\n\ntype InAppChatProps = UseInAppChatHookResponse & {\n withChatHeader?: boolean;\n withPopoverClose?: boolean;\n borderless?: boolean;\n title?: string;\n};\n\nconst messageText = (message: InAppChatMessage): string => {\n const content = message.renderedContent;\n if (typeof content === 'string') return content;\n return content?.text ?? '';\n};\n\nconst isOutgoing = (message: InAppChatMessage): boolean => message.aiRole?.toUpperCase() === 'USER';\n\nconst InAppChat = ({\n messages,\n isLoading,\n error,\n sendMessage,\n withChatHeader = false,\n withPopoverClose = false,\n borderless = false,\n title = 'Chat',\n}: InAppChatProps) => {\n const [inputValue, setInputValue] = useState('');\n const { scrollAreaRef, scrollToBottom } = useAutoScroll();\n\n useEffect(() => {\n setTimeout(() => scrollToBottom({ smooth: true }), 0);\n }, [messages.length, scrollToBottom]);\n\n const handleSubmit = () => {\n if (!inputValue.trim()) return;\n // `sendMessage` is synchronous: it returns true the instant the message is\n // optimistically queued (network send runs in the background). Clear the\n // composer right away on success so a fast second Enter can't re-send the same\n // text as a duplicate; on false (chat not ready) keep the visitor's text.\n if (sendMessage(inputValue)) setInputValue('');\n };\n\n const handleKeyDown = (e: KeyboardEvent<HTMLTextAreaElement>) => {\n if (e.key === 'Enter' && !e.shiftKey) {\n e.preventDefault();\n handleSubmit();\n }\n };\n\n return (\n <Theme asChild>\n <Flex direction=\"column\" className={cn('h-full', !borderless && 'border border-gray-400/40')}>\n {withChatHeader && (\n <Flex align=\"center\" justify=\"between\" className=\"border-b border-b-gray-400/40 px-6 py-4\">\n <Heading size={3}>{title}</Heading>\n {withPopoverClose && (\n <Popover.Close>\n <Button shape=\"square\" roundness=\"full\" variant=\"ghost\" mode=\"subtle\" inset=\"right\">\n <X />\n </Button>\n </Popover.Close>\n )}\n </Flex>\n )}\n\n <Flex direction=\"column\" className=\"grow overflow-auto bg-gray-50\">\n <ScrollArea.Root ref={scrollAreaRef} className=\"h-full grow-1 p-6\">\n <ScrollArea.Viewport className=\"h-full\">\n <Flex direction=\"column\" gap={3}>\n {messages.map((message) => (\n <div\n key={message.externalUid || message.id}\n className={cn(\n 'max-w-[80%] rounded-lg py-2 px-3',\n isOutgoing(message)\n ? 'bg-accent-600 ml-auto items-end text-white'\n : 'bg-gray-200 mr-auto items-start text-gray-900',\n )}\n >\n <Text as=\"p\" size={2}>{messageText(message)}</Text>\n </div>\n ))}\n\n {isLoading && (\n <Text as=\"p\" size={2} className=\"mr-auto text-gray-500\">\n Loading\u2026\n </Text>\n )}\n\n {error && (\n <Text\n as=\"p\"\n size={2}\n className=\"bg-negative-100 text-negative-900 mx-auto rounded-lg py-2 px-3\"\n >\n {error}\n </Text>\n )}\n </Flex>\n </ScrollArea.Viewport>\n <ScrollArea.Scrollbar orientation=\"vertical\" className=\"w-1 bg-gray-200 opacity-50\">\n <ScrollArea.Thumb className=\"flex-1 rounded-2xl bg-gray-400\" />\n </ScrollArea.Scrollbar>\n <ScrollArea.Corner />\n </ScrollArea.Root>\n </Flex>\n\n <div className=\"shrink-0 grow-0 border-t border-t-gray-400/40\">\n <Flex gap={2} align=\"end\" className=\"w-full\">\n <div className=\"w-full [&_textarea]:!border-none [&_textarea]:!outline-none\">\n <TextArea\n aria-label=\"message\"\n size=\"extralarge\"\n placeholder=\"Type a message\u2026\"\n value={inputValue}\n onKeyDown={handleKeyDown}\n onChange={(text) => setInputValue(text)}\n roundness=\"none\"\n autogrow\n />\n </div>\n <div className=\"mr-[7px] mb-[7px]\">\n <Button\n shape=\"square\"\n roundness=\"full\"\n variant=\"fill\"\n size=\"medium\"\n onPress={handleSubmit}\n isDisabled={!inputValue.trim()}\n >\n <Send size={20} />\n </Button>\n </div>\n </Flex>\n </div>\n </Flex>\n </Theme>\n );\n};\n\ntype InAppChatWrapperProps = Omit<InAppChatProps, keyof UseInAppChatHookResponse>\n & Omit<UseInAppChatHookProps, 'enabled' | 'onInboundMessage'>\n & {\n // Foreground browser notifications for incoming agent/AI messages while the\n // chat isn't focused. `false` disables; an object customizes title/icon/body.\n // Default: enabled but silent until permission is granted (this always-visible\n // surface never auto-prompts \u2014 call `Client.requestNotificationPermission()`\n // from your own UI, or use `<InAppChatButton>` which prompts on first open).\n notifications?: boolean | InAppChatNotificationOptions;\n };\n\nconst InAppChatWrapper = ({ identityId, idempotencyKey, initialMessage, notifications = true, ...props }: InAppChatWrapperProps) => {\n // Always-visible surface: treat as \"open\" and gate notifications on tab\n // visibility/focus only. No launcher gesture exists here, so default to\n // 'manual' permission (auto-requesting would prompt on mount).\n const notifier = useInAppChatNotifications({\n isOpen: true,\n enabled: notifications !== false,\n options: {\n requestPermissionOn: 'manual',\n ...(typeof notifications === 'object' ? notifications : undefined),\n },\n });\n const chat = useInAppChat({\n identityId,\n idempotencyKey,\n initialMessage,\n onInboundMessage: notifier.handleInboundMessage,\n });\n return <InAppChat {...chat} {...props} />;\n};\n\nexport type { InAppChatProps, InAppChatWrapperProps };\n\nexport { InAppChat };\n\nexport default InAppChatWrapper;\n"],
5
- "mappings": "AAqEU,OACE,OAAAA,EADF,QAAAC,MAAA,oBArEV,UAAYC,MAAgB,8BAC5B,OAAgB,aAAAC,EAAW,YAAAC,MAAgB,QAC3C,OAAS,QAAAC,EAAM,KAAAC,MAAS,eAGxB,OAAS,UAAAC,EAAQ,QAAAC,EAAM,WAAAC,EAAS,WAAAC,EAAS,QAAAC,EAAM,YAAAC,EAAU,SAAAC,MAAa,gBACtE,OAAS,MAAAC,MAAU,iBACnB,OAAOC,MAAmB,8BAC1B,OAAOC,MAIA,8BACP,OAAOC,MAEA,4CASP,MAAMC,EAAeC,GAAsC,CACzD,MAAMC,EAAUD,EAAQ,gBACxB,OAAI,OAAOC,GAAY,SAAiBA,EACjCA,GAAS,MAAQ,EAC1B,EAEMC,EAAcF,GAAuCA,EAAQ,QAAQ,YAAY,IAAM,OAEvFG,EAAY,CAAC,CACjB,SAAAC,EACA,UAAAC,EACA,MAAAC,EACA,YAAAC,EACA,eAAAC,EAAiB,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,EACA,eAAAC,EACA,iBAAkBG,EAAS,oBAC7B,CAAC,EACD,OAAO7C,EAACsB,EAAA,CAAW,GAAGwB,EAAO,GAAGF,EAAO,CACzC,EAMA,IAAOG,EAAQR",
4
+ "sourcesContent": ["import * as ScrollArea from '@radix-ui/react-scroll-area';\nimport React, { useEffect, useState } from 'react';\nimport { Send, X } from 'lucide-react';\nimport type { KeyboardEvent } from 'react';\n\nimport { Button, Flex, Heading, Popover, Text, TextArea, Theme } from '../components';\nimport { cn } from '../utils/cn.js';\nimport useAutoScroll from '../hooks/use-auto-scroll.js';\nimport useInAppChat, {\n type InAppChatMessage,\n type UseInAppChatHookProps,\n type UseInAppChatHookResponse,\n} from '../hooks/use-in-app-chat.js';\nimport useInAppChatNotifications, {\n type InAppChatNotificationOptions,\n} from '../hooks/use-in-app-chat-notifications.js';\n\ntype InAppChatProps = UseInAppChatHookResponse & {\n withChatHeader?: boolean;\n withPopoverClose?: boolean;\n borderless?: boolean;\n title?: string;\n};\n\nconst messageText = (message: InAppChatMessage): string => {\n const content = message.renderedContent;\n if (typeof content === 'string') return content;\n return content?.text ?? '';\n};\n\nconst isOutgoing = (message: InAppChatMessage): boolean => message.aiRole?.toUpperCase() === 'USER';\n\nconst InAppChat = ({\n messages,\n isLoading,\n error,\n sendMessage,\n withChatHeader = false,\n withPopoverClose = false,\n borderless = false,\n title = 'Chat',\n}: InAppChatProps) => {\n const [inputValue, setInputValue] = useState('');\n const { scrollAreaRef, scrollToBottom } = useAutoScroll();\n\n useEffect(() => {\n setTimeout(() => scrollToBottom({ smooth: true }), 0);\n }, [messages.length, scrollToBottom]);\n\n const handleSubmit = () => {\n if (!inputValue.trim()) return;\n // `sendMessage` is synchronous: it returns true the instant the message is\n // optimistically queued (network send runs in the background). Clear the\n // composer right away on success so a fast second Enter can't re-send the same\n // text as a duplicate; on false (chat not ready) keep the visitor's text.\n if (sendMessage(inputValue)) setInputValue('');\n };\n\n const handleKeyDown = (e: KeyboardEvent<HTMLTextAreaElement>) => {\n if (e.key === 'Enter' && !e.shiftKey) {\n e.preventDefault();\n handleSubmit();\n }\n };\n\n return (\n <Theme asChild>\n <Flex direction=\"column\" className={cn('h-full', !borderless && 'border border-gray-400/40')}>\n {withChatHeader && (\n <Flex align=\"center\" justify=\"between\" className=\"border-b border-b-gray-400/40 px-6 py-4\">\n <Heading size={3}>{title}</Heading>\n {withPopoverClose && (\n <Popover.Close>\n <Button shape=\"square\" roundness=\"full\" variant=\"ghost\" mode=\"subtle\" inset=\"right\">\n <X />\n </Button>\n </Popover.Close>\n )}\n </Flex>\n )}\n\n <Flex direction=\"column\" className=\"grow overflow-auto bg-gray-50\">\n <ScrollArea.Root ref={scrollAreaRef} className=\"h-full grow p-6\">\n <ScrollArea.Viewport className=\"h-full\">\n <Flex direction=\"column\" gap={3}>\n {messages.map((message) => (\n <div\n key={message.externalUid || message.id}\n className={cn(\n 'max-w-[80%] rounded-lg py-2 px-3',\n isOutgoing(message)\n ? 'bg-accent-600 ml-auto items-end text-white'\n : 'bg-gray-200 mr-auto items-start text-gray-900',\n )}\n >\n <Text as=\"p\" size={2}>{messageText(message)}</Text>\n </div>\n ))}\n\n {isLoading && (\n <Text as=\"p\" size={2} className=\"mr-auto text-gray-500\">\n Loading\u2026\n </Text>\n )}\n\n {error && (\n <Text\n as=\"p\"\n size={2}\n className=\"bg-negative-100 text-negative-900 mx-auto rounded-lg py-2 px-3\"\n >\n {error}\n </Text>\n )}\n </Flex>\n </ScrollArea.Viewport>\n <ScrollArea.Scrollbar orientation=\"vertical\" className=\"w-1 bg-gray-200 opacity-50\">\n <ScrollArea.Thumb className=\"flex-1 rounded-2xl bg-gray-400\" />\n </ScrollArea.Scrollbar>\n <ScrollArea.Corner />\n </ScrollArea.Root>\n </Flex>\n\n <div className=\"shrink-0 grow-0 border-t border-t-gray-400/40\">\n <Flex gap={2} align=\"end\" className=\"w-full\">\n <div className=\"w-full [&_textarea]:border-none! [&_textarea]:outline-none!\">\n <TextArea\n aria-label=\"message\"\n size=\"extralarge\"\n placeholder=\"Type a message\u2026\"\n value={inputValue}\n onKeyDown={handleKeyDown}\n onChange={(text) => setInputValue(text)}\n roundness=\"none\"\n autogrow\n />\n </div>\n <div className=\"mr-[7px] mb-[7px]\">\n <Button\n shape=\"square\"\n roundness=\"full\"\n variant=\"fill\"\n size=\"medium\"\n onPress={handleSubmit}\n isDisabled={!inputValue.trim()}\n >\n <Send size={20} />\n </Button>\n </div>\n </Flex>\n </div>\n </Flex>\n </Theme>\n );\n};\n\ntype InAppChatWrapperProps = Omit<InAppChatProps, keyof UseInAppChatHookResponse>\n & Omit<UseInAppChatHookProps, 'enabled' | 'onInboundMessage'>\n & {\n // Foreground browser notifications for incoming agent/AI messages while the\n // chat isn't focused. `false` disables; an object customizes title/icon/body.\n // Default: enabled but silent until permission is granted (this always-visible\n // surface never auto-prompts \u2014 call `Client.requestNotificationPermission()`\n // from your own UI, or use `<InAppChatButton>` which prompts on first open).\n notifications?: boolean | InAppChatNotificationOptions;\n };\n\nconst InAppChatWrapper = ({ identityId, idempotencyKey, initialMessage, notifications = true, ...props }: InAppChatWrapperProps) => {\n // Always-visible surface: treat as \"open\" and gate notifications on tab\n // visibility/focus only. No launcher gesture exists here, so default to\n // 'manual' permission (auto-requesting would prompt on mount).\n const notifier = useInAppChatNotifications({\n isOpen: true,\n enabled: notifications !== false,\n options: {\n requestPermissionOn: 'manual',\n ...(typeof notifications === 'object' ? notifications : undefined),\n },\n });\n const chat = useInAppChat({\n identityId,\n idempotencyKey,\n initialMessage,\n onInboundMessage: notifier.handleInboundMessage,\n });\n return <InAppChat {...chat} {...props} />;\n};\n\nexport type { InAppChatProps, InAppChatWrapperProps };\n\nexport { InAppChat };\n\nexport default InAppChatWrapper;\n"],
5
+ "mappings": "AAqEU,OACE,OAAAA,EADF,QAAAC,MAAA,oBArEV,UAAYC,MAAgB,8BAC5B,OAAgB,aAAAC,EAAW,YAAAC,MAAgB,QAC3C,OAAS,QAAAC,EAAM,KAAAC,MAA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OACV,QAAQ,OACR,KAAK,SACL,QAAS4B,EACT,WAAY,CAACJ,EAAW,KAAK,EAE7B,SAAA/B,EAACK,EAAA,CAAK,KAAM,GAAI,EAClB,EACF,GACF,EACF,GACF,EACF,CAEJ,EAaMkC,EAAmB,CAAC,CAAE,WAAAC,EAAY,eAAAC,EAAgB,eAAAC,EAAgB,cAAAC,EAAgB,GAAM,GAAGC,CAAM,IAA6B,CAIlI,MAAMC,EAAW5B,EAA0B,CACzC,OAAQ,GACR,QAAS0B,IAAkB,GAC3B,QAAS,CACP,oBAAqB,SACrB,GAAI,OAAOA,GAAkB,SAAWA,EAAgB,MAC1D,CACF,CAAC,EACKG,EAAO9B,EAAa,CACxB,WAAAwB,EACA,eAAAC,EACA,eAAAC,EACA,iBAAkBG,EAAS,oBAC7B,CAAC,EACD,OAAO7C,EAACsB,EAAA,CAAW,GAAGwB,EAAO,GAAGF,EAAO,CACzC,EAMA,IAAOG,EAAQR",
6
6
  "names": ["jsx", "jsxs", "ScrollArea", "useEffect", "useState", "Send", "X", "Button", "Flex", "Heading", "Popover", "Text", "TextArea", "Theme", "cn", "useAutoScroll", "useInAppChat", "useInAppChatNotifications", "messageText", "message", "content", "isOutgoing", "InAppChat", "messages", "isLoading", "error", "sendMessage", "withChatHeader", "withPopoverClose", "borderless", "title", "inputValue", "setInputValue", "scrollAreaRef", "scrollToBottom", "handleSubmit", "handleKeyDown", "e", "text", "InAppChatWrapper", "identityId", "idempotencyKey", "initialMessage", "notifications", "props", "notifier", "chat", "InAppChat_default"]
7
7
  }
@@ -0,0 +1,2 @@
1
+ declare const NotificationBell: () => import("react/jsx-runtime").JSX.Element;
2
+ export default NotificationBell;
@@ -0,0 +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};
2
+ //# sourceMappingURL=NotificationBell.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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,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vE,EACF,GACF,GACF,EACF,CAEJ,EAEA,IAAOa,EAAQN",
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dashx/react",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
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.8.1",
78
+ "@dashx/browser": "^0.8.2",
79
79
  "@radix-ui/colors": "^3.0.0",
80
80
  "@radix-ui/primitive": "^1.1.3",
81
81
  "@radix-ui/react-accessible-icon": "^1.1.8",
package/styles.css CHANGED
@@ -1298,12 +1298,24 @@ button, input:where([type='button'], [type='reset'], [type='submit']), ::file-se
1298
1298
  border-style: none !important;
1299
1299
  }
1300
1300
  }
1301
+ .\[\&_textarea\]\:border-none\! {
1302
+ & textarea {
1303
+ --tw-border-style: none !important;
1304
+ border-style: none !important;
1305
+ }
1306
+ }
1301
1307
  .\[\&_textarea\]\:\!outline-none {
1302
1308
  & textarea {
1303
1309
  --tw-outline-style: none !important;
1304
1310
  outline-style: none !important;
1305
1311
  }
1306
1312
  }
1313
+ .\[\&_textarea\]\:outline-none\! {
1314
+ & textarea {
1315
+ --tw-outline-style: none !important;
1316
+ outline-style: none !important;
1317
+ }
1318
+ }
1307
1319
  :is(.dark, .dark-theme),
1308
1320
  :is(.dark, .dark-theme) :where(.dx:not(.light, .light-theme)) {
1309
1321
  color-scheme: dark;