@dashx/react 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,21 @@
2
2
 
3
3
  All notable changes to `@dashx/react` are documented in this file. Format loosely follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), versions follow [SemVer](https://semver.org/).
4
4
 
5
+ ## [0.4.1] — 2026-08-05
6
+
7
+ ### Changed
8
+
9
+ - **`useInAppChatNotifications`'s `onActivate` now receives the message that raised the notification.**
10
+
11
+ ```diff
12
+ - onActivate?: () => void
13
+ + onActivate?: (message: InAppChatMessageData) => void
14
+ ```
15
+
16
+ Notifications are tagged per conversation, so a surface watching more than one thread could raise several at once — but the old zero-argument callback gave the handler no way to tell them apart, and it closed over whichever message arrived last. Clicking an older notification opened the wrong conversation.
17
+
18
+ **Backward compatible.** A `() => void` handler is still assignable and still behaves as before; take the parameter only if you need to route by `message.conversationId`. `InAppChatMessageData` is imported from `@dashx/browser`, same as the existing `renderBody` option on this hook.
19
+
5
20
  ## [0.4.0] — 2026-07-29
6
21
 
7
22
  ### Changed
@@ -9,7 +9,7 @@ type UseInAppChatNotificationsProps = {
9
9
  isOpen: boolean;
10
10
  enabled?: boolean;
11
11
  options?: InAppChatNotificationOptions;
12
- onActivate?: () => void;
12
+ onActivate?: (message: InAppChatMessageData) => void;
13
13
  };
14
14
  /**
15
15
  * Foreground browser notifications for incoming In-App Chat messages. Returns a
@@ -1,2 +1,2 @@
1
- "use strict";var A=Object.create;var c=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var P=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var g=(t,e)=>{for(var r in e)c(t,r,{get:e[r],enumerable:!0})},h=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of O(e))!b.call(t,n)&&n!==r&&c(t,n,{get:()=>e[n],enumerable:!(i=N(e,n))||i.enumerable});return t};var R=(t,e,r)=>(r=t!=null?A(P(t)):{},h(e||!t||!t.__esModule?c(r,"default",{value:t,enumerable:!0}):r,t)),q=t=>h(c({},"__esModule",{value:!0}),t);var D={};g(D,{default:()=>U});module.exports=q(D);var o=require("react"),l=R(require("./use-dashx-provider.js"));const v=t=>typeof t=="string"?t:t?.text??t?.body??"",x=({isOpen:t,enabled:e=!0,options:r,onActivate:i})=>{const n=(0,l.default)(),p=(0,o.useRef)(t);p.current=t;const u=(0,o.useRef)(e);u.current=e;const s=(0,o.useRef)(r);s.current=r;const f=(0,o.useRef)(i);f.current=i;const m=()=>!(!p.current||typeof document>"u"||document.hidden||typeof document.hasFocus=="function"&&!document.hasFocus()),C=(0,o.useCallback)(a=>{if(!u.current||(a.aiRole??"").toUpperCase()==="USER"||m())return;const d=s.current?.renderBody?.(a)??v(a.renderedContent);d&&n.showInAppChatNotification?.({title:s.current?.title??"New message",body:d,icon:s.current?.icon,tag:a.conversationId?`in_app_chat:${a.conversationId}`:void 0,onClick:()=>f.current?.()})},[n]),I=(0,o.useCallback)(()=>n.requestNotificationPermission?.()??Promise.resolve("denied"),[n]),y=(0,o.useCallback)(()=>{u.current&&(s.current?.requestPermissionOn??"firstOpen")==="firstOpen"&&n.requestNotificationPermission?.().catch(()=>{})},[n]);return{handleInboundMessage:C,requestPermission:I,requestPermissionOnOpen:y}};var U=x;
1
+ "use strict";var y=Object.create;var p=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var P=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var g=(t,e)=>{for(var r in e)p(t,r,{get:e[r],enumerable:!0})},h=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of O(e))!b.call(t,n)&&n!==r&&p(t,n,{get:()=>e[n],enumerable:!(s=N(e,n))||s.enumerable});return t};var R=(t,e,r)=>(r=t!=null?y(P(t)):{},h(e||!t||!t.__esModule?p(r,"default",{value:t,enumerable:!0}):r,t)),q=t=>h(p({},"__esModule",{value:!0}),t);var M={};g(M,{default:()=>D});module.exports=q(M);var o=require("react"),l=R(require("./use-dashx-provider.js"));const v=t=>typeof t=="string"?t:t?.text??t?.body??"",x=({isOpen:t,enabled:e=!0,options:r,onActivate:s})=>{const n=(0,l.default)(),u=(0,o.useRef)(t);u.current=t;const c=(0,o.useRef)(e);c.current=e;const a=(0,o.useRef)(r);a.current=r;const f=(0,o.useRef)(s);f.current=s;const C=()=>!(!u.current||typeof document>"u"||document.hidden||typeof document.hasFocus=="function"&&!document.hasFocus()),m=(0,o.useCallback)(i=>{if(!c.current||(i.aiRole??"").toUpperCase()==="USER"||C())return;const d=a.current?.renderBody?.(i)??v(i.renderedContent);d&&n.showInAppChatNotification?.({title:a.current?.title??"New message",body:d,icon:a.current?.icon,tag:i.conversationId?`in_app_chat:${i.conversationId}`:void 0,onClick:()=>f.current?.(i)})},[n]),I=(0,o.useCallback)(()=>n.requestNotificationPermission?.()??Promise.resolve("denied"),[n]),A=(0,o.useCallback)(()=>{c.current&&(a.current?.requestPermissionOn??"firstOpen")==="firstOpen"&&n.requestNotificationPermission?.().catch(()=>{})},[n]);return{handleInboundMessage:m,requestPermission:I,requestPermissionOnOpen:A}};var D=x;
2
2
  //# sourceMappingURL=use-in-app-chat-notifications.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/hooks/use-in-app-chat-notifications.ts"],
4
- "sourcesContent": ["import { useCallback, useRef } from 'react';\nimport type { InAppChatMessageData } from '@dashx/browser';\n\nimport useDashXProvider from './use-dashx-provider.js';\n\ntype InAppChatNotificationOptions = {\n // Notification title. Defaults to 'New message'.\n title?: string;\n // Icon URL shown in the notification.\n icon?: string;\n // Custom body text from the inbound message; defaults to the message text.\n renderBody?: (message: InAppChatMessageData) => string;\n // When to request notification permission. 'firstOpen' (the default for the\n // launcher) requests it the first time the visitor opens chat \u2014 a real user\n // gesture, which browsers require for a non-penalized prompt. 'manual' never\n // auto-requests (use for always-visible surfaces, where the embedder drives\n // the prompt via the returned `requestPermission`).\n requestPermissionOn?: 'firstOpen' | 'manual';\n};\n\ntype UseInAppChatNotificationsProps = {\n // Whether the chat surface is currently open/visible. Combined with tab\n // visibility + window focus to decide if the visitor is actively looking at\n // chat (in which case we don't notify).\n isOpen: boolean;\n // `false` disables notifications entirely.\n enabled?: boolean;\n options?: InAppChatNotificationOptions;\n // Invoked when the visitor clicks a notification \u2014 focus is handled by the\n // SDK; this opens the chat panel.\n onActivate?: () => void;\n};\n\nconst textFromContent = (content: any): string => {\n if (typeof content === 'string') return content;\n return content?.text ?? content?.body ?? '';\n};\n\n/**\n * Foreground browser notifications for incoming In-App Chat messages. Returns a\n * `handleInboundMessage` to pass as `useInAppChat`'s `onInboundMessage`; it\n * fires a notification only for agent/AI replies that arrive while the chat\n * isn't focused (panel closed, or tab hidden/unfocused) and only once the\n * visitor has granted permission.\n */\nconst useInAppChatNotifications = ({\n isOpen,\n enabled = true,\n options,\n onActivate,\n}: UseInAppChatNotificationsProps) => {\n const dashX = useDashXProvider();\n\n // Latest values for the message handler, so it stays referentially stable\n // (it's wired into the chat hook's subscription).\n const isOpenRef = useRef(isOpen);\n isOpenRef.current = isOpen;\n const enabledRef = useRef(enabled);\n enabledRef.current = enabled;\n const optionsRef = useRef(options);\n optionsRef.current = options;\n const onActivateRef = useRef(onActivate);\n onActivateRef.current = onActivate;\n\n const isChatFocused = (): boolean => {\n if (!isOpenRef.current) return false;\n if (typeof document === 'undefined') return false;\n if (document.hidden) return false;\n if (typeof document.hasFocus === 'function' && !document.hasFocus()) return false;\n return true;\n };\n\n const handleInboundMessage = useCallback(\n (message: InAppChatMessageData) => {\n if (!enabledRef.current) return;\n // Agent/AI replies only \u2014 never the visitor's own echoed message.\n if ((message.aiRole ?? '').toUpperCase() === 'USER') return;\n // Don't interrupt a visitor who's actively looking at the chat.\n if (isChatFocused()) return;\n\n const body = optionsRef.current?.renderBody?.(message) ?? textFromContent(message.renderedContent);\n if (!body) return;\n\n dashX.showInAppChatNotification?.({\n title: optionsRef.current?.title ?? 'New message',\n body,\n icon: optionsRef.current?.icon,\n tag: message.conversationId ? `in_app_chat:${message.conversationId}` : undefined,\n onClick: () => onActivateRef.current?.(),\n });\n },\n [dashX],\n );\n\n const requestPermission = useCallback(\n () => dashX.requestNotificationPermission?.() ?? Promise.resolve('denied' as const),\n [dashX],\n );\n\n // Call this SYNCHRONOUSLY from the surface's open event (a real user gesture)\n // so the permission prompt lands inside the browser's transient activation\n // window. Requesting from an effect after the click has unwound is\n // ignored/rejected by some browsers. Honors `requestPermissionOn` ('manual'\n // skips it), and is safe to call on every open (no-ops once permission is\n // decided \u2014 see Client.requestNotificationPermission).\n const requestPermissionOnOpen = useCallback(() => {\n if (!enabledRef.current) return;\n if ((optionsRef.current?.requestPermissionOn ?? 'firstOpen') !== 'firstOpen') return;\n dashX.requestNotificationPermission?.().catch(() => {});\n }, [dashX]);\n\n return { handleInboundMessage, requestPermission, requestPermissionOnOpen };\n};\n\nexport type { InAppChatNotificationOptions, UseInAppChatNotificationsProps };\n\nexport default useInAppChatNotifications;\n"],
5
- "mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAoC,iBAGpCC,EAA6B,sCA8B7B,MAAMC,EAAmBC,GACnB,OAAOA,GAAY,SAAiBA,EACjCA,GAAS,MAAQA,GAAS,MAAQ,GAUrCC,EAA4B,CAAC,CACjC,OAAAC,EACA,QAAAC,EAAU,GACV,QAAAC,EACA,WAAAC,CACF,IAAsC,CACpC,MAAMC,KAAQ,EAAAC,SAAiB,EAIzBC,KAAY,UAAON,CAAM,EAC/BM,EAAU,QAAUN,EACpB,MAAMO,KAAa,UAAON,CAAO,EACjCM,EAAW,QAAUN,EACrB,MAAMO,KAAa,UAAON,CAAO,EACjCM,EAAW,QAAUN,EACrB,MAAMO,KAAgB,UAAON,CAAU,EACvCM,EAAc,QAAUN,EAExB,MAAMO,EAAgB,IAChB,GAACJ,EAAU,SACX,OAAO,SAAa,KACpB,SAAS,QACT,OAAO,SAAS,UAAa,YAAc,CAAC,SAAS,SAAS,GAI9DK,KAAuB,eAC1BC,GAAkC,CAKjC,GAJI,CAACL,EAAW,UAEXK,EAAQ,QAAU,IAAI,YAAY,IAAM,QAEzCF,EAAc,EAAG,OAErB,MAAMG,EAAOL,EAAW,SAAS,aAAaI,CAAO,GAAKf,EAAgBe,EAAQ,eAAe,EAC5FC,GAELT,EAAM,4BAA4B,CAChC,MAAOI,EAAW,SAAS,OAAS,cACpC,KAAAK,EACA,KAAML,EAAW,SAAS,KAC1B,IAAKI,EAAQ,eAAiB,eAAeA,EAAQ,cAAc,GAAK,OACxE,QAAS,IAAMH,EAAc,UAAU,CACzC,CAAC,CACH,EACA,CAACL,CAAK,CACR,EAEMU,KAAoB,eACxB,IAAMV,EAAM,gCAAgC,GAAK,QAAQ,QAAQ,QAAiB,EAClF,CAACA,CAAK,CACR,EAQMW,KAA0B,eAAY,IAAM,CAC3CR,EAAW,UACXC,EAAW,SAAS,qBAAuB,eAAiB,aACjEJ,EAAM,gCAAgC,EAAE,MAAM,IAAM,CAAC,CAAC,CACxD,EAAG,CAACA,CAAK,CAAC,EAEV,MAAO,CAAE,qBAAAO,EAAsB,kBAAAG,EAAmB,wBAAAC,CAAwB,CAC5E,EAIA,IAAOtB,EAAQM",
4
+ "sourcesContent": ["import { useCallback, useRef } from 'react';\nimport type { InAppChatMessageData } from '@dashx/browser';\n\nimport useDashXProvider from './use-dashx-provider.js';\n\ntype InAppChatNotificationOptions = {\n // Notification title. Defaults to 'New message'.\n title?: string;\n // Icon URL shown in the notification.\n icon?: string;\n // Custom body text from the inbound message; defaults to the message text.\n renderBody?: (message: InAppChatMessageData) => string;\n // When to request notification permission. 'firstOpen' (the default for the\n // launcher) requests it the first time the visitor opens chat \u2014 a real user\n // gesture, which browsers require for a non-penalized prompt. 'manual' never\n // auto-requests (use for always-visible surfaces, where the embedder drives\n // the prompt via the returned `requestPermission`).\n requestPermissionOn?: 'firstOpen' | 'manual';\n};\n\ntype UseInAppChatNotificationsProps = {\n // Whether the chat surface is currently open/visible. Combined with tab\n // visibility + window focus to decide if the visitor is actively looking at\n // chat (in which case we don't notify).\n isOpen: boolean;\n // `false` disables notifications entirely.\n enabled?: boolean;\n options?: InAppChatNotificationOptions;\n // Invoked when the visitor clicks a notification \u2014 focus is handled by the\n // SDK; this opens the chat panel. Receives the message that raised THAT\n // notification, so a surface watching several conversations can open the right\n // one: without it, every notification resolves to whichever arrived last.\n onActivate?: (message: InAppChatMessageData) => void;\n};\n\nconst textFromContent = (content: any): string => {\n if (typeof content === 'string') return content;\n return content?.text ?? content?.body ?? '';\n};\n\n/**\n * Foreground browser notifications for incoming In-App Chat messages. Returns a\n * `handleInboundMessage` to pass as `useInAppChat`'s `onInboundMessage`; it\n * fires a notification only for agent/AI replies that arrive while the chat\n * isn't focused (panel closed, or tab hidden/unfocused) and only once the\n * visitor has granted permission.\n */\nconst useInAppChatNotifications = ({\n isOpen,\n enabled = true,\n options,\n onActivate,\n}: UseInAppChatNotificationsProps) => {\n const dashX = useDashXProvider();\n\n // Latest values for the message handler, so it stays referentially stable\n // (it's wired into the chat hook's subscription).\n const isOpenRef = useRef(isOpen);\n isOpenRef.current = isOpen;\n const enabledRef = useRef(enabled);\n enabledRef.current = enabled;\n const optionsRef = useRef(options);\n optionsRef.current = options;\n const onActivateRef = useRef(onActivate);\n onActivateRef.current = onActivate;\n\n const isChatFocused = (): boolean => {\n if (!isOpenRef.current) return false;\n if (typeof document === 'undefined') return false;\n if (document.hidden) return false;\n if (typeof document.hasFocus === 'function' && !document.hasFocus()) return false;\n return true;\n };\n\n const handleInboundMessage = useCallback(\n (message: InAppChatMessageData) => {\n if (!enabledRef.current) return;\n // Agent/AI replies only \u2014 never the visitor's own echoed message.\n if ((message.aiRole ?? '').toUpperCase() === 'USER') return;\n // Don't interrupt a visitor who's actively looking at the chat.\n if (isChatFocused()) return;\n\n const body = optionsRef.current?.renderBody?.(message) ?? textFromContent(message.renderedContent);\n if (!body) return;\n\n dashX.showInAppChatNotification?.({\n title: optionsRef.current?.title ?? 'New message',\n body,\n icon: optionsRef.current?.icon,\n tag: message.conversationId ? `in_app_chat:${message.conversationId}` : undefined,\n onClick: () => onActivateRef.current?.(message),\n });\n },\n [dashX],\n );\n\n const requestPermission = useCallback(\n () => dashX.requestNotificationPermission?.() ?? Promise.resolve('denied' as const),\n [dashX],\n );\n\n // Call this SYNCHRONOUSLY from the surface's open event (a real user gesture)\n // so the permission prompt lands inside the browser's transient activation\n // window. Requesting from an effect after the click has unwound is\n // ignored/rejected by some browsers. Honors `requestPermissionOn` ('manual'\n // skips it), and is safe to call on every open (no-ops once permission is\n // decided \u2014 see Client.requestNotificationPermission).\n const requestPermissionOnOpen = useCallback(() => {\n if (!enabledRef.current) return;\n if ((optionsRef.current?.requestPermissionOn ?? 'firstOpen') !== 'firstOpen') return;\n dashX.requestNotificationPermission?.().catch(() => {});\n }, [dashX]);\n\n return { handleInboundMessage, requestPermission, requestPermissionOnOpen };\n};\n\nexport type { InAppChatNotificationOptions, UseInAppChatNotificationsProps };\n\nexport default useInAppChatNotifications;\n"],
5
+ "mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAoC,iBAGpCC,EAA6B,sCAgC7B,MAAMC,EAAmBC,GACnB,OAAOA,GAAY,SAAiBA,EACjCA,GAAS,MAAQA,GAAS,MAAQ,GAUrCC,EAA4B,CAAC,CACjC,OAAAC,EACA,QAAAC,EAAU,GACV,QAAAC,EACA,WAAAC,CACF,IAAsC,CACpC,MAAMC,KAAQ,EAAAC,SAAiB,EAIzBC,KAAY,UAAON,CAAM,EAC/BM,EAAU,QAAUN,EACpB,MAAMO,KAAa,UAAON,CAAO,EACjCM,EAAW,QAAUN,EACrB,MAAMO,KAAa,UAAON,CAAO,EACjCM,EAAW,QAAUN,EACrB,MAAMO,KAAgB,UAAON,CAAU,EACvCM,EAAc,QAAUN,EAExB,MAAMO,EAAgB,IAChB,GAACJ,EAAU,SACX,OAAO,SAAa,KACpB,SAAS,QACT,OAAO,SAAS,UAAa,YAAc,CAAC,SAAS,SAAS,GAI9DK,KAAuB,eAC1BC,GAAkC,CAKjC,GAJI,CAACL,EAAW,UAEXK,EAAQ,QAAU,IAAI,YAAY,IAAM,QAEzCF,EAAc,EAAG,OAErB,MAAMG,EAAOL,EAAW,SAAS,aAAaI,CAAO,GAAKf,EAAgBe,EAAQ,eAAe,EAC5FC,GAELT,EAAM,4BAA4B,CAChC,MAAOI,EAAW,SAAS,OAAS,cACpC,KAAAK,EACA,KAAML,EAAW,SAAS,KAC1B,IAAKI,EAAQ,eAAiB,eAAeA,EAAQ,cAAc,GAAK,OACxE,QAAS,IAAMH,EAAc,UAAUG,CAAO,CAChD,CAAC,CACH,EACA,CAACR,CAAK,CACR,EAEMU,KAAoB,eACxB,IAAMV,EAAM,gCAAgC,GAAK,QAAQ,QAAQ,QAAiB,EAClF,CAACA,CAAK,CACR,EAQMW,KAA0B,eAAY,IAAM,CAC3CR,EAAW,UACXC,EAAW,SAAS,qBAAuB,eAAiB,aACjEJ,EAAM,gCAAgC,EAAE,MAAM,IAAM,CAAC,CAAC,CACxD,EAAG,CAACA,CAAK,CAAC,EAEV,MAAO,CAAE,qBAAAO,EAAsB,kBAAAG,EAAmB,wBAAAC,CAAwB,CAC5E,EAIA,IAAOtB,EAAQM",
6
6
  "names": ["use_in_app_chat_notifications_exports", "__export", "use_in_app_chat_notifications_default", "__toCommonJS", "import_react", "import_use_dashx_provider", "textFromContent", "content", "useInAppChatNotifications", "isOpen", "enabled", "options", "onActivate", "dashX", "useDashXProvider", "isOpenRef", "enabledRef", "optionsRef", "onActivateRef", "isChatFocused", "handleInboundMessage", "message", "body", "requestPermission", "requestPermissionOnOpen"]
7
7
  }
@@ -9,5 +9,15 @@ type UseInAppHookResponse = {
9
9
  markMessageAsUnread: (id: string) => Promise<any>;
10
10
  markAllMessagesAsRead: () => Promise<any>;
11
11
  };
12
- declare const useInApp: () => UseInAppHookResponse;
12
+ type UseInAppOptions = {
13
+ /**
14
+ * Fires a react-hot-toast for every live IN_APP_MESSAGE. Only useful with a mounted
15
+ * `<Toast>`, which is also what runs react-hot-toast's expiration timers - without one
16
+ * the toasts never render and its store just retains the last few entries. Set false
17
+ * when the host renders its own notification stack.
18
+ */
19
+ showToast?: boolean;
20
+ };
21
+ declare const useInApp: ({ showToast }?: UseInAppOptions) => UseInAppHookResponse;
13
22
  export default useInApp;
23
+ export type { UseInAppOptions };
@@ -1,2 +1,2 @@
1
- "use strict";var E=Object.create;var i=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var w=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var U=(e,s)=>{for(var o in s)i(e,o,{get:s[o],enumerable:!0})},M=(e,s,o,p)=>{if(s&&typeof s=="object"||typeof s=="function")for(let n of S(s))!D.call(e,n)&&n!==o&&i(e,n,{get:()=>s[n],enumerable:!(p=R(s,n))||p.enumerable});return e};var u=(e,s,o)=>(o=e!=null?E(w(e)):{},M(s||!e||!e.__esModule?i(o,"default",{value:e,enumerable:!0}):o,e)),X=e=>M(i({},"__esModule",{value:!0}),e);var W={};U(W,{default:()=>C});module.exports=X(W);var A=u(require("react-hot-toast")),r=require("react"),c=require("@dashx/browser"),f=u(require("./use-dashx-provider.js")),h=require("../providers/DashXProvider.js");const _=()=>{let e=(0,f.default)();const{subscribe:s}=(0,h.useWebSocket)(),[o,p]=(0,r.useState)([]),[n,k]=(0,r.useState)(null),[g,l]=(0,r.useState)(!1),[m,d]=(0,r.useState)(!1),b=a=>e.trackMessage({id:a,status:"READ"}).catch(t=>{console.error("DashX: failed to mark in-app message as read",t)}),I=a=>e.trackMessage({id:a,status:"UNREAD"}).catch(t=>{console.error("DashX: failed to mark in-app message as unread",t)}),y=()=>e.trackAllMessages().catch(a=>{console.error("DashX: failed to mark all in-app messages as read",a)}),P=async()=>{if(!(m||!g)){d(!0);try{const{hasMore:a}=await e.fetchMoreInAppMessages();l(a)}catch(a){console.error("DashX: failed to fetch more in-app messages",a)}finally{d(!1)}}};return(0,r.useEffect)(()=>{e.watchFetchInAppMessages(a=>{p(a),a.length<=c.IN_APP_MESSAGES_PAGE_SIZE&&l(a.length===c.IN_APP_MESSAGES_PAGE_SIZE)}),e.watchFetchInAppMessagesAggregate(k)},[e]),(0,r.useEffect)(()=>s(t=>{t?.type===c.WebsocketMessage.IN_APP_MESSAGE&&(0,A.default)(t.data.renderedContent.body)}),[s]),{messages:o,unreadMessagesCount:n,hasMore:g,isLoadingMore:m,loadMore:P,markMessageAsRead:b,markMessageAsUnread:I,markAllMessagesAsRead:y}};var C=_;
1
+ "use strict";var U=Object.create;var c=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var w=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var X=(s,e)=>{for(var o in e)c(s,o,{get:e[o],enumerable:!0})},d=(s,e,o,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of S(e))!D.call(s,n)&&n!==o&&c(s,n,{get:()=>e[n],enumerable:!(i=R(e,n))||i.enumerable});return s};var M=(s,e,o)=>(o=s!=null?U(w(s)):{},d(e||!s||!s.__esModule?c(o,"default",{value:s,enumerable:!0}):o,s)),_=s=>d(c({},"__esModule",{value:!0}),s);var G={};X(G,{default:()=>W});module.exports=_(G);var A=M(require("react-hot-toast")),r=require("react"),p=require("@dashx/browser"),f=M(require("./use-dashx-provider.js")),h=require("../providers/DashXProvider.js");const C=({showToast:s=!0}={})=>{let e=(0,f.default)();const{subscribe:o}=(0,h.useWebSocket)(),[i,n]=(0,r.useState)([]),[k,b]=(0,r.useState)(null),[g,l]=(0,r.useState)(!1),[m,u]=(0,r.useState)(!1),I=a=>e.trackMessage({id:a,status:"READ"}).catch(t=>{console.error("DashX: failed to mark in-app message as read",t)}),y=a=>e.trackMessage({id:a,status:"UNREAD"}).catch(t=>{console.error("DashX: failed to mark in-app message as unread",t)}),P=()=>e.trackAllMessages().catch(a=>{console.error("DashX: failed to mark all in-app messages as read",a)}),E=async()=>{if(!(m||!g)){u(!0);try{const{hasMore:a}=await e.fetchMoreInAppMessages();l(a)}catch(a){console.error("DashX: failed to fetch more in-app messages",a)}finally{u(!1)}}};return(0,r.useEffect)(()=>{e.watchFetchInAppMessages(a=>{n(a),a.length<=p.IN_APP_MESSAGES_PAGE_SIZE&&l(a.length===p.IN_APP_MESSAGES_PAGE_SIZE)}),e.watchFetchInAppMessagesAggregate(b)},[e]),(0,r.useEffect)(()=>s?o(t=>{t?.type===p.WebsocketMessage.IN_APP_MESSAGE&&(0,A.default)(t.data.renderedContent.body)}):void 0,[o,s]),{messages:i,unreadMessagesCount:k,hasMore:g,isLoadingMore:m,loadMore:E,markMessageAsRead:I,markMessageAsUnread:y,markAllMessagesAsRead:P}};var W=C;
2
2
  //# sourceMappingURL=use-in-app.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/hooks/use-in-app.ts"],
4
- "sourcesContent": ["import toast from 'react-hot-toast';\nimport { useEffect, useState } from 'react';\nimport { WebsocketMessage, IN_APP_MESSAGES_PAGE_SIZE } from '@dashx/browser';\nimport type { InAppMessages, WebsocketMessageType } from '@dashx/browser';\n\nimport useDashXProvider from './use-dashx-provider.js';\nimport { useWebSocket } from '../providers/DashXProvider.js';\n\ntype UseInAppHookResponse = {\n messages: InAppMessages;\n unreadMessagesCount: number | null;\n hasMore: boolean;\n isLoadingMore: boolean;\n loadMore: () => Promise<void>;\n markMessageAsRead: (id: string) => Promise<any>;\n markMessageAsUnread: (id: string) => Promise<any>;\n markAllMessagesAsRead: () => Promise<any>;\n};\n\nconst useInApp = (): UseInAppHookResponse => {\n let dashX = useDashXProvider();\n const { subscribe } = useWebSocket();\n const [messages, setMessages] = useState<InAppMessages>([]);\n const [unreadMessagesCount, setUnreadMessagesCount] = useState<number | null>(null);\n const [hasMore, setHasMore] = useState(false);\n const [isLoadingMore, setIsLoadingMore] = useState(false);\n\n const markMessageAsRead = (id: string) =>\n dashX.trackMessage({ id, status: 'READ' }).catch((error: unknown) => {\n console.error('DashX: failed to mark in-app message as read', error);\n });\n\n const markMessageAsUnread = (id: string) =>\n dashX.trackMessage({ id, status: 'UNREAD' }).catch((error: unknown) => {\n console.error('DashX: failed to mark in-app message as unread', error);\n });\n\n const markAllMessagesAsRead = () =>\n dashX.trackAllMessages().catch((error: unknown) => {\n console.error('DashX: failed to mark all in-app messages as read', error);\n });\n\n const loadMore = async () => {\n if (isLoadingMore || !hasMore) return;\n setIsLoadingMore(true);\n try {\n const { hasMore: more } = await dashX.fetchMoreInAppMessages();\n setHasMore(more);\n } catch (error) {\n // hasMore stays true so a later scroll retries the page.\n console.error('DashX: failed to fetch more in-app messages', error);\n } finally {\n setIsLoadingMore(false);\n }\n };\n\n useEffect(() => {\n // Set up in-app message watchers (automatically refetch on WebSocket reconnection)\n dashX.watchFetchInAppMessages((nextMessages) => {\n setMessages(nextMessages);\n // While the list is a single page (initial load, empty inbox, or a reconnect\n // refetch of page 1), a full page implies more; past that, loadMore owns hasMore.\n if (nextMessages.length <= IN_APP_MESSAGES_PAGE_SIZE) {\n setHasMore(nextMessages.length === IN_APP_MESSAGES_PAGE_SIZE);\n }\n });\n dashX.watchFetchInAppMessagesAggregate(setUnreadMessagesCount);\n }, [dashX]);\n\n useEffect(() => {\n // Subscribe to WebSocket messages for in-app messages\n const unsubscribe = subscribe((message: WebsocketMessageType) => {\n // Handle only IN_APP_MESSAGE for toast display\n // The client handles all other message processing internally\n if (message?.type === WebsocketMessage.IN_APP_MESSAGE) {\n toast(message.data.renderedContent.body);\n }\n });\n\n return unsubscribe;\n }, [subscribe]);\n\n return {\n messages,\n unreadMessagesCount,\n hasMore,\n isLoadingMore,\n loadMore,\n markMessageAsRead,\n markMessageAsUnread,\n markAllMessagesAsRead,\n };\n};\n\nexport default useInApp;\n"],
5
- "mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkB,8BAClBC,EAAoC,iBACpCC,EAA4D,0BAG5DC,EAA6B,sCAC7BC,EAA6B,yCAa7B,MAAMC,EAAW,IAA4B,CAC3C,IAAIC,KAAQ,EAAAC,SAAiB,EAC7B,KAAM,CAAE,UAAAC,CAAU,KAAI,gBAAa,EAC7B,CAACC,EAAUC,CAAW,KAAI,YAAwB,CAAC,CAAC,EACpD,CAACC,EAAqBC,CAAsB,KAAI,YAAwB,IAAI,EAC5E,CAACC,EAASC,CAAU,KAAI,YAAS,EAAK,EACtC,CAACC,EAAeC,CAAgB,KAAI,YAAS,EAAK,EAElDC,EAAqBC,GACzBZ,EAAM,aAAa,CAAE,GAAAY,EAAI,OAAQ,MAAO,CAAC,EAAE,MAAOC,GAAmB,CACnE,QAAQ,MAAM,+CAAgDA,CAAK,CACrE,CAAC,EAEGC,EAAuBF,GAC3BZ,EAAM,aAAa,CAAE,GAAAY,EAAI,OAAQ,QAAS,CAAC,EAAE,MAAOC,GAAmB,CACrE,QAAQ,MAAM,iDAAkDA,CAAK,CACvE,CAAC,EAEGE,EAAwB,IAC5Bf,EAAM,iBAAiB,EAAE,MAAOa,GAAmB,CACjD,QAAQ,MAAM,oDAAqDA,CAAK,CAC1E,CAAC,EAEGG,EAAW,SAAY,CAC3B,GAAI,EAAAP,GAAiB,CAACF,GACtB,CAAAG,EAAiB,EAAI,EACrB,GAAI,CACF,KAAM,CAAE,QAASO,CAAK,EAAI,MAAMjB,EAAM,uBAAuB,EAC7DQ,EAAWS,CAAI,CACjB,OAASJ,EAAO,CAEd,QAAQ,MAAM,8CAA+CA,CAAK,CACpE,QAAE,CACAH,EAAiB,EAAK,CACxB,EACF,EAEA,sBAAU,IAAM,CAEdV,EAAM,wBAAyBkB,GAAiB,CAC9Cd,EAAYc,CAAY,EAGpBA,EAAa,QAAU,6BACzBV,EAAWU,EAAa,SAAW,2BAAyB,CAEhE,CAAC,EACDlB,EAAM,iCAAiCM,CAAsB,CAC/D,EAAG,CAACN,CAAK,CAAC,KAEV,aAAU,IAEYE,EAAWiB,GAAkC,CAG3DA,GAAS,OAAS,mBAAiB,mBACrC,EAAAC,SAAMD,EAAQ,KAAK,gBAAgB,IAAI,CAE3C,CAAC,EAGA,CAACjB,CAAS,CAAC,EAEP,CACL,SAAAC,EACA,oBAAAE,EACA,QAAAE,EACA,cAAAE,EACA,SAAAO,EACA,kBAAAL,EACA,oBAAAG,EACA,sBAAAC,CACF,CACF,EAEA,IAAOvB,EAAQO",
6
- "names": ["use_in_app_exports", "__export", "use_in_app_default", "__toCommonJS", "import_react_hot_toast", "import_react", "import_browser", "import_use_dashx_provider", "import_DashXProvider", "useInApp", "dashX", "useDashXProvider", "subscribe", "messages", "setMessages", "unreadMessagesCount", "setUnreadMessagesCount", "hasMore", "setHasMore", "isLoadingMore", "setIsLoadingMore", "markMessageAsRead", "id", "error", "markMessageAsUnread", "markAllMessagesAsRead", "loadMore", "more", "nextMessages", "message", "toast"]
4
+ "sourcesContent": ["import toast from 'react-hot-toast';\nimport { useEffect, useState } from 'react';\nimport { WebsocketMessage, IN_APP_MESSAGES_PAGE_SIZE } from '@dashx/browser';\nimport type { InAppMessages, WebsocketMessageType } from '@dashx/browser';\n\nimport useDashXProvider from './use-dashx-provider.js';\nimport { useWebSocket } from '../providers/DashXProvider.js';\n\ntype UseInAppHookResponse = {\n messages: InAppMessages;\n unreadMessagesCount: number | null;\n hasMore: boolean;\n isLoadingMore: boolean;\n loadMore: () => Promise<void>;\n markMessageAsRead: (id: string) => Promise<any>;\n markMessageAsUnread: (id: string) => Promise<any>;\n markAllMessagesAsRead: () => Promise<any>;\n};\n\ntype UseInAppOptions = {\n /**\n * Fires a react-hot-toast for every live IN_APP_MESSAGE. Only useful with a mounted\n * `<Toast>`, which is also what runs react-hot-toast's expiration timers - without one\n * the toasts never render and its store just retains the last few entries. Set false\n * when the host renders its own notification stack.\n */\n showToast?: boolean;\n};\n\nconst useInApp = ({ showToast = true }: UseInAppOptions = {}): UseInAppHookResponse => {\n let dashX = useDashXProvider();\n const { subscribe } = useWebSocket();\n const [messages, setMessages] = useState<InAppMessages>([]);\n const [unreadMessagesCount, setUnreadMessagesCount] = useState<number | null>(null);\n const [hasMore, setHasMore] = useState(false);\n const [isLoadingMore, setIsLoadingMore] = useState(false);\n\n const markMessageAsRead = (id: string) =>\n dashX.trackMessage({ id, status: 'READ' }).catch((error: unknown) => {\n console.error('DashX: failed to mark in-app message as read', error);\n });\n\n const markMessageAsUnread = (id: string) =>\n dashX.trackMessage({ id, status: 'UNREAD' }).catch((error: unknown) => {\n console.error('DashX: failed to mark in-app message as unread', error);\n });\n\n const markAllMessagesAsRead = () =>\n dashX.trackAllMessages().catch((error: unknown) => {\n console.error('DashX: failed to mark all in-app messages as read', error);\n });\n\n const loadMore = async () => {\n if (isLoadingMore || !hasMore) return;\n setIsLoadingMore(true);\n try {\n const { hasMore: more } = await dashX.fetchMoreInAppMessages();\n setHasMore(more);\n } catch (error) {\n // hasMore stays true so a later scroll retries the page.\n console.error('DashX: failed to fetch more in-app messages', error);\n } finally {\n setIsLoadingMore(false);\n }\n };\n\n useEffect(() => {\n // Set up in-app message watchers (automatically refetch on WebSocket reconnection)\n dashX.watchFetchInAppMessages((nextMessages) => {\n setMessages(nextMessages);\n // While the list is a single page (initial load, empty inbox, or a reconnect\n // refetch of page 1), a full page implies more; past that, loadMore owns hasMore.\n if (nextMessages.length <= IN_APP_MESSAGES_PAGE_SIZE) {\n setHasMore(nextMessages.length === IN_APP_MESSAGES_PAGE_SIZE);\n }\n });\n dashX.watchFetchInAppMessagesAggregate(setUnreadMessagesCount);\n }, [dashX]);\n\n useEffect(() => {\n if (!showToast) return;\n\n // Subscribe to WebSocket messages for in-app messages\n const unsubscribe = subscribe((message: WebsocketMessageType) => {\n // Handle only IN_APP_MESSAGE for toast display\n // The client handles all other message processing internally\n if (message?.type === WebsocketMessage.IN_APP_MESSAGE) {\n toast(message.data.renderedContent.body);\n }\n });\n\n return unsubscribe;\n }, [subscribe, showToast]);\n\n return {\n messages,\n unreadMessagesCount,\n hasMore,\n isLoadingMore,\n loadMore,\n markMessageAsRead,\n markMessageAsUnread,\n markAllMessagesAsRead,\n };\n};\n\nexport default useInApp;\nexport type { UseInAppOptions };\n"],
5
+ "mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkB,8BAClBC,EAAoC,iBACpCC,EAA4D,0BAG5DC,EAA6B,sCAC7BC,EAA6B,yCAuB7B,MAAMC,EAAW,CAAC,CAAE,UAAAC,EAAY,EAAK,EAAqB,CAAC,IAA4B,CACrF,IAAIC,KAAQ,EAAAC,SAAiB,EAC7B,KAAM,CAAE,UAAAC,CAAU,KAAI,gBAAa,EAC7B,CAACC,EAAUC,CAAW,KAAI,YAAwB,CAAC,CAAC,EACpD,CAACC,EAAqBC,CAAsB,KAAI,YAAwB,IAAI,EAC5E,CAACC,EAASC,CAAU,KAAI,YAAS,EAAK,EACtC,CAACC,EAAeC,CAAgB,KAAI,YAAS,EAAK,EAElDC,EAAqBC,GACzBZ,EAAM,aAAa,CAAE,GAAAY,EAAI,OAAQ,MAAO,CAAC,EAAE,MAAOC,GAAmB,CACnE,QAAQ,MAAM,+CAAgDA,CAAK,CACrE,CAAC,EAEGC,EAAuBF,GAC3BZ,EAAM,aAAa,CAAE,GAAAY,EAAI,OAAQ,QAAS,CAAC,EAAE,MAAOC,GAAmB,CACrE,QAAQ,MAAM,iDAAkDA,CAAK,CACvE,CAAC,EAEGE,EAAwB,IAC5Bf,EAAM,iBAAiB,EAAE,MAAOa,GAAmB,CACjD,QAAQ,MAAM,oDAAqDA,CAAK,CAC1E,CAAC,EAEGG,EAAW,SAAY,CAC3B,GAAI,EAAAP,GAAiB,CAACF,GACtB,CAAAG,EAAiB,EAAI,EACrB,GAAI,CACF,KAAM,CAAE,QAASO,CAAK,EAAI,MAAMjB,EAAM,uBAAuB,EAC7DQ,EAAWS,CAAI,CACjB,OAASJ,EAAO,CAEd,QAAQ,MAAM,8CAA+CA,CAAK,CACpE,QAAE,CACAH,EAAiB,EAAK,CACxB,EACF,EAEA,sBAAU,IAAM,CAEdV,EAAM,wBAAyBkB,GAAiB,CAC9Cd,EAAYc,CAAY,EAGpBA,EAAa,QAAU,6BACzBV,EAAWU,EAAa,SAAW,2BAAyB,CAEhE,CAAC,EACDlB,EAAM,iCAAiCM,CAAsB,CAC/D,EAAG,CAACN,CAAK,CAAC,KAEV,aAAU,IACHD,EAGeG,EAAWiB,GAAkC,CAG3DA,GAAS,OAAS,mBAAiB,mBACrC,EAAAC,SAAMD,EAAQ,KAAK,gBAAgB,IAAI,CAE3C,CAAC,EATe,OAYf,CAACjB,EAAWH,CAAS,CAAC,EAElB,CACL,SAAAI,EACA,oBAAAE,EACA,QAAAE,EACA,cAAAE,EACA,SAAAO,EACA,kBAAAL,EACA,oBAAAG,EACA,sBAAAC,CACF,CACF,EAEA,IAAOxB,EAAQO",
6
+ "names": ["use_in_app_exports", "__export", "use_in_app_default", "__toCommonJS", "import_react_hot_toast", "import_react", "import_browser", "import_use_dashx_provider", "import_DashXProvider", "useInApp", "showToast", "dashX", "useDashXProvider", "subscribe", "messages", "setMessages", "unreadMessagesCount", "setUnreadMessagesCount", "hasMore", "setHasMore", "isLoadingMore", "setIsLoadingMore", "markMessageAsRead", "id", "error", "markMessageAsUnread", "markAllMessagesAsRead", "loadMore", "more", "nextMessages", "message", "toast"]
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,EAAA,6BAjBRC,EAAmC,oBAEnCC,EAAyB,6BACzBC,EAA2E,yBAC3EC,EAAyC,6BAEzC,MAAMC,EAAmB,IAAM,CAC7B,GAAI,CACF,uBAAAC,EACA,yBAAAC,EACA,cAAAC,EACA,yBAAAC,CACF,KAAI,YAAS,EAEb,SACE,OAAC,SACC,oBAAC,UAAQ,KAAR,CACC,qBAAC,UAAQ,KAAR,CACC,oBAAC,UAAQ,QAAR,CACC,mBAAC,UAAQ,QAAR,CACC,mBAAC,UACC,MAAM,SACN,UAAU,OACV,QAASA,EAA2B,OAAS,QAE7C,mBAAC,UAAM,EACT,EACF,EACF,KACA,OAAC,UAAQ,QAAR,CAAgB,QAAQ,eAAe,GAC1C,KACA,QAAC,UAAQ,QAAR,CAAgB,QAAQ,QAAQ,MAAM,QAAQ,OAAO,QACpD,oBAAC,UAAQ,OAAR,CAAe,QAAO,GACrB,oBAAC,QAAK,QAAQ,UAAU,MAAM,SAC5B,oBAAC,WAAQ,KAAM,EAAG,yBAAa,KAC/B,OAAC,UAAQ,MAAR,CACC,mBAAC,UAAO,MAAM,SAAS,UAAU,OAAO,QAAQ,QAAQ,KAAK,SAAS,MAAM,QAC1E,mBAAC,MAAE,EACL,EACF,GACF,EACF,KACA,OAAC,UAAQ,KAAR,CACC,oBAAC,QAAK,UAAU,SAAS,IAAK,EAC3B,UAAAD,EAAc,SAAW,MACxB,OAAC,QAAK,QAAQ,SAAS,MAAM,SAC3B,mBAAC,QAAK,QAAQ,WAAW,KAAM,EAAG,iCAElC,EACF,EAEDA,EAAc,IAAKE,MAClB,OAAC,QACC,oBAAC,QAAK,MAAM,SAAS,IAAK,EAAG,QAAQ,UACnC,qBAAC,QAAK,UAAU,SAAS,IAAK,EAC5B,oBAAC,QAAK,GAAG,IAAI,QAAQ,YAAY,OAAO,WAAW,KAAM,EACtD,SAAAA,EAAa,gBAAgB,KAChC,KACA,OAAC,QAAK,KAAM,EAAG,QAAQ,WACpB,kCAAmBA,EAAa,OAAQ,IAAI,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
+ }
@@ -9,7 +9,7 @@ type UseInAppChatNotificationsProps = {
9
9
  isOpen: boolean;
10
10
  enabled?: boolean;
11
11
  options?: InAppChatNotificationOptions;
12
- onActivate?: () => void;
12
+ onActivate?: (message: InAppChatMessageData) => void;
13
13
  };
14
14
  /**
15
15
  * Foreground browser notifications for incoming In-App Chat messages. Returns a
@@ -1,2 +1,2 @@
1
- import{useCallback as s,useRef as o}from"react";import I from"./use-dashx-provider.js";const y=t=>typeof t=="string"?t:t?.text??t?.body??"",A=({isOpen:t,enabled:a=!0,options:c,onActivate:u})=>{const e=I(),p=o(t);p.current=t;const i=o(a);i.current=a;const n=o(c);n.current=c;const f=o(u);f.current=u;const h=()=>!(!p.current||typeof document>"u"||document.hidden||typeof document.hasFocus=="function"&&!document.hasFocus()),l=s(r=>{if(!i.current||(r.aiRole??"").toUpperCase()==="USER"||h())return;const d=n.current?.renderBody?.(r)??y(r.renderedContent);d&&e.showInAppChatNotification?.({title:n.current?.title??"New message",body:d,icon:n.current?.icon,tag:r.conversationId?`in_app_chat:${r.conversationId}`:void 0,onClick:()=>f.current?.()})},[e]),m=s(()=>e.requestNotificationPermission?.()??Promise.resolve("denied"),[e]),C=s(()=>{i.current&&(n.current?.requestPermissionOn??"firstOpen")==="firstOpen"&&e.requestNotificationPermission?.().catch(()=>{})},[e]);return{handleInboundMessage:l,requestPermission:m,requestPermissionOnOpen:C}};var P=A;export{P as default};
1
+ import{useCallback as s,useRef as o}from"react";import I from"./use-dashx-provider.js";const A=t=>typeof t=="string"?t:t?.text??t?.body??"",y=({isOpen:t,enabled:a=!0,options:p,onActivate:c})=>{const e=I(),u=o(t);u.current=t;const i=o(a);i.current=a;const r=o(p);r.current=p;const f=o(c);f.current=c;const h=()=>!(!u.current||typeof document>"u"||document.hidden||typeof document.hasFocus=="function"&&!document.hasFocus()),l=s(n=>{if(!i.current||(n.aiRole??"").toUpperCase()==="USER"||h())return;const d=r.current?.renderBody?.(n)??A(n.renderedContent);d&&e.showInAppChatNotification?.({title:r.current?.title??"New message",body:d,icon:r.current?.icon,tag:n.conversationId?`in_app_chat:${n.conversationId}`:void 0,onClick:()=>f.current?.(n)})},[e]),C=s(()=>e.requestNotificationPermission?.()??Promise.resolve("denied"),[e]),m=s(()=>{i.current&&(r.current?.requestPermissionOn??"firstOpen")==="firstOpen"&&e.requestNotificationPermission?.().catch(()=>{})},[e]);return{handleInboundMessage:l,requestPermission:C,requestPermissionOnOpen:m}};var P=y;export{P as default};
2
2
  //# sourceMappingURL=use-in-app-chat-notifications.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/hooks/use-in-app-chat-notifications.ts"],
4
- "sourcesContent": ["import { useCallback, useRef } from 'react';\nimport type { InAppChatMessageData } from '@dashx/browser';\n\nimport useDashXProvider from './use-dashx-provider.js';\n\ntype InAppChatNotificationOptions = {\n // Notification title. Defaults to 'New message'.\n title?: string;\n // Icon URL shown in the notification.\n icon?: string;\n // Custom body text from the inbound message; defaults to the message text.\n renderBody?: (message: InAppChatMessageData) => string;\n // When to request notification permission. 'firstOpen' (the default for the\n // launcher) requests it the first time the visitor opens chat \u2014 a real user\n // gesture, which browsers require for a non-penalized prompt. 'manual' never\n // auto-requests (use for always-visible surfaces, where the embedder drives\n // the prompt via the returned `requestPermission`).\n requestPermissionOn?: 'firstOpen' | 'manual';\n};\n\ntype UseInAppChatNotificationsProps = {\n // Whether the chat surface is currently open/visible. Combined with tab\n // visibility + window focus to decide if the visitor is actively looking at\n // chat (in which case we don't notify).\n isOpen: boolean;\n // `false` disables notifications entirely.\n enabled?: boolean;\n options?: InAppChatNotificationOptions;\n // Invoked when the visitor clicks a notification \u2014 focus is handled by the\n // SDK; this opens the chat panel.\n onActivate?: () => void;\n};\n\nconst textFromContent = (content: any): string => {\n if (typeof content === 'string') return content;\n return content?.text ?? content?.body ?? '';\n};\n\n/**\n * Foreground browser notifications for incoming In-App Chat messages. Returns a\n * `handleInboundMessage` to pass as `useInAppChat`'s `onInboundMessage`; it\n * fires a notification only for agent/AI replies that arrive while the chat\n * isn't focused (panel closed, or tab hidden/unfocused) and only once the\n * visitor has granted permission.\n */\nconst useInAppChatNotifications = ({\n isOpen,\n enabled = true,\n options,\n onActivate,\n}: UseInAppChatNotificationsProps) => {\n const dashX = useDashXProvider();\n\n // Latest values for the message handler, so it stays referentially stable\n // (it's wired into the chat hook's subscription).\n const isOpenRef = useRef(isOpen);\n isOpenRef.current = isOpen;\n const enabledRef = useRef(enabled);\n enabledRef.current = enabled;\n const optionsRef = useRef(options);\n optionsRef.current = options;\n const onActivateRef = useRef(onActivate);\n onActivateRef.current = onActivate;\n\n const isChatFocused = (): boolean => {\n if (!isOpenRef.current) return false;\n if (typeof document === 'undefined') return false;\n if (document.hidden) return false;\n if (typeof document.hasFocus === 'function' && !document.hasFocus()) return false;\n return true;\n };\n\n const handleInboundMessage = useCallback(\n (message: InAppChatMessageData) => {\n if (!enabledRef.current) return;\n // Agent/AI replies only \u2014 never the visitor's own echoed message.\n if ((message.aiRole ?? '').toUpperCase() === 'USER') return;\n // Don't interrupt a visitor who's actively looking at the chat.\n if (isChatFocused()) return;\n\n const body = optionsRef.current?.renderBody?.(message) ?? textFromContent(message.renderedContent);\n if (!body) return;\n\n dashX.showInAppChatNotification?.({\n title: optionsRef.current?.title ?? 'New message',\n body,\n icon: optionsRef.current?.icon,\n tag: message.conversationId ? `in_app_chat:${message.conversationId}` : undefined,\n onClick: () => onActivateRef.current?.(),\n });\n },\n [dashX],\n );\n\n const requestPermission = useCallback(\n () => dashX.requestNotificationPermission?.() ?? Promise.resolve('denied' as const),\n [dashX],\n );\n\n // Call this SYNCHRONOUSLY from the surface's open event (a real user gesture)\n // so the permission prompt lands inside the browser's transient activation\n // window. Requesting from an effect after the click has unwound is\n // ignored/rejected by some browsers. Honors `requestPermissionOn` ('manual'\n // skips it), and is safe to call on every open (no-ops once permission is\n // decided \u2014 see Client.requestNotificationPermission).\n const requestPermissionOnOpen = useCallback(() => {\n if (!enabledRef.current) return;\n if ((optionsRef.current?.requestPermissionOn ?? 'firstOpen') !== 'firstOpen') return;\n dashX.requestNotificationPermission?.().catch(() => {});\n }, [dashX]);\n\n return { handleInboundMessage, requestPermission, requestPermissionOnOpen };\n};\n\nexport type { InAppChatNotificationOptions, UseInAppChatNotificationsProps };\n\nexport default useInAppChatNotifications;\n"],
5
- "mappings": "AAAA,OAAS,eAAAA,EAAa,UAAAC,MAAc,QAGpC,OAAOC,MAAsB,0BA8B7B,MAAMC,EAAmBC,GACnB,OAAOA,GAAY,SAAiBA,EACjCA,GAAS,MAAQA,GAAS,MAAQ,GAUrCC,EAA4B,CAAC,CACjC,OAAAC,EACA,QAAAC,EAAU,GACV,QAAAC,EACA,WAAAC,CACF,IAAsC,CACpC,MAAMC,EAAQR,EAAiB,EAIzBS,EAAYV,EAAOK,CAAM,EAC/BK,EAAU,QAAUL,EACpB,MAAMM,EAAaX,EAAOM,CAAO,EACjCK,EAAW,QAAUL,EACrB,MAAMM,EAAaZ,EAAOO,CAAO,EACjCK,EAAW,QAAUL,EACrB,MAAMM,EAAgBb,EAAOQ,CAAU,EACvCK,EAAc,QAAUL,EAExB,MAAMM,EAAgB,IAChB,GAACJ,EAAU,SACX,OAAO,SAAa,KACpB,SAAS,QACT,OAAO,SAAS,UAAa,YAAc,CAAC,SAAS,SAAS,GAI9DK,EAAuBhB,EAC1BiB,GAAkC,CAKjC,GAJI,CAACL,EAAW,UAEXK,EAAQ,QAAU,IAAI,YAAY,IAAM,QAEzCF,EAAc,EAAG,OAErB,MAAMG,EAAOL,EAAW,SAAS,aAAaI,CAAO,GAAKd,EAAgBc,EAAQ,eAAe,EAC5FC,GAELR,EAAM,4BAA4B,CAChC,MAAOG,EAAW,SAAS,OAAS,cACpC,KAAAK,EACA,KAAML,EAAW,SAAS,KAC1B,IAAKI,EAAQ,eAAiB,eAAeA,EAAQ,cAAc,GAAK,OACxE,QAAS,IAAMH,EAAc,UAAU,CACzC,CAAC,CACH,EACA,CAACJ,CAAK,CACR,EAEMS,EAAoBnB,EACxB,IAAMU,EAAM,gCAAgC,GAAK,QAAQ,QAAQ,QAAiB,EAClF,CAACA,CAAK,CACR,EAQMU,EAA0BpB,EAAY,IAAM,CAC3CY,EAAW,UACXC,EAAW,SAAS,qBAAuB,eAAiB,aACjEH,EAAM,gCAAgC,EAAE,MAAM,IAAM,CAAC,CAAC,CACxD,EAAG,CAACA,CAAK,CAAC,EAEV,MAAO,CAAE,qBAAAM,EAAsB,kBAAAG,EAAmB,wBAAAC,CAAwB,CAC5E,EAIA,IAAOC,EAAQhB",
4
+ "sourcesContent": ["import { useCallback, useRef } from 'react';\nimport type { InAppChatMessageData } from '@dashx/browser';\n\nimport useDashXProvider from './use-dashx-provider.js';\n\ntype InAppChatNotificationOptions = {\n // Notification title. Defaults to 'New message'.\n title?: string;\n // Icon URL shown in the notification.\n icon?: string;\n // Custom body text from the inbound message; defaults to the message text.\n renderBody?: (message: InAppChatMessageData) => string;\n // When to request notification permission. 'firstOpen' (the default for the\n // launcher) requests it the first time the visitor opens chat \u2014 a real user\n // gesture, which browsers require for a non-penalized prompt. 'manual' never\n // auto-requests (use for always-visible surfaces, where the embedder drives\n // the prompt via the returned `requestPermission`).\n requestPermissionOn?: 'firstOpen' | 'manual';\n};\n\ntype UseInAppChatNotificationsProps = {\n // Whether the chat surface is currently open/visible. Combined with tab\n // visibility + window focus to decide if the visitor is actively looking at\n // chat (in which case we don't notify).\n isOpen: boolean;\n // `false` disables notifications entirely.\n enabled?: boolean;\n options?: InAppChatNotificationOptions;\n // Invoked when the visitor clicks a notification \u2014 focus is handled by the\n // SDK; this opens the chat panel. Receives the message that raised THAT\n // notification, so a surface watching several conversations can open the right\n // one: without it, every notification resolves to whichever arrived last.\n onActivate?: (message: InAppChatMessageData) => void;\n};\n\nconst textFromContent = (content: any): string => {\n if (typeof content === 'string') return content;\n return content?.text ?? content?.body ?? '';\n};\n\n/**\n * Foreground browser notifications for incoming In-App Chat messages. Returns a\n * `handleInboundMessage` to pass as `useInAppChat`'s `onInboundMessage`; it\n * fires a notification only for agent/AI replies that arrive while the chat\n * isn't focused (panel closed, or tab hidden/unfocused) and only once the\n * visitor has granted permission.\n */\nconst useInAppChatNotifications = ({\n isOpen,\n enabled = true,\n options,\n onActivate,\n}: UseInAppChatNotificationsProps) => {\n const dashX = useDashXProvider();\n\n // Latest values for the message handler, so it stays referentially stable\n // (it's wired into the chat hook's subscription).\n const isOpenRef = useRef(isOpen);\n isOpenRef.current = isOpen;\n const enabledRef = useRef(enabled);\n enabledRef.current = enabled;\n const optionsRef = useRef(options);\n optionsRef.current = options;\n const onActivateRef = useRef(onActivate);\n onActivateRef.current = onActivate;\n\n const isChatFocused = (): boolean => {\n if (!isOpenRef.current) return false;\n if (typeof document === 'undefined') return false;\n if (document.hidden) return false;\n if (typeof document.hasFocus === 'function' && !document.hasFocus()) return false;\n return true;\n };\n\n const handleInboundMessage = useCallback(\n (message: InAppChatMessageData) => {\n if (!enabledRef.current) return;\n // Agent/AI replies only \u2014 never the visitor's own echoed message.\n if ((message.aiRole ?? '').toUpperCase() === 'USER') return;\n // Don't interrupt a visitor who's actively looking at the chat.\n if (isChatFocused()) return;\n\n const body = optionsRef.current?.renderBody?.(message) ?? textFromContent(message.renderedContent);\n if (!body) return;\n\n dashX.showInAppChatNotification?.({\n title: optionsRef.current?.title ?? 'New message',\n body,\n icon: optionsRef.current?.icon,\n tag: message.conversationId ? `in_app_chat:${message.conversationId}` : undefined,\n onClick: () => onActivateRef.current?.(message),\n });\n },\n [dashX],\n );\n\n const requestPermission = useCallback(\n () => dashX.requestNotificationPermission?.() ?? Promise.resolve('denied' as const),\n [dashX],\n );\n\n // Call this SYNCHRONOUSLY from the surface's open event (a real user gesture)\n // so the permission prompt lands inside the browser's transient activation\n // window. Requesting from an effect after the click has unwound is\n // ignored/rejected by some browsers. Honors `requestPermissionOn` ('manual'\n // skips it), and is safe to call on every open (no-ops once permission is\n // decided \u2014 see Client.requestNotificationPermission).\n const requestPermissionOnOpen = useCallback(() => {\n if (!enabledRef.current) return;\n if ((optionsRef.current?.requestPermissionOn ?? 'firstOpen') !== 'firstOpen') return;\n dashX.requestNotificationPermission?.().catch(() => {});\n }, [dashX]);\n\n return { handleInboundMessage, requestPermission, requestPermissionOnOpen };\n};\n\nexport type { InAppChatNotificationOptions, UseInAppChatNotificationsProps };\n\nexport default useInAppChatNotifications;\n"],
5
+ "mappings": "AAAA,OAAS,eAAAA,EAAa,UAAAC,MAAc,QAGpC,OAAOC,MAAsB,0BAgC7B,MAAMC,EAAmBC,GACnB,OAAOA,GAAY,SAAiBA,EACjCA,GAAS,MAAQA,GAAS,MAAQ,GAUrCC,EAA4B,CAAC,CACjC,OAAAC,EACA,QAAAC,EAAU,GACV,QAAAC,EACA,WAAAC,CACF,IAAsC,CACpC,MAAMC,EAAQR,EAAiB,EAIzBS,EAAYV,EAAOK,CAAM,EAC/BK,EAAU,QAAUL,EACpB,MAAMM,EAAaX,EAAOM,CAAO,EACjCK,EAAW,QAAUL,EACrB,MAAMM,EAAaZ,EAAOO,CAAO,EACjCK,EAAW,QAAUL,EACrB,MAAMM,EAAgBb,EAAOQ,CAAU,EACvCK,EAAc,QAAUL,EAExB,MAAMM,EAAgB,IAChB,GAACJ,EAAU,SACX,OAAO,SAAa,KACpB,SAAS,QACT,OAAO,SAAS,UAAa,YAAc,CAAC,SAAS,SAAS,GAI9DK,EAAuBhB,EAC1BiB,GAAkC,CAKjC,GAJI,CAACL,EAAW,UAEXK,EAAQ,QAAU,IAAI,YAAY,IAAM,QAEzCF,EAAc,EAAG,OAErB,MAAMG,EAAOL,EAAW,SAAS,aAAaI,CAAO,GAAKd,EAAgBc,EAAQ,eAAe,EAC5FC,GAELR,EAAM,4BAA4B,CAChC,MAAOG,EAAW,SAAS,OAAS,cACpC,KAAAK,EACA,KAAML,EAAW,SAAS,KAC1B,IAAKI,EAAQ,eAAiB,eAAeA,EAAQ,cAAc,GAAK,OACxE,QAAS,IAAMH,EAAc,UAAUG,CAAO,CAChD,CAAC,CACH,EACA,CAACP,CAAK,CACR,EAEMS,EAAoBnB,EACxB,IAAMU,EAAM,gCAAgC,GAAK,QAAQ,QAAQ,QAAiB,EAClF,CAACA,CAAK,CACR,EAQMU,EAA0BpB,EAAY,IAAM,CAC3CY,EAAW,UACXC,EAAW,SAAS,qBAAuB,eAAiB,aACjEH,EAAM,gCAAgC,EAAE,MAAM,IAAM,CAAC,CAAC,CACxD,EAAG,CAACA,CAAK,CAAC,EAEV,MAAO,CAAE,qBAAAM,EAAsB,kBAAAG,EAAmB,wBAAAC,CAAwB,CAC5E,EAIA,IAAOC,EAAQhB",
6
6
  "names": ["useCallback", "useRef", "useDashXProvider", "textFromContent", "content", "useInAppChatNotifications", "isOpen", "enabled", "options", "onActivate", "dashX", "isOpenRef", "enabledRef", "optionsRef", "onActivateRef", "isChatFocused", "handleInboundMessage", "message", "body", "requestPermission", "requestPermissionOnOpen", "use_in_app_chat_notifications_default"]
7
7
  }
@@ -9,5 +9,15 @@ type UseInAppHookResponse = {
9
9
  markMessageAsUnread: (id: string) => Promise<any>;
10
10
  markAllMessagesAsRead: () => Promise<any>;
11
11
  };
12
- declare const useInApp: () => UseInAppHookResponse;
12
+ type UseInAppOptions = {
13
+ /**
14
+ * Fires a react-hot-toast for every live IN_APP_MESSAGE. Only useful with a mounted
15
+ * `<Toast>`, which is also what runs react-hot-toast's expiration timers - without one
16
+ * the toasts never render and its store just retains the last few entries. Set false
17
+ * when the host renders its own notification stack.
18
+ */
19
+ showToast?: boolean;
20
+ };
21
+ declare const useInApp: ({ showToast }?: UseInAppOptions) => UseInAppHookResponse;
13
22
  export default useInApp;
23
+ export type { UseInAppOptions };
@@ -1,2 +1,2 @@
1
- import k from"react-hot-toast";import{useEffect as i,useState as o}from"react";import{WebsocketMessage as b,IN_APP_MESSAGES_PAGE_SIZE as g}from"@dashx/browser";import I from"./use-dashx-provider.js";import{useWebSocket as y}from"../providers/DashXProvider.js";const P=()=>{let s=I();const{subscribe:r}=y(),[l,m]=o([]),[d,M]=o(null),[n,t]=o(!1),[c,p]=o(!1),u=e=>s.trackMessage({id:e,status:"READ"}).catch(a=>{console.error("DashX: failed to mark in-app message as read",a)}),A=e=>s.trackMessage({id:e,status:"UNREAD"}).catch(a=>{console.error("DashX: failed to mark in-app message as unread",a)}),f=()=>s.trackAllMessages().catch(e=>{console.error("DashX: failed to mark all in-app messages as read",e)}),h=async()=>{if(!(c||!n)){p(!0);try{const{hasMore:e}=await s.fetchMoreInAppMessages();t(e)}catch(e){console.error("DashX: failed to fetch more in-app messages",e)}finally{p(!1)}}};return i(()=>{s.watchFetchInAppMessages(e=>{m(e),e.length<=g&&t(e.length===g)}),s.watchFetchInAppMessagesAggregate(M)},[s]),i(()=>r(a=>{a?.type===b.IN_APP_MESSAGE&&k(a.data.renderedContent.body)}),[r]),{messages:l,unreadMessagesCount:d,hasMore:n,isLoadingMore:c,loadMore:h,markMessageAsRead:u,markMessageAsUnread:A,markAllMessagesAsRead:f}};var U=P;export{U as default};
1
+ import b from"react-hot-toast";import{useEffect as g,useState as o}from"react";import{WebsocketMessage as I,IN_APP_MESSAGES_PAGE_SIZE as l}from"@dashx/browser";import y from"./use-dashx-provider.js";import{useWebSocket as P}from"../providers/DashXProvider.js";const E=({showToast:r=!0}={})=>{let s=y();const{subscribe:n}=P(),[m,u]=o([]),[d,M]=o(null),[t,p]=o(!1),[i,c]=o(!1),A=e=>s.trackMessage({id:e,status:"READ"}).catch(a=>{console.error("DashX: failed to mark in-app message as read",a)}),f=e=>s.trackMessage({id:e,status:"UNREAD"}).catch(a=>{console.error("DashX: failed to mark in-app message as unread",a)}),h=()=>s.trackAllMessages().catch(e=>{console.error("DashX: failed to mark all in-app messages as read",e)}),k=async()=>{if(!(i||!t)){c(!0);try{const{hasMore:e}=await s.fetchMoreInAppMessages();p(e)}catch(e){console.error("DashX: failed to fetch more in-app messages",e)}finally{c(!1)}}};return g(()=>{s.watchFetchInAppMessages(e=>{u(e),e.length<=l&&p(e.length===l)}),s.watchFetchInAppMessagesAggregate(M)},[s]),g(()=>r?n(a=>{a?.type===I.IN_APP_MESSAGE&&b(a.data.renderedContent.body)}):void 0,[n,r]),{messages:m,unreadMessagesCount:d,hasMore:t,isLoadingMore:i,loadMore:k,markMessageAsRead:A,markMessageAsUnread:f,markAllMessagesAsRead:h}};var X=E;export{X as default};
2
2
  //# sourceMappingURL=use-in-app.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/hooks/use-in-app.ts"],
4
- "sourcesContent": ["import toast from 'react-hot-toast';\nimport { useEffect, useState } from 'react';\nimport { WebsocketMessage, IN_APP_MESSAGES_PAGE_SIZE } from '@dashx/browser';\nimport type { InAppMessages, WebsocketMessageType } from '@dashx/browser';\n\nimport useDashXProvider from './use-dashx-provider.js';\nimport { useWebSocket } from '../providers/DashXProvider.js';\n\ntype UseInAppHookResponse = {\n messages: InAppMessages;\n unreadMessagesCount: number | null;\n hasMore: boolean;\n isLoadingMore: boolean;\n loadMore: () => Promise<void>;\n markMessageAsRead: (id: string) => Promise<any>;\n markMessageAsUnread: (id: string) => Promise<any>;\n markAllMessagesAsRead: () => Promise<any>;\n};\n\nconst useInApp = (): UseInAppHookResponse => {\n let dashX = useDashXProvider();\n const { subscribe } = useWebSocket();\n const [messages, setMessages] = useState<InAppMessages>([]);\n const [unreadMessagesCount, setUnreadMessagesCount] = useState<number | null>(null);\n const [hasMore, setHasMore] = useState(false);\n const [isLoadingMore, setIsLoadingMore] = useState(false);\n\n const markMessageAsRead = (id: string) =>\n dashX.trackMessage({ id, status: 'READ' }).catch((error: unknown) => {\n console.error('DashX: failed to mark in-app message as read', error);\n });\n\n const markMessageAsUnread = (id: string) =>\n dashX.trackMessage({ id, status: 'UNREAD' }).catch((error: unknown) => {\n console.error('DashX: failed to mark in-app message as unread', error);\n });\n\n const markAllMessagesAsRead = () =>\n dashX.trackAllMessages().catch((error: unknown) => {\n console.error('DashX: failed to mark all in-app messages as read', error);\n });\n\n const loadMore = async () => {\n if (isLoadingMore || !hasMore) return;\n setIsLoadingMore(true);\n try {\n const { hasMore: more } = await dashX.fetchMoreInAppMessages();\n setHasMore(more);\n } catch (error) {\n // hasMore stays true so a later scroll retries the page.\n console.error('DashX: failed to fetch more in-app messages', error);\n } finally {\n setIsLoadingMore(false);\n }\n };\n\n useEffect(() => {\n // Set up in-app message watchers (automatically refetch on WebSocket reconnection)\n dashX.watchFetchInAppMessages((nextMessages) => {\n setMessages(nextMessages);\n // While the list is a single page (initial load, empty inbox, or a reconnect\n // refetch of page 1), a full page implies more; past that, loadMore owns hasMore.\n if (nextMessages.length <= IN_APP_MESSAGES_PAGE_SIZE) {\n setHasMore(nextMessages.length === IN_APP_MESSAGES_PAGE_SIZE);\n }\n });\n dashX.watchFetchInAppMessagesAggregate(setUnreadMessagesCount);\n }, [dashX]);\n\n useEffect(() => {\n // Subscribe to WebSocket messages for in-app messages\n const unsubscribe = subscribe((message: WebsocketMessageType) => {\n // Handle only IN_APP_MESSAGE for toast display\n // The client handles all other message processing internally\n if (message?.type === WebsocketMessage.IN_APP_MESSAGE) {\n toast(message.data.renderedContent.body);\n }\n });\n\n return unsubscribe;\n }, [subscribe]);\n\n return {\n messages,\n unreadMessagesCount,\n hasMore,\n isLoadingMore,\n loadMore,\n markMessageAsRead,\n markMessageAsUnread,\n markAllMessagesAsRead,\n };\n};\n\nexport default useInApp;\n"],
5
- "mappings": "AAAA,OAAOA,MAAW,kBAClB,OAAS,aAAAC,EAAW,YAAAC,MAAgB,QACpC,OAAS,oBAAAC,EAAkB,6BAAAC,MAAiC,iBAG5D,OAAOC,MAAsB,0BAC7B,OAAS,gBAAAC,MAAoB,gCAa7B,MAAMC,EAAW,IAA4B,CAC3C,IAAIC,EAAQH,EAAiB,EAC7B,KAAM,CAAE,UAAAI,CAAU,EAAIH,EAAa,EAC7B,CAACI,EAAUC,CAAW,EAAIT,EAAwB,CAAC,CAAC,EACpD,CAACU,EAAqBC,CAAsB,EAAIX,EAAwB,IAAI,EAC5E,CAACY,EAASC,CAAU,EAAIb,EAAS,EAAK,EACtC,CAACc,EAAeC,CAAgB,EAAIf,EAAS,EAAK,EAElDgB,EAAqBC,GACzBX,EAAM,aAAa,CAAE,GAAAW,EAAI,OAAQ,MAAO,CAAC,EAAE,MAAOC,GAAmB,CACnE,QAAQ,MAAM,+CAAgDA,CAAK,CACrE,CAAC,EAEGC,EAAuBF,GAC3BX,EAAM,aAAa,CAAE,GAAAW,EAAI,OAAQ,QAAS,CAAC,EAAE,MAAOC,GAAmB,CACrE,QAAQ,MAAM,iDAAkDA,CAAK,CACvE,CAAC,EAEGE,EAAwB,IAC5Bd,EAAM,iBAAiB,EAAE,MAAOY,GAAmB,CACjD,QAAQ,MAAM,oDAAqDA,CAAK,CAC1E,CAAC,EAEGG,EAAW,SAAY,CAC3B,GAAI,EAAAP,GAAiB,CAACF,GACtB,CAAAG,EAAiB,EAAI,EACrB,GAAI,CACF,KAAM,CAAE,QAASO,CAAK,EAAI,MAAMhB,EAAM,uBAAuB,EAC7DO,EAAWS,CAAI,CACjB,OAASJ,EAAO,CAEd,QAAQ,MAAM,8CAA+CA,CAAK,CACpE,QAAE,CACAH,EAAiB,EAAK,CACxB,EACF,EAEA,OAAAhB,EAAU,IAAM,CAEdO,EAAM,wBAAyBiB,GAAiB,CAC9Cd,EAAYc,CAAY,EAGpBA,EAAa,QAAUrB,GACzBW,EAAWU,EAAa,SAAWrB,CAAyB,CAEhE,CAAC,EACDI,EAAM,iCAAiCK,CAAsB,CAC/D,EAAG,CAACL,CAAK,CAAC,EAEVP,EAAU,IAEYQ,EAAWiB,GAAkC,CAG3DA,GAAS,OAASvB,EAAiB,gBACrCH,EAAM0B,EAAQ,KAAK,gBAAgB,IAAI,CAE3C,CAAC,EAGA,CAACjB,CAAS,CAAC,EAEP,CACL,SAAAC,EACA,oBAAAE,EACA,QAAAE,EACA,cAAAE,EACA,SAAAO,EACA,kBAAAL,EACA,oBAAAG,EACA,sBAAAC,CACF,CACF,EAEA,IAAOK,EAAQpB",
6
- "names": ["toast", "useEffect", "useState", "WebsocketMessage", "IN_APP_MESSAGES_PAGE_SIZE", "useDashXProvider", "useWebSocket", "useInApp", "dashX", "subscribe", "messages", "setMessages", "unreadMessagesCount", "setUnreadMessagesCount", "hasMore", "setHasMore", "isLoadingMore", "setIsLoadingMore", "markMessageAsRead", "id", "error", "markMessageAsUnread", "markAllMessagesAsRead", "loadMore", "more", "nextMessages", "message", "use_in_app_default"]
4
+ "sourcesContent": ["import toast from 'react-hot-toast';\nimport { useEffect, useState } from 'react';\nimport { WebsocketMessage, IN_APP_MESSAGES_PAGE_SIZE } from '@dashx/browser';\nimport type { InAppMessages, WebsocketMessageType } from '@dashx/browser';\n\nimport useDashXProvider from './use-dashx-provider.js';\nimport { useWebSocket } from '../providers/DashXProvider.js';\n\ntype UseInAppHookResponse = {\n messages: InAppMessages;\n unreadMessagesCount: number | null;\n hasMore: boolean;\n isLoadingMore: boolean;\n loadMore: () => Promise<void>;\n markMessageAsRead: (id: string) => Promise<any>;\n markMessageAsUnread: (id: string) => Promise<any>;\n markAllMessagesAsRead: () => Promise<any>;\n};\n\ntype UseInAppOptions = {\n /**\n * Fires a react-hot-toast for every live IN_APP_MESSAGE. Only useful with a mounted\n * `<Toast>`, which is also what runs react-hot-toast's expiration timers - without one\n * the toasts never render and its store just retains the last few entries. Set false\n * when the host renders its own notification stack.\n */\n showToast?: boolean;\n};\n\nconst useInApp = ({ showToast = true }: UseInAppOptions = {}): UseInAppHookResponse => {\n let dashX = useDashXProvider();\n const { subscribe } = useWebSocket();\n const [messages, setMessages] = useState<InAppMessages>([]);\n const [unreadMessagesCount, setUnreadMessagesCount] = useState<number | null>(null);\n const [hasMore, setHasMore] = useState(false);\n const [isLoadingMore, setIsLoadingMore] = useState(false);\n\n const markMessageAsRead = (id: string) =>\n dashX.trackMessage({ id, status: 'READ' }).catch((error: unknown) => {\n console.error('DashX: failed to mark in-app message as read', error);\n });\n\n const markMessageAsUnread = (id: string) =>\n dashX.trackMessage({ id, status: 'UNREAD' }).catch((error: unknown) => {\n console.error('DashX: failed to mark in-app message as unread', error);\n });\n\n const markAllMessagesAsRead = () =>\n dashX.trackAllMessages().catch((error: unknown) => {\n console.error('DashX: failed to mark all in-app messages as read', error);\n });\n\n const loadMore = async () => {\n if (isLoadingMore || !hasMore) return;\n setIsLoadingMore(true);\n try {\n const { hasMore: more } = await dashX.fetchMoreInAppMessages();\n setHasMore(more);\n } catch (error) {\n // hasMore stays true so a later scroll retries the page.\n console.error('DashX: failed to fetch more in-app messages', error);\n } finally {\n setIsLoadingMore(false);\n }\n };\n\n useEffect(() => {\n // Set up in-app message watchers (automatically refetch on WebSocket reconnection)\n dashX.watchFetchInAppMessages((nextMessages) => {\n setMessages(nextMessages);\n // While the list is a single page (initial load, empty inbox, or a reconnect\n // refetch of page 1), a full page implies more; past that, loadMore owns hasMore.\n if (nextMessages.length <= IN_APP_MESSAGES_PAGE_SIZE) {\n setHasMore(nextMessages.length === IN_APP_MESSAGES_PAGE_SIZE);\n }\n });\n dashX.watchFetchInAppMessagesAggregate(setUnreadMessagesCount);\n }, [dashX]);\n\n useEffect(() => {\n if (!showToast) return;\n\n // Subscribe to WebSocket messages for in-app messages\n const unsubscribe = subscribe((message: WebsocketMessageType) => {\n // Handle only IN_APP_MESSAGE for toast display\n // The client handles all other message processing internally\n if (message?.type === WebsocketMessage.IN_APP_MESSAGE) {\n toast(message.data.renderedContent.body);\n }\n });\n\n return unsubscribe;\n }, [subscribe, showToast]);\n\n return {\n messages,\n unreadMessagesCount,\n hasMore,\n isLoadingMore,\n loadMore,\n markMessageAsRead,\n markMessageAsUnread,\n markAllMessagesAsRead,\n };\n};\n\nexport default useInApp;\nexport type { UseInAppOptions };\n"],
5
+ "mappings": "AAAA,OAAOA,MAAW,kBAClB,OAAS,aAAAC,EAAW,YAAAC,MAAgB,QACpC,OAAS,oBAAAC,EAAkB,6BAAAC,MAAiC,iBAG5D,OAAOC,MAAsB,0BAC7B,OAAS,gBAAAC,MAAoB,gCAuB7B,MAAMC,EAAW,CAAC,CAAE,UAAAC,EAAY,EAAK,EAAqB,CAAC,IAA4B,CACrF,IAAIC,EAAQJ,EAAiB,EAC7B,KAAM,CAAE,UAAAK,CAAU,EAAIJ,EAAa,EAC7B,CAACK,EAAUC,CAAW,EAAIV,EAAwB,CAAC,CAAC,EACpD,CAACW,EAAqBC,CAAsB,EAAIZ,EAAwB,IAAI,EAC5E,CAACa,EAASC,CAAU,EAAId,EAAS,EAAK,EACtC,CAACe,EAAeC,CAAgB,EAAIhB,EAAS,EAAK,EAElDiB,EAAqBC,GACzBX,EAAM,aAAa,CAAE,GAAAW,EAAI,OAAQ,MAAO,CAAC,EAAE,MAAOC,GAAmB,CACnE,QAAQ,MAAM,+CAAgDA,CAAK,CACrE,CAAC,EAEGC,EAAuBF,GAC3BX,EAAM,aAAa,CAAE,GAAAW,EAAI,OAAQ,QAAS,CAAC,EAAE,MAAOC,GAAmB,CACrE,QAAQ,MAAM,iDAAkDA,CAAK,CACvE,CAAC,EAEGE,EAAwB,IAC5Bd,EAAM,iBAAiB,EAAE,MAAOY,GAAmB,CACjD,QAAQ,MAAM,oDAAqDA,CAAK,CAC1E,CAAC,EAEGG,EAAW,SAAY,CAC3B,GAAI,EAAAP,GAAiB,CAACF,GACtB,CAAAG,EAAiB,EAAI,EACrB,GAAI,CACF,KAAM,CAAE,QAASO,CAAK,EAAI,MAAMhB,EAAM,uBAAuB,EAC7DO,EAAWS,CAAI,CACjB,OAASJ,EAAO,CAEd,QAAQ,MAAM,8CAA+CA,CAAK,CACpE,QAAE,CACAH,EAAiB,EAAK,CACxB,EACF,EAEA,OAAAjB,EAAU,IAAM,CAEdQ,EAAM,wBAAyBiB,GAAiB,CAC9Cd,EAAYc,CAAY,EAGpBA,EAAa,QAAUtB,GACzBY,EAAWU,EAAa,SAAWtB,CAAyB,CAEhE,CAAC,EACDK,EAAM,iCAAiCK,CAAsB,CAC/D,EAAG,CAACL,CAAK,CAAC,EAEVR,EAAU,IACHO,EAGeE,EAAWiB,GAAkC,CAG3DA,GAAS,OAASxB,EAAiB,gBACrCH,EAAM2B,EAAQ,KAAK,gBAAgB,IAAI,CAE3C,CAAC,EATe,OAYf,CAACjB,EAAWF,CAAS,CAAC,EAElB,CACL,SAAAG,EACA,oBAAAE,EACA,QAAAE,EACA,cAAAE,EACA,SAAAO,EACA,kBAAAL,EACA,oBAAAG,EACA,sBAAAC,CACF,CACF,EAEA,IAAOK,EAAQrB",
6
+ "names": ["toast", "useEffect", "useState", "WebsocketMessage", "IN_APP_MESSAGES_PAGE_SIZE", "useDashXProvider", "useWebSocket", "useInApp", "showToast", "dashX", "subscribe", "messages", "setMessages", "unreadMessagesCount", "setUnreadMessagesCount", "hasMore", "setHasMore", "isLoadingMore", "setIsLoadingMore", "markMessageAsRead", "id", "error", "markMessageAsUnread", "markAllMessagesAsRead", "loadMore", "more", "nextMessages", "message", "use_in_app_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,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
+ "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.4.0",
3
+ "version": "0.4.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.10.0",
78
+ "@dashx/browser": "^0.11.0",
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",
@@ -27,8 +27,10 @@ type UseInAppChatNotificationsProps = {
27
27
  enabled?: boolean;
28
28
  options?: InAppChatNotificationOptions;
29
29
  // Invoked when the visitor clicks a notification — focus is handled by the
30
- // SDK; this opens the chat panel.
31
- onActivate?: () => void;
30
+ // SDK; this opens the chat panel. Receives the message that raised THAT
31
+ // notification, so a surface watching several conversations can open the right
32
+ // one: without it, every notification resolves to whichever arrived last.
33
+ onActivate?: (message: InAppChatMessageData) => void;
32
34
  };
33
35
 
34
36
  const textFromContent = (content: any): string => {
@@ -86,7 +88,7 @@ const useInAppChatNotifications = ({
86
88
  body,
87
89
  icon: optionsRef.current?.icon,
88
90
  tag: message.conversationId ? `in_app_chat:${message.conversationId}` : undefined,
89
- onClick: () => onActivateRef.current?.(),
91
+ onClick: () => onActivateRef.current?.(message),
90
92
  });
91
93
  },
92
94
  [dashX],
@@ -17,7 +17,17 @@ type UseInAppHookResponse = {
17
17
  markAllMessagesAsRead: () => Promise<any>;
18
18
  };
19
19
 
20
- const useInApp = (): UseInAppHookResponse => {
20
+ type UseInAppOptions = {
21
+ /**
22
+ * Fires a react-hot-toast for every live IN_APP_MESSAGE. Only useful with a mounted
23
+ * `<Toast>`, which is also what runs react-hot-toast's expiration timers - without one
24
+ * the toasts never render and its store just retains the last few entries. Set false
25
+ * when the host renders its own notification stack.
26
+ */
27
+ showToast?: boolean;
28
+ };
29
+
30
+ const useInApp = ({ showToast = true }: UseInAppOptions = {}): UseInAppHookResponse => {
21
31
  let dashX = useDashXProvider();
22
32
  const { subscribe } = useWebSocket();
23
33
  const [messages, setMessages] = useState<InAppMessages>([]);
@@ -68,6 +78,8 @@ const useInApp = (): UseInAppHookResponse => {
68
78
  }, [dashX]);
69
79
 
70
80
  useEffect(() => {
81
+ if (!showToast) return;
82
+
71
83
  // Subscribe to WebSocket messages for in-app messages
72
84
  const unsubscribe = subscribe((message: WebsocketMessageType) => {
73
85
  // Handle only IN_APP_MESSAGE for toast display
@@ -78,7 +90,7 @@ const useInApp = (): UseInAppHookResponse => {
78
90
  });
79
91
 
80
92
  return unsubscribe;
81
- }, [subscribe]);
93
+ }, [subscribe, showToast]);
82
94
 
83
95
  return {
84
96
  messages,
@@ -93,3 +105,4 @@ const useInApp = (): UseInAppHookResponse => {
93
105
  };
94
106
 
95
107
  export default useInApp;
108
+ export type { UseInAppOptions };