@trycourier/courier-react-components 1.2.4 → 2.0.1

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,5 +1,5 @@
1
1
  import { ReactNode } from 'react';
2
- import { CourierInboxListItemActionFactoryProps, CourierInboxListItemFactoryProps, CourierInboxTheme, CourierInbox as CourierInboxElement, CourierInboxHeaderFactoryProps, CourierInboxStateEmptyFactoryProps, CourierInboxStateLoadingFactoryProps, CourierInboxStateErrorFactoryProps, CourierInboxPaginationItemFactoryProps, CourierInboxFeedType } from '@trycourier/courier-ui-inbox';
2
+ import { CourierInboxListItemActionFactoryProps, CourierInboxListItemFactoryProps, CourierInboxTheme, CourierInbox as CourierInboxElement, CourierInboxHeaderFactoryProps, CourierInboxStateEmptyFactoryProps, CourierInboxStateLoadingFactoryProps, CourierInboxStateErrorFactoryProps, CourierInboxPaginationItemFactoryProps, CourierInboxFeed } from '@trycourier/courier-ui-inbox';
3
3
  import { CourierComponentThemeMode } from '@trycourier/courier-ui-core';
4
4
  export interface CourierInboxProps {
5
5
  /** Height of the inbox container. Defaults to "auto" and will resize itself based on it's children. */
@@ -10,8 +10,10 @@ export interface CourierInboxProps {
10
10
  darkTheme?: CourierInboxTheme;
11
11
  /** Theme mode: "light", "dark", or "system". Defaults to "system" */
12
12
  mode?: CourierComponentThemeMode;
13
- /** Type of feed to display in the inbox ("inbox" or "archive"). Defaults to "inbox" */
14
- feedType?: CourierInboxFeedType;
13
+ /** Type of feed to display in the inbox. Defaults to "inbox" */
14
+ feedType?: string;
15
+ /** Array of feeds to display in the inbox. Each feed contains tabs with different filters. */
16
+ feeds?: CourierInboxFeed[];
15
17
  /** Callback fired when a message is clicked. */
16
18
  onMessageClick?: (props: CourierInboxListItemFactoryProps) => void;
17
19
  /** Callback fired when a message action (e.g., button) is clicked. */
@@ -1,5 +1,5 @@
1
1
  import { ReactNode } from 'react';
2
- import { CourierInboxFeedType, CourierInboxHeaderFactoryProps, CourierInboxListItemActionFactoryProps, CourierInboxListItemFactoryProps, CourierInboxMenuButtonFactoryProps, CourierInboxPopupMenu as CourierInboxPopupMenuElement, CourierInboxPaginationItemFactoryProps, CourierInboxPopupAlignment, CourierInboxStateEmptyFactoryProps, CourierInboxStateErrorFactoryProps, CourierInboxStateLoadingFactoryProps, CourierInboxTheme } from '@trycourier/courier-ui-inbox';
2
+ import { CourierInboxHeaderFactoryProps, CourierInboxListItemActionFactoryProps, CourierInboxListItemFactoryProps, CourierInboxMenuButtonFactoryProps, CourierInboxPopupMenu as CourierInboxPopupMenuElement, CourierInboxPaginationItemFactoryProps, CourierInboxPopupAlignment, CourierInboxStateEmptyFactoryProps, CourierInboxStateErrorFactoryProps, CourierInboxStateLoadingFactoryProps, CourierInboxTheme, CourierInboxFeed } from '@trycourier/courier-ui-inbox';
3
3
  import { CourierComponentThemeMode } from '@trycourier/courier-ui-core';
4
4
  export interface CourierInboxPopupMenuProps {
5
5
  /** Alignment of the popup menu: 'top-right', 'top-left', 'top-center', 'bottom-right', 'bottom-left', 'bottom-center', 'center-right', 'center-left', 'center-center'. */
@@ -22,8 +22,8 @@ export interface CourierInboxPopupMenuProps {
22
22
  darkTheme?: CourierInboxTheme;
23
23
  /** Theme mode: 'light', 'dark', or 'system'. */
24
24
  mode?: CourierComponentThemeMode;
25
- /** Type of feed to display in the popup menu ('inbox' or 'archive'). */
26
- feedType?: CourierInboxFeedType;
25
+ /** Array of feeds to display in the inbox. Each feed contains tabs with different filters. */
26
+ feeds?: CourierInboxFeed[];
27
27
  /** Callback fired when a message is clicked. */
28
28
  onMessageClick?: (props: CourierInboxListItemFactoryProps) => void;
29
29
  /** Callback fired when a message action (e.g., button) is clicked. */
@@ -1,5 +1,5 @@
1
1
  import { ReactNode, CSSProperties } from 'react';
2
- import { CourierToastTheme, CourierToastItemFactoryProps, CourierToastDismissButtonOption, CourierToastItemClickEvent, CourierToastItemActionClickEvent } from '@trycourier/courier-ui-toast';
2
+ import { CourierToastTheme, CourierToast as CourierToastElement, CourierToastItemFactoryProps, CourierToastDismissButtonOption, CourierToastItemClickEvent, CourierToastItemActionClickEvent } from '@trycourier/courier-ui-toast';
3
3
  import { CourierComponentThemeMode } from '@trycourier/courier-ui-core';
4
4
  /** Props that may be passed to the CourierToast component. */
5
5
  export interface CourierToastProps {
@@ -1,5 +1,5 @@
1
1
  import { Courier, CourierProps, InboxMessage } from '@trycourier/courier-js';
2
- import { CourierInboxFeedType, InboxDataSet } from '@trycourier/courier-ui-inbox';
2
+ import { InboxDataSet, CourierInboxFeed } from '@trycourier/courier-ui-inbox';
3
3
  type AuthenticationHooks = {
4
4
  userId?: string;
5
5
  signIn: (props: CourierProps) => void;
@@ -10,7 +10,7 @@ type InboxHooks = {
10
10
  canUseCache: boolean;
11
11
  }) => Promise<void>;
12
12
  fetchNextPageOfMessages: (props: {
13
- feedType: CourierInboxFeedType;
13
+ datasetId: string;
14
14
  }) => Promise<InboxDataSet | null>;
15
15
  setPaginationLimit: (limit: number) => void;
16
16
  readMessage: (message: InboxMessage) => Promise<void>;
@@ -20,9 +20,10 @@ type InboxHooks = {
20
20
  openMessage: (message: InboxMessage) => Promise<void>;
21
21
  unarchiveMessage: (message: InboxMessage) => Promise<void>;
22
22
  readAllMessages: () => Promise<void>;
23
- inbox?: InboxDataSet;
24
- archive?: InboxDataSet;
25
- unreadCount?: number;
23
+ registerFeeds: (feeds: CourierInboxFeed[]) => void;
24
+ listenForUpdates: () => Promise<void>;
25
+ feeds: Record<string, InboxDataSet>;
26
+ totalUnreadCount?: number;
26
27
  error?: Error;
27
28
  };
28
29
  type ToastHooks = {
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@trycourier/courier-js"),t=require("@trycourier/courier-ui-inbox"),r=require("@trycourier/courier-ui-toast"),s=require("react"),n=require("react/jsx-runtime"),o=({children:e})=>{const[t,r]=s.useState(!1);return s.useEffect((()=>{r(!0)}),[]),"undefined"==typeof window?null:t?n.jsx(n.Fragment,{children:e}):null},a=s.createContext(null),i=s.forwardRef(((e,t)=>{const r=s.useContext(a);if(!r)throw new Error("RenderContext not found. Ensure CourierInbox is wrapped in a CourierRenderContext.");const i=s.useRef(null),[u,c]=s.useState(!1);function d(){return i.current}s.useEffect((()=>{const t=d();t&&t.onMessageClick(e.onMessageClick)}),[e.onMessageClick,u]),s.useEffect((()=>{const t=d();t&&t.onMessageActionClick(e.onMessageActionClick)}),[e.onMessageActionClick,u]),s.useEffect((()=>{const t=d();t&&t.onMessageLongPress(e.onMessageLongPress)}),[e.onMessageLongPress,u]),s.useEffect((()=>{const t=d();t&&e.renderHeader&&queueMicrotask((()=>{t.setHeader((t=>{const s=e.renderHeader(t);return r(s)}))}))}),[e.renderHeader,u]),s.useEffect((()=>{const t=d();t&&e.renderListItem&&queueMicrotask((()=>{t.setListItem((t=>{const s=e.renderListItem(t);return r(s)}))}))}),[e.renderListItem,u]),s.useEffect((()=>{const t=d();t&&e.renderEmptyState&&queueMicrotask((()=>{t.setEmptyState((t=>{const s=e.renderEmptyState(t);return r(s)}))}))}),[e.renderEmptyState,u]),s.useEffect((()=>{const t=d();t&&e.renderLoadingState&&queueMicrotask((()=>{t.setLoadingState((t=>{const s=e.renderLoadingState(t);return r(s)}))}))}),[e.renderLoadingState,u]),s.useEffect((()=>{const t=d();t&&e.renderErrorState&&queueMicrotask((()=>{t.setErrorState((t=>{const s=e.renderErrorState(t);return r(s)}))}))}),[e.renderErrorState,u]),s.useEffect((()=>{const t=d();t&&e.renderPaginationItem&&queueMicrotask((()=>{t.setPaginationItem((t=>{const s=e.renderPaginationItem(t);return r(s)}))}))}),[e.renderPaginationItem,u]),s.useEffect((()=>{const t=d();t&&queueMicrotask((()=>{t.setFeedType(e.feedType||"inbox")}))}),[e.feedType,u]);const g=n.jsx("courier-inbox",{ref:function(e){t&&("function"==typeof t?t(e):t.current=e),i.current=e,c(!!e)},height:e.height,"light-theme":e.lightTheme?JSON.stringify(e.lightTheme):void 0,"dark-theme":e.darkTheme?JSON.stringify(e.darkTheme):void 0,mode:e.mode});return n.jsx(o,{children:g})})),u=s.forwardRef(((e,t)=>{const r=s.useContext(a);if(!r)throw new Error("RenderContext not found. Ensure CourierInboxPopupMenu is wrapped in a CourierRenderContext.");const i=s.useRef(null),[u,c]=s.useState(!1);function d(){return i.current}const g=s.useRef(void 0);s.useEffect((()=>{const t=d();t&&e.feedType!==g.current&&(g.current=e.feedType,queueMicrotask((()=>{var r;null==(r=t.setFeedType)||r.call(t,e.feedType??"inbox")})))}),[e.feedType,u]),s.useEffect((()=>{const t=d();t&&t.onMessageClick(e.onMessageClick)}),[e.onMessageClick,u]),s.useEffect((()=>{const t=d();t&&t.onMessageActionClick(e.onMessageActionClick)}),[e.onMessageActionClick,u]),s.useEffect((()=>{const t=d();t&&t.onMessageLongPress(e.onMessageLongPress)}),[e.onMessageLongPress,u]),s.useEffect((()=>{const t=d();t&&e.renderHeader&&queueMicrotask((()=>{t.setHeader((t=>{const s=e.renderHeader(t);return r(s)}))}))}),[e.renderHeader,u]),s.useEffect((()=>{const t=d();t&&e.renderListItem&&queueMicrotask((()=>{t.setListItem((t=>{const s=e.renderListItem(t);return r(s)}))}))}),[e.renderListItem,u]),s.useEffect((()=>{const t=d();t&&e.renderEmptyState&&queueMicrotask((()=>{t.setEmptyState((t=>{const s=e.renderEmptyState(t);return r(s)}))}))}),[e.renderEmptyState,u]),s.useEffect((()=>{const t=d();t&&e.renderLoadingState&&queueMicrotask((()=>{t.setLoadingState((t=>{const s=e.renderLoadingState(t);return r(s)}))}))}),[e.renderLoadingState,u]),s.useEffect((()=>{const t=d();t&&e.renderErrorState&&queueMicrotask((()=>{t.setErrorState((t=>{const s=e.renderErrorState(t);return r(s)}))}))}),[e.renderErrorState,u]),s.useEffect((()=>{const t=d();t&&e.renderPaginationItem&&queueMicrotask((()=>{t.setPaginationItem((t=>{const s=e.renderPaginationItem(t);return r(s)}))}))}),[e.renderPaginationItem,u]),s.useEffect((()=>{const t=d();t&&e.renderMenuButton&&queueMicrotask((()=>{t.setMenuButton((t=>{const s=e.renderMenuButton(t);return r(s)}))}))}),[e.renderMenuButton,u]);const f=n.jsx("courier-inbox-popup-menu",{ref:function(e){t&&("function"==typeof t?t(e):t.current=e),i.current=e,c(!!e)},"popup-alignment":e.popupAlignment,"popup-width":e.popupWidth,"popup-height":e.popupHeight,left:e.left,top:e.top,right:e.right,bottom:e.bottom,"light-theme":e.lightTheme?JSON.stringify(e.lightTheme):void 0,"dark-theme":e.darkTheme?JSON.stringify(e.darkTheme):void 0,mode:e.mode});return n.jsx(o,{children:f})})),c=s.forwardRef(((e,t)=>{const r=s.useContext(a);if(!r)throw new Error("RenderContext not found. Ensure CourierToast is wrapped in a CourierRenderContext.");const[i,u]=s.useState({elementMounted:!1,onItemClickSet:!1,onItemActionClickSet:!1,renderToastItemSet:!1,renderToastItemContentSet:!1}),[c,d]=s.useState(!1),g=s.useRef(null);function f(){return g.current}s.useEffect((()=>{Object.values(i).every((e=>e))&&e.onReady&&e.onReady(!0)}),[i,e.onReady]),s.useEffect((()=>{c&&u((e=>({...e,elementMounted:!0})))}),[c]),s.useEffect((()=>{const t=f();t&&(t.onToastItemClick(e.onToastItemClick),u((e=>({...e,onItemClickSet:!0}))))}),[e.onToastItemClick,c]),s.useEffect((()=>{const t=f();t&&(t.onToastItemActionClick(e.onToastItemActionClick),u((e=>({...e,onItemActionClickSet:!0}))))}),[e.onToastItemActionClick,c]),s.useEffect((()=>{const t=f();t&&e.renderToastItem?(queueMicrotask((()=>{t.setToastItem((t=>{const s=e.renderToastItem(t);return r(s)}))})),u((e=>({...e,renderToastItemSet:!0})))):u((e=>({...e,renderToastItemSet:!0})))}),[e.renderToastItem,c]),s.useEffect((()=>{const t=f();t&&e.renderToastItemContent?queueMicrotask((()=>{t.setToastItemContent((t=>{const s=e.renderToastItemContent(t);return r(s)})),u((e=>({...e,renderToastItemContentSet:!0})))})):u((e=>({...e,renderToastItemContentSet:!0})))}),[e.renderToastItemContent,c]);const m=n.jsx("courier-toast",{ref:function(e){t&&("function"==typeof t?t(e):t.current=e),g.current=e,d(!!e)},style:e.style,"light-theme":e.lightTheme?JSON.stringify(e.lightTheme):void 0,"dark-theme":e.darkTheme?JSON.stringify(e.darkTheme):void 0,mode:e.mode,"auto-dismiss":e.autoDismiss,"auto-dismiss-timeout-ms":e.autoDismissTimeoutMs,"dismiss-button":e.dismissButton});return n.jsx(o,{children:m})}));exports.CourierInboxComponent=i,exports.CourierInboxPopupMenuComponent=u,exports.CourierRenderContext=a,exports.CourierToastComponent=c,exports.useCourier=()=>{const n=t=>e.Courier.shared.signIn(t),o=()=>e.Courier.shared.signOut(),a=e=>t.CourierInboxDatastore.shared.load(e),i=e=>t.CourierInboxDatastore.shared.fetchNextPageOfMessages(e),u=t=>e.Courier.shared.paginationLimit=t,c=e=>t.CourierInboxDatastore.shared.readMessage({message:e}),d=e=>t.CourierInboxDatastore.shared.unreadMessage({message:e}),g=e=>t.CourierInboxDatastore.shared.clickMessage({message:e}),f=e=>t.CourierInboxDatastore.shared.archiveMessage({message:e}),m=e=>t.CourierInboxDatastore.shared.openMessage({message:e}),h=e=>t.CourierInboxDatastore.shared.unarchiveMessage({message:e}),l=()=>t.CourierInboxDatastore.shared.readAllMessages(),[C,M]=s.useState({userId:void 0,signIn:n,signOut:o}),[p,I]=s.useState({load:a,fetchNextPageOfMessages:i,setPaginationLimit:u,readMessage:c,unreadMessage:d,clickMessage:g,archiveMessage:f,openMessage:m,unarchiveMessage:h,readAllMessages:l}),S=e=>r.CourierToastDatastore.shared.addMessage(e),E=e=>r.CourierToastDatastore.shared.removeMessage(e),[x,k]=s.useState({addMessage:S,removeMessage:E});s.useEffect((()=>{const s=e.Courier.shared.addAuthenticationListener((()=>T())),n=new t.CourierInboxDataStoreListener({onError:e=>y(e),onDataSetChange:()=>y(),onPageAdded:()=>y(),onMessageAdd:()=>y(),onMessageRemove:()=>y(),onMessageUpdate:()=>y(),onUnreadCountChange:()=>y()});t.CourierInboxDatastore.shared.addDataStoreListener(n);const o=new r.CourierToastDatastoreListener({onMessageAdd:()=>v(),onMessageRemove:()=>v(),onError:e=>v(e)});return r.CourierToastDatastore.shared.addDatastoreListener(o),T(),y(),v(),()=>{s.remove(),n.remove(),o.remove()}}),[]);const T=()=>{var t;const r=null==(t=e.Courier.shared.client)?void 0:t.options;M({userId:null==r?void 0:r.userId,signIn:n,signOut:o})},y=e=>{const r=t.CourierInboxDatastore.shared;I({load:a,fetchNextPageOfMessages:i,setPaginationLimit:u,readMessage:c,unreadMessage:d,clickMessage:g,archiveMessage:f,openMessage:m,unarchiveMessage:h,readAllMessages:l,inbox:r.inboxDataSet,archive:r.archiveDataSet,unreadCount:r.unreadCount,error:e})},v=e=>{k({addMessage:S,removeMessage:E,error:e})};return{shared:e.Courier.shared,auth:C,inbox:p,toast:x}};
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@trycourier/courier-js"),t=require("@trycourier/courier-ui-inbox"),r=require("@trycourier/courier-ui-toast"),s=require("react"),n=require("react/jsx-runtime"),o=({children:e})=>{const[t,r]=s.useState(!1);return s.useEffect((()=>{r(!0)}),[]),"undefined"==typeof window?null:t?n.jsx(n.Fragment,{children:e}):null},a=s.createContext(null),i=s.forwardRef(((e,t)=>{const r=s.useContext(a);if(!r)throw new Error("RenderContext not found. Ensure CourierInbox is wrapped in a CourierRenderContext.");const i=s.useRef(null),[u,d]=s.useState(!1),c=s.useRef(!1);function g(){return i.current}s.useEffect((()=>{const t=g();t&&t.onMessageClick(e.onMessageClick)}),[e.onMessageClick,u]),s.useEffect((()=>{const t=g();t&&t.onMessageActionClick(e.onMessageActionClick)}),[e.onMessageActionClick,u]),s.useEffect((()=>{const t=g();t&&t.onMessageLongPress(e.onMessageLongPress)}),[e.onMessageLongPress,u]),s.useEffect((()=>{const t=g();t&&e.renderHeader&&queueMicrotask((()=>{t.setHeader((t=>{const s=e.renderHeader(t);return r(s)}))}))}),[e.renderHeader,u]),s.useEffect((()=>{const t=g();t&&e.renderListItem&&queueMicrotask((()=>{t.setListItem((t=>{const s=e.renderListItem(t);return r(s)}))}))}),[e.renderListItem,u]),s.useEffect((()=>{const t=g();t&&e.renderEmptyState&&queueMicrotask((()=>{t.setEmptyState((t=>{const s=e.renderEmptyState(t);return r(s)}))}))}),[e.renderEmptyState,u]),s.useEffect((()=>{const t=g();t&&e.renderLoadingState&&queueMicrotask((()=>{t.setLoadingState((t=>{const s=e.renderLoadingState(t);return r(s)}))}))}),[e.renderLoadingState,u]),s.useEffect((()=>{const t=g();t&&e.renderErrorState&&queueMicrotask((()=>{t.setErrorState((t=>{const s=e.renderErrorState(t);return r(s)}))}))}),[e.renderErrorState,u]),s.useEffect((()=>{const t=g();t&&e.renderPaginationItem&&queueMicrotask((()=>{t.setPaginationItem((t=>{const s=e.renderPaginationItem(t);return r(s)}))}))}),[e.renderPaginationItem,u]),s.useEffect((()=>{const t=g();t&&e.feeds&&!c.current&&(c.current=!0,queueMicrotask((()=>{t.setFeeds(e.feeds)})))}),[e.feeds,u]);const f=n.jsx("courier-inbox",{ref:function(e){t&&("function"==typeof t?t(e):t.current=e),i.current=e,d(!!e)},height:e.height,"light-theme":e.lightTheme?JSON.stringify(e.lightTheme):void 0,"dark-theme":e.darkTheme?JSON.stringify(e.darkTheme):void 0,mode:e.mode});return n.jsx(o,{children:f})})),u=s.forwardRef(((e,t)=>{const r=s.useContext(a);if(!r)throw new Error("RenderContext not found. Ensure CourierInboxPopupMenu is wrapped in a CourierRenderContext.");const i=s.useRef(null),[u,d]=s.useState(!1),c=s.useRef(!1);function g(){return i.current}s.useEffect((()=>{const t=g();t&&t.onMessageClick(e.onMessageClick)}),[e.onMessageClick,u]),s.useEffect((()=>{const t=g();t&&t.onMessageActionClick(e.onMessageActionClick)}),[e.onMessageActionClick,u]),s.useEffect((()=>{const t=g();t&&t.onMessageLongPress(e.onMessageLongPress)}),[e.onMessageLongPress,u]),s.useEffect((()=>{const t=g();t&&e.renderHeader&&queueMicrotask((()=>{t.setHeader((t=>{const s=e.renderHeader(t);return r(s)}))}))}),[e.renderHeader,u]),s.useEffect((()=>{const t=g();t&&e.renderListItem&&queueMicrotask((()=>{t.setListItem((t=>{const s=e.renderListItem(t);return r(s)}))}))}),[e.renderListItem,u]),s.useEffect((()=>{const t=g();t&&e.renderEmptyState&&queueMicrotask((()=>{t.setEmptyState((t=>{const s=e.renderEmptyState(t);return r(s)}))}))}),[e.renderEmptyState,u]),s.useEffect((()=>{const t=g();t&&e.renderLoadingState&&queueMicrotask((()=>{t.setLoadingState((t=>{const s=e.renderLoadingState(t);return r(s)}))}))}),[e.renderLoadingState,u]),s.useEffect((()=>{const t=g();t&&e.renderErrorState&&queueMicrotask((()=>{t.setErrorState((t=>{const s=e.renderErrorState(t);return r(s)}))}))}),[e.renderErrorState,u]),s.useEffect((()=>{const t=g();t&&e.renderPaginationItem&&queueMicrotask((()=>{t.setPaginationItem((t=>{const s=e.renderPaginationItem(t);return r(s)}))}))}),[e.renderPaginationItem,u]),s.useEffect((()=>{const t=g();t&&e.renderMenuButton&&queueMicrotask((()=>{t.setMenuButton((t=>{const s=e.renderMenuButton(t);return r(s)}))}))}),[e.renderMenuButton,u]),s.useEffect((()=>{const t=g();t&&e.feeds&&!c.current&&(c.current=!0,queueMicrotask((()=>{t.setFeeds(e.feeds)})))}),[e.feeds,u]);const f=n.jsx("courier-inbox-popup-menu",{ref:function(e){t&&("function"==typeof t?t(e):t.current=e),i.current=e,d(!!e)},"popup-alignment":e.popupAlignment,"popup-width":e.popupWidth,"popup-height":e.popupHeight,left:e.left,top:e.top,right:e.right,bottom:e.bottom,"light-theme":e.lightTheme?JSON.stringify(e.lightTheme):void 0,"dark-theme":e.darkTheme?JSON.stringify(e.darkTheme):void 0,mode:e.mode});return n.jsx(o,{children:f})})),d=s.forwardRef(((e,t)=>{const r=s.useContext(a);if(!r)throw new Error("RenderContext not found. Ensure CourierToast is wrapped in a CourierRenderContext.");const[i,u]=s.useState({elementMounted:!1,onItemClickSet:!1,onItemActionClickSet:!1,renderToastItemSet:!1,renderToastItemContentSet:!1}),[d,c]=s.useState(!1),g=s.useRef(null);function f(){return g.current}s.useEffect((()=>{Object.values(i).every((e=>e))&&e.onReady&&e.onReady(!0)}),[i,e.onReady]),s.useEffect((()=>{d&&u((e=>({...e,elementMounted:!0})))}),[d]),s.useEffect((()=>{const t=f();t&&(t.onToastItemClick(e.onToastItemClick),u((e=>({...e,onItemClickSet:!0}))))}),[e.onToastItemClick,d]),s.useEffect((()=>{const t=f();t&&(t.onToastItemActionClick(e.onToastItemActionClick),u((e=>({...e,onItemActionClickSet:!0}))))}),[e.onToastItemActionClick,d]),s.useEffect((()=>{const t=f();t&&e.renderToastItem?(queueMicrotask((()=>{t.setToastItem((t=>{const s=e.renderToastItem(t);return r(s)}))})),u((e=>({...e,renderToastItemSet:!0})))):u((e=>({...e,renderToastItemSet:!0})))}),[e.renderToastItem,d]),s.useEffect((()=>{const t=f();t&&e.renderToastItemContent?queueMicrotask((()=>{t.setToastItemContent((t=>{const s=e.renderToastItemContent(t);return r(s)})),u((e=>({...e,renderToastItemContentSet:!0})))})):u((e=>({...e,renderToastItemContentSet:!0})))}),[e.renderToastItemContent,d]);const m=n.jsx("courier-toast",{ref:function(e){t&&("function"==typeof t?t(e):t.current=e),g.current=e,c(!!e)},style:e.style,"light-theme":e.lightTheme?JSON.stringify(e.lightTheme):void 0,"dark-theme":e.darkTheme?JSON.stringify(e.darkTheme):void 0,mode:e.mode,"auto-dismiss":e.autoDismiss,"auto-dismiss-timeout-ms":e.autoDismissTimeoutMs,"dismiss-button":e.dismissButton});return n.jsx(o,{children:m})}));exports.CourierInboxComponent=i,exports.CourierInboxPopupMenuComponent=u,exports.CourierRenderContext=a,exports.CourierToastComponent=d,exports.useCourier=()=>{const n=t=>e.Courier.shared.signIn(t),o=()=>e.Courier.shared.signOut(),a=e=>t.CourierInboxDatastore.shared.load(e),i=e=>t.CourierInboxDatastore.shared.fetchNextPageOfMessages(e),u=t=>e.Courier.shared.paginationLimit=t,d=e=>t.CourierInboxDatastore.shared.readMessage({message:e}),c=e=>t.CourierInboxDatastore.shared.unreadMessage({message:e}),g=e=>t.CourierInboxDatastore.shared.clickMessage({message:e}),f=e=>t.CourierInboxDatastore.shared.archiveMessage({message:e}),m=e=>t.CourierInboxDatastore.shared.openMessage({message:e}),C=e=>t.CourierInboxDatastore.shared.unarchiveMessage({message:e}),h=()=>t.CourierInboxDatastore.shared.readAllMessages(),l=e=>t.CourierInboxDatastore.shared.registerFeeds(e),M=()=>t.CourierInboxDatastore.shared.listenForUpdates(),[p,I]=s.useState({userId:void 0,signIn:n,signOut:o}),[E,S]=s.useState({load:a,fetchNextPageOfMessages:i,setPaginationLimit:u,readMessage:d,unreadMessage:c,clickMessage:g,archiveMessage:f,openMessage:m,unarchiveMessage:C,readAllMessages:h,registerFeeds:l,listenForUpdates:M,feeds:{}}),k=e=>r.CourierToastDatastore.shared.addMessage(e),x=e=>r.CourierToastDatastore.shared.removeMessage(e),[T,L]=s.useState({addMessage:k,removeMessage:x});s.useEffect((()=>{const s=e.Courier.shared.addAuthenticationListener((()=>y())),n=new t.CourierInboxDataStoreListener({onError:e=>b(e),onDataSetChange:()=>b(),onPageAdded:()=>b(),onMessageAdd:()=>b(),onMessageRemove:()=>b(),onMessageUpdate:()=>b(),onUnreadCountChange:()=>b(),onTotalUnreadCountChange:()=>b()});t.CourierInboxDatastore.shared.addDataStoreListener(n);const o=new r.CourierToastDatastoreListener({onMessageAdd:()=>v(),onMessageRemove:()=>v(),onError:e=>v(e)});return r.CourierToastDatastore.shared.addDatastoreListener(o),y(),b(),v(),()=>{s.remove(),n.remove(),o.remove()}}),[]);const y=()=>{var t;const r=null==(t=e.Courier.shared.client)?void 0:t.options;I({userId:null==r?void 0:r.userId,signIn:n,signOut:o})},b=e=>{const r=t.CourierInboxDatastore.shared,s=r.getDatasets();S({load:a,fetchNextPageOfMessages:i,setPaginationLimit:u,readMessage:d,unreadMessage:c,clickMessage:g,archiveMessage:f,openMessage:m,unarchiveMessage:C,readAllMessages:h,registerFeeds:l,listenForUpdates:M,feeds:s,totalUnreadCount:r.totalUnreadCount,error:e})},v=e=>{L({addMessage:k,removeMessage:x,error:e})};return{shared:e.Courier.shared,auth:p,inbox:E,toast:T}};
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/components/courier-client-component.tsx","../src/context/render-context.ts","../src/components/courier-inbox-component.tsx","../src/components/courier-inbox-popup-menu-component.tsx","../src/components/courier-toast-component.tsx","../src/hooks/use-courier.tsx"],"sourcesContent":["import React, { useState, useEffect } from 'react';\n\ninterface CourierClientProps {\n children: React.ReactNode;\n}\n\n// This class prevents issues with server side rendering react components\n// It will force the component to only render client side\n// A future update could support server side rendering if there is enough demand\nexport const CourierClientComponent: React.FC<CourierClientProps> = ({ children }) => {\n const [isMounted, setIsMounted] = useState(false);\n\n useEffect(() => {\n setIsMounted(true);\n }, []);\n\n // During SSR, render nothing or fallback\n if (typeof window === 'undefined') {\n return null;\n }\n\n if (!isMounted) {\n return null;\n }\n\n return <>{children}</>;\n};","import { createContext, ReactNode } from \"react\";\n\ntype RenderFn = (node: ReactNode) => HTMLElement;\n\n/**\n * Context providing a function to render a React component.\n *\n * Courier's React package renders as follows:\n *\n * - React engine (client application)\n * - Courier React components\n * - Courier web components\n * - [Optional] User-provided React components (ex. a list item)\n *\n * By default, React will not render the user-provided React components within Courier's\n * web components. We instead manually render the user-provided React components and inject\n * them into the Courier web components.\n *\n * Client rendering changed between React 17 and 18, so the SDKs provide React version-specific\n * rendering functions. See\n * https://18.react.dev/blog/2022/03/08/react-18-upgrade-guide#updates-to-client-rendering-apis.\n */\nexport const CourierRenderContext = createContext<RenderFn | null>(null);\n","import { useRef, useEffect, forwardRef, ReactNode, useContext, useState } from \"react\";\nimport { CourierInboxListItemActionFactoryProps, CourierInboxListItemFactoryProps, CourierInboxTheme, CourierInbox as CourierInboxElement, CourierInboxHeaderFactoryProps, CourierInboxStateEmptyFactoryProps, CourierInboxStateLoadingFactoryProps, CourierInboxStateErrorFactoryProps, CourierInboxPaginationItemFactoryProps, CourierInboxFeedType } from \"@trycourier/courier-ui-inbox\";\nimport { CourierComponentThemeMode } from \"@trycourier/courier-ui-core\";\nimport { CourierClientComponent } from \"./courier-client-component\";\nimport { CourierRenderContext } from \"../context/render-context\";\n\nexport interface CourierInboxProps {\n /** Height of the inbox container. Defaults to \"auto\" and will resize itself based on it's children. */\n height?: string;\n\n /** Theme object for light mode */\n lightTheme?: CourierInboxTheme;\n\n /** Theme object for dark mode */\n darkTheme?: CourierInboxTheme;\n\n /** Theme mode: \"light\", \"dark\", or \"system\". Defaults to \"system\" */\n mode?: CourierComponentThemeMode;\n\n /** Type of feed to display in the inbox (\"inbox\" or \"archive\"). Defaults to \"inbox\" */\n feedType?: CourierInboxFeedType;\n\n /** Callback fired when a message is clicked. */\n onMessageClick?: (props: CourierInboxListItemFactoryProps) => void;\n\n /** Callback fired when a message action (e.g., button) is clicked. */\n onMessageActionClick?: (props: CourierInboxListItemActionFactoryProps) => void;\n\n /** Callback fired when a message is long-pressed (for mobile/gesture support). Only works on devices that support touch. */\n onMessageLongPress?: (props: CourierInboxListItemFactoryProps) => void;\n\n /** Allows you to pass a custom component as the header. */\n renderHeader?: (props: CourierInboxHeaderFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the list item. */\n renderListItem?: (props: CourierInboxListItemFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the empty state. */\n renderEmptyState?: (props: CourierInboxStateEmptyFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the loading state. */\n renderLoadingState?: (props: CourierInboxStateLoadingFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the error state. */\n renderErrorState?: (props: CourierInboxStateErrorFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the pagination list item. */\n renderPaginationItem?: (props: CourierInboxPaginationItemFactoryProps | undefined | null) => ReactNode;\n}\n\nexport const CourierInboxComponent = forwardRef<CourierInboxElement, CourierInboxProps>((props, ref) => {\n const render = useContext(CourierRenderContext);\n if (!render) {\n throw new Error(\"RenderContext not found. Ensure CourierInbox is wrapped in a CourierRenderContext.\");\n }\n\n // Element ref for use in effects, updated by handleRef.\n const inboxRef = useRef<CourierInboxElement | null>(null);\n const [elementReady, setElementReady] = useState(false);\n\n // Callback ref passed to rendered component, used to propagate the DOM element's ref to the parent component.\n // We use a callback ref (rather than a React.RefObject) since we want the parent ref to be up-to-date with\n // rendered component. Updating the parent ref via useEffect does not work, since mutating a RefObject\n // does not trigger useEffect (see https://stackoverflow.com/a/60476525).\n function handleRef(el: CourierInboxElement | null) {\n if (ref) {\n\n // Propagate ref to ref callback functions\n if (typeof ref === 'function') {\n ref(el);\n } else {\n // Propagate ref to ref objects\n // @ts-ignore - RefObject.current is readonly in React 17, however it's not frozen and is equivalent the widened type MutableRefObject\n (ref as React.RefObject<CourierInboxElement | null>).current = el;\n }\n }\n\n // Store the element for use in effects\n inboxRef.current = el;\n\n // Update element ready state\n setElementReady(!!el);\n }\n\n // Helper to get the current element\n function getEl(): CourierInboxElement | null {\n return inboxRef.current;\n }\n\n // Handle message click\n useEffect(() => {\n const inbox = getEl();\n if (!inbox) return;\n inbox.onMessageClick(props.onMessageClick);\n }, [props.onMessageClick, elementReady]);\n\n // Handle message action click\n useEffect(() => {\n const inbox = getEl();\n if (!inbox) return;\n inbox.onMessageActionClick(props.onMessageActionClick);\n }, [props.onMessageActionClick, elementReady]);\n\n // Handle message long press\n useEffect(() => {\n const inbox = getEl();\n if (!inbox) return;\n inbox.onMessageLongPress(props.onMessageLongPress);\n }, [props.onMessageLongPress, elementReady]);\n\n // Render header\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderHeader) return;\n queueMicrotask(() => {\n inbox.setHeader((headerProps?: CourierInboxHeaderFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderHeader!(headerProps);\n return render(reactNode);\n });\n });\n }, [props.renderHeader, elementReady]);\n\n // Render list item\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderListItem) return;\n queueMicrotask(() => {\n inbox.setListItem((itemProps?: CourierInboxListItemFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderListItem!(itemProps);\n return render(reactNode);\n });\n });\n }, [props.renderListItem, elementReady]);\n\n // Render empty state\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderEmptyState) return;\n queueMicrotask(() => {\n inbox.setEmptyState((emptyStateProps?: CourierInboxStateEmptyFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderEmptyState!(emptyStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderEmptyState, elementReady]);\n\n // Render loading state\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderLoadingState) return;\n queueMicrotask(() => {\n inbox.setLoadingState((loadingStateProps?: CourierInboxStateLoadingFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderLoadingState!(loadingStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderLoadingState, elementReady]);\n\n // Render error state\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderErrorState) return;\n queueMicrotask(() => {\n inbox.setErrorState((errorStateProps?: CourierInboxStateErrorFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderErrorState!(errorStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderErrorState, elementReady]);\n\n // Render pagination item\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderPaginationItem) return;\n queueMicrotask(() => {\n inbox.setPaginationItem((paginationProps?: CourierInboxPaginationItemFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderPaginationItem!(paginationProps);\n return render(reactNode);\n });\n });\n }, [props.renderPaginationItem, elementReady]);\n\n // Set feed type\n useEffect(() => {\n const inbox = getEl();\n if (!inbox) return;\n queueMicrotask(() => {\n inbox.setFeedType(props.feedType || 'inbox');\n });\n }, [props.feedType, elementReady]);\n\n const children = (\n /* @ts-ignore */\n <courier-inbox\n ref={handleRef}\n height={props.height}\n light-theme={props.lightTheme ? JSON.stringify(props.lightTheme) : undefined}\n dark-theme={props.darkTheme ? JSON.stringify(props.darkTheme) : undefined}\n mode={props.mode}\n />\n );\n\n return (\n <CourierClientComponent children={children} />\n );\n});\n","import { useEffect, useRef, forwardRef, ReactNode, useContext, useState } from 'react';\nimport {\n CourierInboxFeedType,\n CourierInboxHeaderFactoryProps,\n CourierInboxListItemActionFactoryProps,\n CourierInboxListItemFactoryProps,\n CourierInboxMenuButtonFactoryProps,\n CourierInboxPopupMenu as CourierInboxPopupMenuElement,\n CourierInboxPaginationItemFactoryProps,\n CourierInboxPopupAlignment,\n CourierInboxStateEmptyFactoryProps,\n CourierInboxStateErrorFactoryProps,\n CourierInboxStateLoadingFactoryProps,\n CourierInboxTheme,\n} from '@trycourier/courier-ui-inbox';\nimport { CourierComponentThemeMode } from '@trycourier/courier-ui-core';\nimport { CourierClientComponent } from './courier-client-component';\nimport { CourierRenderContext } from '../context/render-context';\n\nexport interface CourierInboxPopupMenuProps {\n /** Alignment of the popup menu: 'top-right', 'top-left', 'top-center', 'bottom-right', 'bottom-left', 'bottom-center', 'center-right', 'center-left', 'center-center'. */\n popupAlignment?: CourierInboxPopupAlignment;\n\n /** Width of the popup menu container. */\n popupWidth?: string;\n\n /** Height of the popup menu container. */\n popupHeight?: string;\n\n /** CSS left position for the popup menu. */\n left?: string;\n\n /** CSS top position for the popup menu. */\n top?: string;\n\n /** CSS right position for the popup menu. */\n right?: string;\n\n /** CSS bottom position for the popup menu. */\n bottom?: string;\n\n /** Theme object for light mode. */\n lightTheme?: CourierInboxTheme;\n\n /** Theme object for dark mode. */\n darkTheme?: CourierInboxTheme;\n\n /** Theme mode: 'light', 'dark', or 'system'. */\n mode?: CourierComponentThemeMode;\n\n /** Type of feed to display in the popup menu ('inbox' or 'archive'). */\n feedType?: CourierInboxFeedType;\n\n /** Callback fired when a message is clicked. */\n onMessageClick?: (props: CourierInboxListItemFactoryProps) => void;\n\n /** Callback fired when a message action (e.g., button) is clicked. */\n onMessageActionClick?: (props: CourierInboxListItemActionFactoryProps) => void;\n\n /** Callback fired when a message is long-pressed (for mobile/gesture support). */\n onMessageLongPress?: (props: CourierInboxListItemFactoryProps) => void;\n\n /** Allows you to pass a custom component as the header. */\n renderHeader?: (props: CourierInboxHeaderFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the list item. */\n renderListItem?: (props: CourierInboxListItemFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the empty state. */\n renderEmptyState?: (props: CourierInboxStateEmptyFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the loading state. */\n renderLoadingState?: (props: CourierInboxStateLoadingFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the error state. */\n renderErrorState?: (props: CourierInboxStateErrorFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the pagination list item. */\n renderPaginationItem?: (props: CourierInboxPaginationItemFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the menu button. */\n renderMenuButton?: (props: CourierInboxMenuButtonFactoryProps | undefined | null) => ReactNode;\n}\n\nexport const CourierInboxPopupMenuComponent = forwardRef<CourierInboxPopupMenuElement, CourierInboxPopupMenuProps>(\n (props, ref) => {\n const render = useContext(CourierRenderContext);\n if (!render) {\n throw new Error(\"RenderContext not found. Ensure CourierInboxPopupMenu is wrapped in a CourierRenderContext.\");\n }\n\n // Element ref for use in effects, updated by handleRef.\n const inboxRef = useRef<CourierInboxPopupMenuElement | null>(null);\n const [elementReady, setElementReady] = useState(false);\n\n // Callback ref passed to rendered component, used to propagate the DOM element's ref to the parent component.\n // We use a callback ref (rather than a React.RefObject) since we want the parent ref to be up-to-date with\n // rendered component. Updating the parent ref via useEffect does not work, since mutating a RefObject\n // does not trigger useEffect (see https://stackoverflow.com/a/60476525).\n function handleRef(el: CourierInboxPopupMenuElement | null) {\n if (ref) {\n if (typeof ref === 'function') {\n ref(el);\n } else {\n // @ts-ignore - RefObject.current is readonly in React 17, however it's not frozen and is equivalent the widened type MutableRefObject\n (ref as React.RefObject<CourierInboxPopupMenuElement | null>).current = el;\n }\n }\n\n // Store the element for use in effects\n inboxRef.current = el;\n\n // Update element ready state\n setElementReady(!!el);\n }\n\n // Helper to get the current element\n function getEl(): CourierInboxPopupMenuElement | null {\n return inboxRef.current;\n }\n\n // Use a ref to track the last set feedType to prevent duplicate state changes\n const lastFeedTypeRef = useRef<CourierInboxFeedType | undefined>(undefined);\n\n useEffect(() => {\n const menu = getEl();\n if (!menu) return;\n // Only set feedType if it has changed from the last set value\n if (props.feedType !== lastFeedTypeRef.current) {\n lastFeedTypeRef.current = props.feedType;\n queueMicrotask(() => {\n menu.setFeedType?.(props.feedType ?? 'inbox');\n });\n }\n }, [props.feedType, elementReady]);\n\n // Handle message click\n useEffect(() => {\n const menu = getEl();\n if (!menu) return;\n menu.onMessageClick(props.onMessageClick);\n }, [props.onMessageClick, elementReady]);\n\n // Handle message action click\n useEffect(() => {\n const menu = getEl();\n if (!menu) return;\n menu.onMessageActionClick(props.onMessageActionClick);\n }, [props.onMessageActionClick, elementReady]);\n\n // Handle message long press\n useEffect(() => {\n const menu = getEl();\n if (!menu) return;\n menu.onMessageLongPress(props.onMessageLongPress);\n }, [props.onMessageLongPress, elementReady]);\n\n // Render header\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderHeader) return;\n queueMicrotask(() => {\n menu.setHeader((headerProps?: CourierInboxHeaderFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderHeader!(headerProps);\n return render(reactNode);\n });\n });\n }, [props.renderHeader, elementReady]);\n\n // Render list item\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderListItem) return;\n queueMicrotask(() => {\n menu.setListItem((itemProps?: CourierInboxListItemFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderListItem!(itemProps);\n return render(reactNode);\n });\n });\n }, [props.renderListItem, elementReady]);\n\n // Render empty state\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderEmptyState) return;\n queueMicrotask(() => {\n menu.setEmptyState((emptyStateProps?: CourierInboxStateEmptyFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderEmptyState!(emptyStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderEmptyState, elementReady]);\n\n // Render loading state\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderLoadingState) return;\n queueMicrotask(() => {\n menu.setLoadingState((loadingStateProps?: CourierInboxStateLoadingFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderLoadingState!(loadingStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderLoadingState, elementReady]);\n\n // Render error state\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderErrorState) return;\n queueMicrotask(() => {\n menu.setErrorState((errorStateProps?: CourierInboxStateErrorFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderErrorState!(errorStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderErrorState, elementReady]);\n\n // Render pagination item\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderPaginationItem) return;\n queueMicrotask(() => {\n menu.setPaginationItem((paginationProps?: CourierInboxPaginationItemFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderPaginationItem!(paginationProps);\n return render(reactNode);\n });\n });\n }, [props.renderPaginationItem, elementReady]);\n\n // Render menu button\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderMenuButton) return;\n queueMicrotask(() => {\n menu.setMenuButton((buttonProps?: CourierInboxMenuButtonFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderMenuButton!(buttonProps);\n return render(reactNode);\n });\n });\n }, [props.renderMenuButton, elementReady]);\n\n const children = (\n /* @ts-ignore */\n <courier-inbox-popup-menu\n ref={handleRef}\n popup-alignment={props.popupAlignment}\n popup-width={props.popupWidth}\n popup-height={props.popupHeight}\n left={props.left}\n top={props.top}\n right={props.right}\n bottom={props.bottom}\n light-theme={props.lightTheme ? JSON.stringify(props.lightTheme) : undefined}\n dark-theme={props.darkTheme ? JSON.stringify(props.darkTheme) : undefined}\n mode={props.mode}\n />\n );\n\n return (\n <CourierClientComponent children={children} />\n );\n }\n);\n","import { useRef, useEffect, forwardRef, ReactNode, useContext, CSSProperties, useState } from \"react\";\nimport { CourierToastTheme, CourierToast as CourierToastElement, CourierToastItemFactoryProps } from \"@trycourier/courier-ui-toast\";\nimport { CourierComponentThemeMode } from \"@trycourier/courier-ui-core\";\nimport { CourierClientComponent } from \"./courier-client-component\";\nimport { CourierRenderContext } from \"../context/render-context\";\nimport { CourierToastDismissButtonOption, CourierToastItemClickEvent, CourierToastItemActionClickEvent } from \"@trycourier/courier-ui-toast\";\n\n/** Props that may be passed to the CourierToast component. */\nexport interface CourierToastProps {\n /**\n * Styles applied to the CourierToast component.\n *\n * By default, the component has the following styles:\n *\n * ```css\n * position: \"fixed\";\n * width: \"380px\";\n * top: \"30px\";\n * right: \"30px\";\n * z-index: 999;\n * ```\n *\n * Setting styles directly on the component is useful to customize the component's\n * position and layout. Setting `height` is effectively a no-op, as `height`\n * will be dynamically set by the component as toast items are added and removed.\n */\n style?: CSSProperties;\n\n /** Theme object used to render the component when light mode is used. */\n lightTheme?: CourierToastTheme;\n\n /** Theme object used to render the component when dark mode is used. */\n darkTheme?: CourierToastTheme;\n\n /** Manually set the theme mode to one of \"light\", \"dark\", or \"system\". Defaults to \"system\". */\n mode?: CourierComponentThemeMode;\n\n /** Enable toasts to auto-dismiss, including a timer bar at the top of the toast. Defaults to false. */\n autoDismiss?: boolean;\n\n /**\n * The timeout before a toast auto-dismisses, if {@link CourierToastProps.autoDismiss} is enabled.\n * Defaults to 5000ms.\n */\n autoDismissTimeoutMs?: number;\n\n /**\n * Set the dismiss button's visibility.\n *\n * Defaults to \"auto\", which makes the button always visible if `autoDismiss` is false\n * and visible on hover if `autoDismiss` is true.\n */\n dismissButton?: CourierToastDismissButtonOption;\n\n /** Callback function invoked when a toast item is clicked. */\n onToastItemClick?: (props: CourierToastItemClickEvent) => void;\n\n /** Callback function invoked when a toast item action button is clicked. */\n onToastItemActionClick?: (props: CourierToastItemActionClickEvent) => void;\n\n /**\n * Callback function invoked when the component is ready to receive messages.\n *\n * Use onReady to ensure CourierToast has applied event listeners and\n * render props passed to the component before toasts are presented.\n *\n * @example\n * ```tsx\n * const [toastReady, setToastReady] = useState(false);\n * const courier = useCourier();\n *\n * useEffect(() => {\n * if (toastReady) {\n * courier.shared.signIn({ userId, jwt });\n * }\n * }, [toastReady]);\n *\n * return <CourierToast onReady={setToastReady} renderToastItem={myCustomItem} />\n * ```\n */\n onReady?: (ready: boolean) => void;\n\n /** Render prop specifying how to render an entire toast item. */\n renderToastItem?: (props: CourierToastItemFactoryProps) => ReactNode;\n\n /**\n * Render prop specifying how to render a toast item's content.\n *\n * The toast item's container, including the stack, auto-dismiss timer, and dismiss button\n * are still present when this prop is set.\n *\n * See {@link CourierToastProps.dismissButton} to customize the dismiss button's visibility and\n * {@link CourierToastProps.renderToastItem} to customize the entire toast item, including\n * its container.\n */\n renderToastItemContent?: (props: CourierToastItemFactoryProps) => ReactNode;\n}\n\nexport const CourierToastComponent = forwardRef<CourierToastElement, CourierToastProps>((props, ref) => {\n const render = useContext(CourierRenderContext);\n if (!render) {\n throw new Error(\"RenderContext not found. Ensure CourierToast is wrapped in a CourierRenderContext.\");\n }\n\n // Track ready state for each of the useEffects that is called for a prop set on CourierToastComponent\n // which must be translated into an imperative call on <courier-toast>.\n // When all the steps are complete, props.onReady is called to indicate the component is ready to receive toasts.\n const [setupSteps, setSetupSteps] = useState({\n elementMounted: false,\n onItemClickSet: false,\n onItemActionClickSet: false,\n renderToastItemSet: false,\n renderToastItemContentSet: false\n });\n const [elementReady, setElementReady] = useState(false);\n\n // Element ref for use in effects, updated by handleRef.\n const toastRef = useRef<CourierToastElement | null>(null);\n\n // Callback ref passed to rendered component, used to propagate the DOM element's ref to the parent component.\n // We use a callback ref (rather than a React.RefObject) since we want the parent ref to be up-to-date with\n // rendered component. Updating the parent ref via useEffect does not work, since mutating a RefObject\n // does not trigger useEffect (see https://stackoverflow.com/a/60476525).\n function handleRef(el: CourierToastElement | null) {\n if (ref) {\n\n // Propagate ref to ref callback functions\n if (typeof ref === 'function') {\n ref(el);\n } else {\n // Propagate ref to ref objects\n // @ts-ignore - RefObject.current is readonly in React 17, however it's not frozen and is equivalent the widened type MutableRefObject\n (ref as React.RefObject<CourierToastElement | null>).current = el;\n }\n }\n\n // Store the element for use in effects\n toastRef.current = el;\n\n // Update element ready state\n setElementReady(!!el);\n }\n\n // Helper to get the current element\n function getEl(): CourierToastElement | null {\n return toastRef.current;\n }\n\n // Check if all setup steps are complete and fire onReady\n useEffect(() => {\n const allStepsComplete = Object.values(setupSteps).every(step => step);\n if (allStepsComplete && props.onReady) {\n props.onReady(true);\n }\n }, [setupSteps, props.onReady]);\n\n // Track when element is mounted\n useEffect(() => {\n if (elementReady) {\n setSetupSteps(prev => ({ ...prev, elementMounted: true }));\n }\n }, [elementReady]);\n\n // Handle toast item click\n useEffect(() => {\n const toast = getEl();\n if (!toast) return;\n toast.onToastItemClick(props.onToastItemClick);\n setSetupSteps(prev => ({ ...prev, onItemClickSet: true }));\n }, [props.onToastItemClick, elementReady]);\n\n // Handle toast item action click\n useEffect(() => {\n const toast = getEl();\n if (!toast) return;\n toast.onToastItemActionClick(props.onToastItemActionClick);\n setSetupSteps(prev => ({ ...prev, onItemActionClickSet: true }));\n }, [props.onToastItemActionClick, elementReady]);\n\n // Render toast item\n useEffect(() => {\n const toast = getEl();\n if (!toast || !props.renderToastItem) {\n setSetupSteps(prev => ({ ...prev, renderToastItemSet: true }));\n return;\n }\n\n queueMicrotask(() => {\n toast.setToastItem((itemProps: CourierToastItemFactoryProps): HTMLElement => {\n const reactNode = props.renderToastItem!(itemProps);\n return render(reactNode);\n });\n });\n setSetupSteps(prev => ({ ...prev, renderToastItemSet: true }));\n\n }, [props.renderToastItem, elementReady]);\n\n // Render toast item content\n useEffect(() => {\n const toast = getEl();\n if (!toast || !props.renderToastItemContent) {\n setSetupSteps(prev => ({ ...prev, renderToastItemContentSet: true }));\n return;\n }\n queueMicrotask(() => {\n toast.setToastItemContent((itemProps: CourierToastItemFactoryProps): HTMLElement => {\n const reactNode = props.renderToastItemContent!(itemProps);\n return render(reactNode);\n });\n setSetupSteps(prev => ({ ...prev, renderToastItemContentSet: true }));\n });\n }, [props.renderToastItemContent, elementReady]);\n\n const children = (\n /* @ts-ignore */\n <courier-toast\n ref={handleRef}\n style={props.style}\n light-theme={props.lightTheme ? JSON.stringify(props.lightTheme) : undefined}\n dark-theme={props.darkTheme ? JSON.stringify(props.darkTheme) : undefined}\n mode={props.mode}\n auto-dismiss={props.autoDismiss}\n auto-dismiss-timeout-ms={props.autoDismissTimeoutMs}\n dismiss-button={props.dismissButton}\n />\n );\n\n return (\n <CourierClientComponent children={children} />\n );\n});\n","import React from 'react';\nimport { Courier, CourierProps, InboxMessage } from '@trycourier/courier-js';\nimport { CourierInboxDatastore, CourierInboxDataStoreListener, CourierInboxFeedType, InboxDataSet } from '@trycourier/courier-ui-inbox';\nimport { CourierToastDatastore, CourierToastDatastoreListener } from '@trycourier/courier-ui-toast';\n\ntype AuthenticationHooks = {\n userId?: string,\n signIn: (props: CourierProps) => void,\n signOut: () => void\n}\n\ntype InboxHooks = {\n load: (props?: { canUseCache: boolean }) => Promise<void>,\n fetchNextPageOfMessages: (props: { feedType: CourierInboxFeedType }) => Promise<InboxDataSet | null>,\n setPaginationLimit: (limit: number) => void,\n readMessage: (message: InboxMessage) => Promise<void>,\n unreadMessage: (message: InboxMessage) => Promise<void>,\n clickMessage: (message: InboxMessage) => Promise<void>,\n archiveMessage: (message: InboxMessage) => Promise<void>,\n openMessage: (message: InboxMessage) => Promise<void>,\n unarchiveMessage: (message: InboxMessage) => Promise<void>,\n readAllMessages: () => Promise<void>,\n inbox?: InboxDataSet,\n archive?: InboxDataSet,\n unreadCount?: number,\n error?: Error\n}\n\ntype ToastHooks = {\n addMessage: (message: InboxMessage) => void;\n removeMessage: (message: InboxMessage) => void;\n error?: Error,\n}\n\n// A hook for managing the shared state of Courier\n// If you want to use more functions, checkout the Courier JS SDK which\n// can be used directly by importing from '@trycourier/courier-js'\nexport const useCourier = () => {\n\n // Authentication Functions\n const signIn = (props: CourierProps) => Courier.shared.signIn(props);\n const signOut = () => Courier.shared.signOut();\n\n // Inbox Functions\n const loadInbox = (props?: { canUseCache: boolean }) => CourierInboxDatastore.shared.load(props);\n const fetchNextPageOfMessages = (props: { feedType: CourierInboxFeedType }) => CourierInboxDatastore.shared.fetchNextPageOfMessages(props);\n const setPaginationLimit = (limit: number) => Courier.shared.paginationLimit = limit;\n const readMessage = (message: InboxMessage) => CourierInboxDatastore.shared.readMessage({ message });\n const unreadMessage = (message: InboxMessage) => CourierInboxDatastore.shared.unreadMessage({ message });\n const clickMessage = (message: InboxMessage) => CourierInboxDatastore.shared.clickMessage({ message });\n const archiveMessage = (message: InboxMessage) => CourierInboxDatastore.shared.archiveMessage({ message });\n const openMessage = (message: InboxMessage) => CourierInboxDatastore.shared.openMessage({ message });\n const unarchiveMessage = (message: InboxMessage) => CourierInboxDatastore.shared.unarchiveMessage({ message });\n const readAllMessages = () => CourierInboxDatastore.shared.readAllMessages();\n\n // State\n const [auth, setAuth] = React.useState<AuthenticationHooks>({\n userId: undefined,\n signIn,\n signOut\n });\n\n const [inbox, setInbox] = React.useState<InboxHooks>({\n load: loadInbox,\n fetchNextPageOfMessages,\n setPaginationLimit,\n readMessage,\n unreadMessage,\n clickMessage,\n archiveMessage,\n openMessage,\n unarchiveMessage,\n readAllMessages\n });\n\n const addToastMessage = (message: InboxMessage) => CourierToastDatastore.shared.addMessage(message);\n const removeToastMessage = (message: InboxMessage) => CourierToastDatastore.shared.removeMessage(message);\n\n const [toast, setToast] = React.useState<ToastHooks>({\n addMessage: addToastMessage,\n removeMessage: removeToastMessage,\n });\n\n React.useEffect(() => {\n\n // Add a listener to the Courier instance\n const listener = Courier.shared.addAuthenticationListener(() => refreshAuth());\n\n // Add inbox data store listener\n const inboxListener = new CourierInboxDataStoreListener({\n onError: (error: Error) => refreshInbox(error),\n onDataSetChange: () => refreshInbox(),\n onPageAdded: () => refreshInbox(),\n onMessageAdd: () => refreshInbox(),\n onMessageRemove: () => refreshInbox(),\n onMessageUpdate: () => refreshInbox(),\n onUnreadCountChange: () => refreshInbox()\n });\n CourierInboxDatastore.shared.addDataStoreListener(inboxListener);\n\n const toastListener = new CourierToastDatastoreListener({\n onMessageAdd: () => refreshToast(),\n onMessageRemove: () => refreshToast(),\n onError: (error: Error) => refreshToast(error),\n });\n CourierToastDatastore.shared.addDatastoreListener(toastListener);\n\n // Set initial values\n refreshAuth();\n refreshInbox();\n refreshToast();\n\n // Remove listeners when the component unmounts\n return () => {\n listener.remove();\n inboxListener.remove();\n toastListener.remove();\n };\n }, []);\n\n const refreshAuth = () => {\n const options = Courier.shared.client?.options;\n setAuth({\n userId: options?.userId,\n signIn,\n signOut\n });\n }\n\n const refreshInbox = (error?: Error) => {\n const datastore = CourierInboxDatastore.shared;\n setInbox({\n load: loadInbox,\n fetchNextPageOfMessages,\n setPaginationLimit,\n readMessage,\n unreadMessage,\n clickMessage,\n archiveMessage,\n openMessage,\n unarchiveMessage,\n readAllMessages,\n inbox: datastore.inboxDataSet,\n archive: datastore.archiveDataSet,\n unreadCount: datastore.unreadCount,\n error: error,\n });\n }\n\n const refreshToast = (error?: Error) => {\n setToast({\n addMessage: addToastMessage,\n removeMessage: removeToastMessage,\n error,\n });\n };\n\n return {\n shared: Courier.shared,\n auth: auth,\n inbox: inbox,\n toast: toast,\n };\n};\n"],"names":["CourierClientComponent","children","isMounted","setIsMounted","useState","useEffect","window","CourierRenderContext","createContext","CourierInboxComponent","forwardRef","props","ref","render","useContext","Error","inboxRef","useRef","elementReady","setElementReady","getEl","current","inbox","onMessageClick","onMessageActionClick","onMessageLongPress","renderHeader","queueMicrotask","setHeader","headerProps","reactNode","renderListItem","setListItem","itemProps","renderEmptyState","setEmptyState","emptyStateProps","renderLoadingState","setLoadingState","loadingStateProps","renderErrorState","setErrorState","errorStateProps","renderPaginationItem","setPaginationItem","paginationProps","setFeedType","feedType","jsx","el","height","lightTheme","JSON","stringify","darkTheme","mode","CourierInboxPopupMenuComponent","lastFeedTypeRef","menu","_a","call","renderMenuButton","setMenuButton","buttonProps","popupAlignment","popupWidth","popupHeight","left","top","right","bottom","CourierToastComponent","setupSteps","setSetupSteps","elementMounted","onItemClickSet","onItemActionClickSet","renderToastItemSet","renderToastItemContentSet","toastRef","Object","values","every","step","onReady","prev","toast","onToastItemClick","onToastItemActionClick","renderToastItem","setToastItem","renderToastItemContent","setToastItemContent","style","autoDismiss","autoDismissTimeoutMs","dismissButton","signIn","Courier","shared","signOut","loadInbox","CourierInboxDatastore","load","fetchNextPageOfMessages","setPaginationLimit","limit","paginationLimit","readMessage","message","unreadMessage","clickMessage","archiveMessage","openMessage","unarchiveMessage","readAllMessages","auth","setAuth","React","userId","setInbox","addToastMessage","CourierToastDatastore","addMessage","removeToastMessage","removeMessage","setToast","listener","addAuthenticationListener","refreshAuth","inboxListener","CourierInboxDataStoreListener","onError","error","refreshInbox","onDataSetChange","onPageAdded","onMessageAdd","onMessageRemove","onMessageUpdate","onUnreadCountChange","addDataStoreListener","toastListener","CourierToastDatastoreListener","refreshToast","addDatastoreListener","remove","options","client","datastore","inboxDataSet","archive","archiveDataSet","unreadCount"],"mappings":"gQASaA,EAAuD,EAAGC,eACrE,MAAOC,EAAWC,GAAgBC,EAAAA,UAAS,GAO3C,OALAC,EAAAA,WAAU,KACRF,GAAa,EAAI,GAChB,IAGmB,oBAAXG,OACF,KAGJJ,oBAIKD,aAHD,IAGU,ECHRM,EAAuBC,EAAAA,cAA+B,MC4BtDC,EAAwBC,EAAAA,YA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,CACtDN,aAAc,IAAMO,IACpBN,gBAAiB,IAAMM,IACvBZ,QAAUC,GAAiBW,EAAaX,KAU1C,OARAX,wBAAsBvB,OAAO8C,qBAAqBH,GAGlDb,IACAK,IACAU,IAGO,KACLjB,EAASmB,SACThB,EAAcgB,SACdJ,EAAcI,QAAA,CAChB,GACC,IAEH,MAAMjB,EAAc,WAClB,MAAMkB,EAAUjD,OAAAA,EAAAA,EAAAA,QAAQC,OAAOiD,aAAflD,EAAAA,EAAuBiD,QACvC9B,EAAQ,CACNE,OAAQ,MAAA4B,OAAA,EAAAA,EAAS5B,OACjBtB,SACAG,WACD,EAGGkC,EAAgBD,IACpB,MAAMgB,EAAY/C,EAAAA,sBAAsBH,OACxCqB,EAAS,CACPjB,KAAMF,EACNG,0BACAC,qBACAG,cACAE,gBACAC,eACAC,iBACAC,cACAC,mBACAC,kBACA7F,MAAO+H,EAAUC,aACjBC,QAASF,EAAUG,eACnBC,YAAaJ,EAAUI,YACvBpB,SACD,EAGGW,EAAgBX,IACpBP,EAAS,CACPH,WAAYF,EACZI,cAAeD,EACfS,SACD,EAGH,MAAO,CACLlC,OAAQD,EAAAA,QAAQC,OAChBiB,OACA9F,QACAgE,QAAA"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/components/courier-client-component.tsx","../src/context/render-context.ts","../src/components/courier-inbox-component.tsx","../src/components/courier-inbox-popup-menu-component.tsx","../src/components/courier-toast-component.tsx","../src/hooks/use-courier.tsx"],"sourcesContent":["import React, { useState, useEffect } from 'react';\n\ninterface CourierClientProps {\n children: React.ReactNode;\n}\n\n// This class prevents issues with server side rendering react components\n// It will force the component to only render client side\n// A future update could support server side rendering if there is enough demand\nexport const CourierClientComponent: React.FC<CourierClientProps> = ({ children }) => {\n const [isMounted, setIsMounted] = useState(false);\n\n useEffect(() => {\n setIsMounted(true);\n }, []);\n\n // During SSR, render nothing or fallback\n if (typeof window === 'undefined') {\n return null;\n }\n\n if (!isMounted) {\n return null;\n }\n\n return <>{children}</>;\n};","import { createContext, ReactNode } from \"react\";\n\ntype RenderFn = (node: ReactNode) => HTMLElement;\n\n/**\n * Context providing a function to render a React component.\n *\n * Courier's React package renders as follows:\n *\n * - React engine (client application)\n * - Courier React components\n * - Courier web components\n * - [Optional] User-provided React components (ex. a list item)\n *\n * By default, React will not render the user-provided React components within Courier's\n * web components. We instead manually render the user-provided React components and inject\n * them into the Courier web components.\n *\n * Client rendering changed between React 17 and 18, so the SDKs provide React version-specific\n * rendering functions. See\n * https://18.react.dev/blog/2022/03/08/react-18-upgrade-guide#updates-to-client-rendering-apis.\n */\nexport const CourierRenderContext = createContext<RenderFn | null>(null);\n","import { useRef, useEffect, forwardRef, ReactNode, useContext, useState } from \"react\";\nimport { CourierInboxListItemActionFactoryProps, CourierInboxListItemFactoryProps, CourierInboxTheme, CourierInbox as CourierInboxElement, CourierInboxHeaderFactoryProps, CourierInboxStateEmptyFactoryProps, CourierInboxStateLoadingFactoryProps, CourierInboxStateErrorFactoryProps, CourierInboxPaginationItemFactoryProps, CourierInboxFeed } from \"@trycourier/courier-ui-inbox\";\nimport { CourierComponentThemeMode } from \"@trycourier/courier-ui-core\";\nimport { CourierClientComponent } from \"./courier-client-component\";\nimport { CourierRenderContext } from \"../context/render-context\";\n\nexport interface CourierInboxProps {\n /** Height of the inbox container. Defaults to \"auto\" and will resize itself based on it's children. */\n height?: string;\n\n /** Theme object for light mode */\n lightTheme?: CourierInboxTheme;\n\n /** Theme object for dark mode */\n darkTheme?: CourierInboxTheme;\n\n /** Theme mode: \"light\", \"dark\", or \"system\". Defaults to \"system\" */\n mode?: CourierComponentThemeMode;\n\n /** Type of feed to display in the inbox. Defaults to \"inbox\" */\n feedType?: string;\n\n /** Array of feeds to display in the inbox. Each feed contains tabs with different filters. */\n feeds?: CourierInboxFeed[];\n\n /** Callback fired when a message is clicked. */\n onMessageClick?: (props: CourierInboxListItemFactoryProps) => void;\n\n /** Callback fired when a message action (e.g., button) is clicked. */\n onMessageActionClick?: (props: CourierInboxListItemActionFactoryProps) => void;\n\n /** Callback fired when a message is long-pressed (for mobile/gesture support). Only works on devices that support touch. */\n onMessageLongPress?: (props: CourierInboxListItemFactoryProps) => void;\n\n /** Allows you to pass a custom component as the header. */\n renderHeader?: (props: CourierInboxHeaderFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the list item. */\n renderListItem?: (props: CourierInboxListItemFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the empty state. */\n renderEmptyState?: (props: CourierInboxStateEmptyFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the loading state. */\n renderLoadingState?: (props: CourierInboxStateLoadingFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the error state. */\n renderErrorState?: (props: CourierInboxStateErrorFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the pagination list item. */\n renderPaginationItem?: (props: CourierInboxPaginationItemFactoryProps | undefined | null) => ReactNode;\n}\n\nexport const CourierInboxComponent = forwardRef<CourierInboxElement, CourierInboxProps>((props, ref) => {\n const render = useContext(CourierRenderContext);\n if (!render) {\n throw new Error(\"RenderContext not found. Ensure CourierInbox is wrapped in a CourierRenderContext.\");\n }\n\n // Element ref for use in effects, updated by handleRef.\n const inboxRef = useRef<CourierInboxElement | null>(null);\n const [elementReady, setElementReady] = useState(false);\n const feedsSetRef = useRef(false);\n\n // Callback ref passed to rendered component, used to propagate the DOM element's ref to the parent component.\n // We use a callback ref (rather than a React.RefObject) since we want the parent ref to be up-to-date with\n // rendered component. Updating the parent ref via useEffect does not work, since mutating a RefObject\n // does not trigger useEffect (see https://stackoverflow.com/a/60476525).\n function handleRef(el: CourierInboxElement | null) {\n if (ref) {\n\n // Propagate ref to ref callback functions\n if (typeof ref === 'function') {\n ref(el);\n } else {\n // Propagate ref to ref objects\n // @ts-ignore - RefObject.current is readonly in React 17, however it's not frozen and is equivalent the widened type MutableRefObject\n (ref as React.RefObject<CourierInboxElement | null>).current = el;\n }\n }\n\n // Store the element for use in effects\n inboxRef.current = el;\n\n // Update element ready state\n setElementReady(!!el);\n }\n\n // Helper to get the current element\n function getEl(): CourierInboxElement | null {\n return inboxRef.current;\n }\n\n // Handle message click\n useEffect(() => {\n const inbox = getEl();\n if (!inbox) return;\n inbox.onMessageClick(props.onMessageClick);\n }, [props.onMessageClick, elementReady]);\n\n // Handle message action click\n useEffect(() => {\n const inbox = getEl();\n if (!inbox) return;\n inbox.onMessageActionClick(props.onMessageActionClick);\n }, [props.onMessageActionClick, elementReady]);\n\n // Handle message long press\n useEffect(() => {\n const inbox = getEl();\n if (!inbox) return;\n inbox.onMessageLongPress(props.onMessageLongPress);\n }, [props.onMessageLongPress, elementReady]);\n\n // Render header\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderHeader) return;\n queueMicrotask(() => {\n inbox.setHeader((headerProps?: CourierInboxHeaderFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderHeader!(headerProps);\n return render(reactNode);\n });\n });\n }, [props.renderHeader, elementReady]);\n\n // Render list item\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderListItem) return;\n queueMicrotask(() => {\n inbox.setListItem((itemProps?: CourierInboxListItemFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderListItem!(itemProps);\n return render(reactNode);\n });\n });\n }, [props.renderListItem, elementReady]);\n\n // Render empty state\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderEmptyState) return;\n queueMicrotask(() => {\n inbox.setEmptyState((emptyStateProps?: CourierInboxStateEmptyFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderEmptyState!(emptyStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderEmptyState, elementReady]);\n\n // Render loading state\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderLoadingState) return;\n queueMicrotask(() => {\n inbox.setLoadingState((loadingStateProps?: CourierInboxStateLoadingFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderLoadingState!(loadingStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderLoadingState, elementReady]);\n\n // Render error state\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderErrorState) return;\n queueMicrotask(() => {\n inbox.setErrorState((errorStateProps?: CourierInboxStateErrorFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderErrorState!(errorStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderErrorState, elementReady]);\n\n // Render pagination item\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderPaginationItem) return;\n queueMicrotask(() => {\n inbox.setPaginationItem((paginationProps?: CourierInboxPaginationItemFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderPaginationItem!(paginationProps);\n return render(reactNode);\n });\n });\n }, [props.renderPaginationItem, elementReady]);\n\n // Set feeds (only once when element is ready)\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.feeds || feedsSetRef.current) return;\n feedsSetRef.current = true;\n queueMicrotask(() => {\n inbox.setFeeds(props.feeds!);\n });\n }, [props.feeds, elementReady]);\n\n const children = (\n /* @ts-ignore */\n <courier-inbox\n ref={handleRef}\n height={props.height}\n light-theme={props.lightTheme ? JSON.stringify(props.lightTheme) : undefined}\n dark-theme={props.darkTheme ? JSON.stringify(props.darkTheme) : undefined}\n mode={props.mode}\n />\n );\n\n return (\n <CourierClientComponent children={children} />\n );\n});\n","import { useEffect, useRef, forwardRef, ReactNode, useContext, useState } from 'react';\nimport {\n CourierInboxHeaderFactoryProps,\n CourierInboxListItemActionFactoryProps,\n CourierInboxListItemFactoryProps,\n CourierInboxMenuButtonFactoryProps,\n CourierInboxPopupMenu as CourierInboxPopupMenuElement,\n CourierInboxPaginationItemFactoryProps,\n CourierInboxPopupAlignment,\n CourierInboxStateEmptyFactoryProps,\n CourierInboxStateErrorFactoryProps,\n CourierInboxStateLoadingFactoryProps,\n CourierInboxTheme,\n CourierInboxFeed,\n} from '@trycourier/courier-ui-inbox';\nimport { CourierComponentThemeMode } from '@trycourier/courier-ui-core';\nimport { CourierClientComponent } from './courier-client-component';\nimport { CourierRenderContext } from '../context/render-context';\n\nexport interface CourierInboxPopupMenuProps {\n /** Alignment of the popup menu: 'top-right', 'top-left', 'top-center', 'bottom-right', 'bottom-left', 'bottom-center', 'center-right', 'center-left', 'center-center'. */\n popupAlignment?: CourierInboxPopupAlignment;\n\n /** Width of the popup menu container. */\n popupWidth?: string;\n\n /** Height of the popup menu container. */\n popupHeight?: string;\n\n /** CSS left position for the popup menu. */\n left?: string;\n\n /** CSS top position for the popup menu. */\n top?: string;\n\n /** CSS right position for the popup menu. */\n right?: string;\n\n /** CSS bottom position for the popup menu. */\n bottom?: string;\n\n /** Theme object for light mode. */\n lightTheme?: CourierInboxTheme;\n\n /** Theme object for dark mode. */\n darkTheme?: CourierInboxTheme;\n\n /** Theme mode: 'light', 'dark', or 'system'. */\n mode?: CourierComponentThemeMode;\n\n /** Array of feeds to display in the inbox. Each feed contains tabs with different filters. */\n feeds?: CourierInboxFeed[];\n\n /** Callback fired when a message is clicked. */\n onMessageClick?: (props: CourierInboxListItemFactoryProps) => void;\n\n /** Callback fired when a message action (e.g., button) is clicked. */\n onMessageActionClick?: (props: CourierInboxListItemActionFactoryProps) => void;\n\n /** Callback fired when a message is long-pressed (for mobile/gesture support). */\n onMessageLongPress?: (props: CourierInboxListItemFactoryProps) => void;\n\n /** Allows you to pass a custom component as the header. */\n renderHeader?: (props: CourierInboxHeaderFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the list item. */\n renderListItem?: (props: CourierInboxListItemFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the empty state. */\n renderEmptyState?: (props: CourierInboxStateEmptyFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the loading state. */\n renderLoadingState?: (props: CourierInboxStateLoadingFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the error state. */\n renderErrorState?: (props: CourierInboxStateErrorFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the pagination list item. */\n renderPaginationItem?: (props: CourierInboxPaginationItemFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the menu button. */\n renderMenuButton?: (props: CourierInboxMenuButtonFactoryProps | undefined | null) => ReactNode;\n}\n\nexport const CourierInboxPopupMenuComponent = forwardRef<CourierInboxPopupMenuElement, CourierInboxPopupMenuProps>(\n (props, ref) => {\n const render = useContext(CourierRenderContext);\n if (!render) {\n throw new Error(\"RenderContext not found. Ensure CourierInboxPopupMenu is wrapped in a CourierRenderContext.\");\n }\n\n // Element ref for use in effects, updated by handleRef.\n const inboxRef = useRef<CourierInboxPopupMenuElement | null>(null);\n const [elementReady, setElementReady] = useState(false);\n const feedsSetRef = useRef(false);\n\n // Callback ref passed to rendered component, used to propagate the DOM element's ref to the parent component.\n // We use a callback ref (rather than a React.RefObject) since we want the parent ref to be up-to-date with\n // rendered component. Updating the parent ref via useEffect does not work, since mutating a RefObject\n // does not trigger useEffect (see https://stackoverflow.com/a/60476525).\n function handleRef(el: CourierInboxPopupMenuElement | null) {\n if (ref) {\n if (typeof ref === 'function') {\n ref(el);\n } else {\n // @ts-ignore - RefObject.current is readonly in React 17, however it's not frozen and is equivalent the widened type MutableRefObject\n (ref as React.RefObject<CourierInboxPopupMenuElement | null>).current = el;\n }\n }\n\n // Store the element for use in effects\n inboxRef.current = el;\n\n // Update element ready state\n setElementReady(!!el);\n }\n\n // Helper to get the current element\n function getEl(): CourierInboxPopupMenuElement | null {\n return inboxRef.current;\n }\n\n // Handle message click\n useEffect(() => {\n const menu = getEl();\n if (!menu) return;\n menu.onMessageClick(props.onMessageClick);\n }, [props.onMessageClick, elementReady]);\n\n // Handle message action click\n useEffect(() => {\n const menu = getEl();\n if (!menu) return;\n menu.onMessageActionClick(props.onMessageActionClick);\n }, [props.onMessageActionClick, elementReady]);\n\n // Handle message long press\n useEffect(() => {\n const menu = getEl();\n if (!menu) return;\n menu.onMessageLongPress(props.onMessageLongPress);\n }, [props.onMessageLongPress, elementReady]);\n\n // Render header\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderHeader) return;\n queueMicrotask(() => {\n menu.setHeader((headerProps?: CourierInboxHeaderFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderHeader!(headerProps);\n return render(reactNode);\n });\n });\n }, [props.renderHeader, elementReady]);\n\n // Render list item\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderListItem) return;\n queueMicrotask(() => {\n menu.setListItem((itemProps?: CourierInboxListItemFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderListItem!(itemProps);\n return render(reactNode);\n });\n });\n }, [props.renderListItem, elementReady]);\n\n // Render empty state\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderEmptyState) return;\n queueMicrotask(() => {\n menu.setEmptyState((emptyStateProps?: CourierInboxStateEmptyFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderEmptyState!(emptyStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderEmptyState, elementReady]);\n\n // Render loading state\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderLoadingState) return;\n queueMicrotask(() => {\n menu.setLoadingState((loadingStateProps?: CourierInboxStateLoadingFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderLoadingState!(loadingStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderLoadingState, elementReady]);\n\n // Render error state\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderErrorState) return;\n queueMicrotask(() => {\n menu.setErrorState((errorStateProps?: CourierInboxStateErrorFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderErrorState!(errorStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderErrorState, elementReady]);\n\n // Render pagination item\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderPaginationItem) return;\n queueMicrotask(() => {\n menu.setPaginationItem((paginationProps?: CourierInboxPaginationItemFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderPaginationItem!(paginationProps);\n return render(reactNode);\n });\n });\n }, [props.renderPaginationItem, elementReady]);\n\n // Render menu button\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderMenuButton) return;\n queueMicrotask(() => {\n menu.setMenuButton((buttonProps?: CourierInboxMenuButtonFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderMenuButton!(buttonProps);\n return render(reactNode);\n });\n });\n }, [props.renderMenuButton, elementReady]);\n\n // Set feeds (only once when element is ready)\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.feeds || feedsSetRef.current) return;\n feedsSetRef.current = true;\n queueMicrotask(() => {\n menu.setFeeds(props.feeds!);\n });\n }, [props.feeds, elementReady]);\n\n const children = (\n /* @ts-ignore */\n <courier-inbox-popup-menu\n ref={handleRef}\n popup-alignment={props.popupAlignment}\n popup-width={props.popupWidth}\n popup-height={props.popupHeight}\n left={props.left}\n top={props.top}\n right={props.right}\n bottom={props.bottom}\n light-theme={props.lightTheme ? JSON.stringify(props.lightTheme) : undefined}\n dark-theme={props.darkTheme ? JSON.stringify(props.darkTheme) : undefined}\n mode={props.mode}\n />\n );\n\n return (\n <CourierClientComponent children={children} />\n );\n }\n);\n","import { useRef, useEffect, forwardRef, ReactNode, useContext, CSSProperties, useState } from \"react\";\nimport { CourierToastTheme, CourierToast as CourierToastElement, CourierToastItemFactoryProps } from \"@trycourier/courier-ui-toast\";\nimport { CourierComponentThemeMode } from \"@trycourier/courier-ui-core\";\nimport { CourierClientComponent } from \"./courier-client-component\";\nimport { CourierRenderContext } from \"../context/render-context\";\nimport { CourierToastDismissButtonOption, CourierToastItemClickEvent, CourierToastItemActionClickEvent } from \"@trycourier/courier-ui-toast\";\n\n/** Props that may be passed to the CourierToast component. */\nexport interface CourierToastProps {\n /**\n * Styles applied to the CourierToast component.\n *\n * By default, the component has the following styles:\n *\n * ```css\n * position: \"fixed\";\n * width: \"380px\";\n * top: \"30px\";\n * right: \"30px\";\n * z-index: 999;\n * ```\n *\n * Setting styles directly on the component is useful to customize the component's\n * position and layout. Setting `height` is effectively a no-op, as `height`\n * will be dynamically set by the component as toast items are added and removed.\n */\n style?: CSSProperties;\n\n /** Theme object used to render the component when light mode is used. */\n lightTheme?: CourierToastTheme;\n\n /** Theme object used to render the component when dark mode is used. */\n darkTheme?: CourierToastTheme;\n\n /** Manually set the theme mode to one of \"light\", \"dark\", or \"system\". Defaults to \"system\". */\n mode?: CourierComponentThemeMode;\n\n /** Enable toasts to auto-dismiss, including a timer bar at the top of the toast. Defaults to false. */\n autoDismiss?: boolean;\n\n /**\n * The timeout before a toast auto-dismisses, if {@link CourierToastProps.autoDismiss} is enabled.\n * Defaults to 5000ms.\n */\n autoDismissTimeoutMs?: number;\n\n /**\n * Set the dismiss button's visibility.\n *\n * Defaults to \"auto\", which makes the button always visible if `autoDismiss` is false\n * and visible on hover if `autoDismiss` is true.\n */\n dismissButton?: CourierToastDismissButtonOption;\n\n /** Callback function invoked when a toast item is clicked. */\n onToastItemClick?: (props: CourierToastItemClickEvent) => void;\n\n /** Callback function invoked when a toast item action button is clicked. */\n onToastItemActionClick?: (props: CourierToastItemActionClickEvent) => void;\n\n /**\n * Callback function invoked when the component is ready to receive messages.\n *\n * Use onReady to ensure CourierToast has applied event listeners and\n * render props passed to the component before toasts are presented.\n *\n * @example\n * ```tsx\n * const [toastReady, setToastReady] = useState(false);\n * const courier = useCourier();\n *\n * useEffect(() => {\n * if (toastReady) {\n * courier.shared.signIn({ userId, jwt });\n * }\n * }, [toastReady]);\n *\n * return <CourierToast onReady={setToastReady} renderToastItem={myCustomItem} />\n * ```\n */\n onReady?: (ready: boolean) => void;\n\n /** Render prop specifying how to render an entire toast item. */\n renderToastItem?: (props: CourierToastItemFactoryProps) => ReactNode;\n\n /**\n * Render prop specifying how to render a toast item's content.\n *\n * The toast item's container, including the stack, auto-dismiss timer, and dismiss button\n * are still present when this prop is set.\n *\n * See {@link CourierToastProps.dismissButton} to customize the dismiss button's visibility and\n * {@link CourierToastProps.renderToastItem} to customize the entire toast item, including\n * its container.\n */\n renderToastItemContent?: (props: CourierToastItemFactoryProps) => ReactNode;\n}\n\nexport const CourierToastComponent = forwardRef<CourierToastElement, CourierToastProps>((props, ref) => {\n const render = useContext(CourierRenderContext);\n if (!render) {\n throw new Error(\"RenderContext not found. Ensure CourierToast is wrapped in a CourierRenderContext.\");\n }\n\n // Track ready state for each of the useEffects that is called for a prop set on CourierToastComponent\n // which must be translated into an imperative call on <courier-toast>.\n // When all the steps are complete, props.onReady is called to indicate the component is ready to receive toasts.\n const [setupSteps, setSetupSteps] = useState({\n elementMounted: false,\n onItemClickSet: false,\n onItemActionClickSet: false,\n renderToastItemSet: false,\n renderToastItemContentSet: false\n });\n const [elementReady, setElementReady] = useState(false);\n\n // Element ref for use in effects, updated by handleRef.\n const toastRef = useRef<CourierToastElement | null>(null);\n\n // Callback ref passed to rendered component, used to propagate the DOM element's ref to the parent component.\n // We use a callback ref (rather than a React.RefObject) since we want the parent ref to be up-to-date with\n // rendered component. Updating the parent ref via useEffect does not work, since mutating a RefObject\n // does not trigger useEffect (see https://stackoverflow.com/a/60476525).\n function handleRef(el: CourierToastElement | null) {\n if (ref) {\n\n // Propagate ref to ref callback functions\n if (typeof ref === 'function') {\n ref(el);\n } else {\n // Propagate ref to ref objects\n // @ts-ignore - RefObject.current is readonly in React 17, however it's not frozen and is equivalent the widened type MutableRefObject\n (ref as React.RefObject<CourierToastElement | null>).current = el;\n }\n }\n\n // Store the element for use in effects\n toastRef.current = el;\n\n // Update element ready state\n setElementReady(!!el);\n }\n\n // Helper to get the current element\n function getEl(): CourierToastElement | null {\n return toastRef.current;\n }\n\n // Check if all setup steps are complete and fire onReady\n useEffect(() => {\n const allStepsComplete = Object.values(setupSteps).every(step => step);\n if (allStepsComplete && props.onReady) {\n props.onReady(true);\n }\n }, [setupSteps, props.onReady]);\n\n // Track when element is mounted\n useEffect(() => {\n if (elementReady) {\n setSetupSteps(prev => ({ ...prev, elementMounted: true }));\n }\n }, [elementReady]);\n\n // Handle toast item click\n useEffect(() => {\n const toast = getEl();\n if (!toast) return;\n toast.onToastItemClick(props.onToastItemClick);\n setSetupSteps(prev => ({ ...prev, onItemClickSet: true }));\n }, [props.onToastItemClick, elementReady]);\n\n // Handle toast item action click\n useEffect(() => {\n const toast = getEl();\n if (!toast) return;\n toast.onToastItemActionClick(props.onToastItemActionClick);\n setSetupSteps(prev => ({ ...prev, onItemActionClickSet: true }));\n }, [props.onToastItemActionClick, elementReady]);\n\n // Render toast item\n useEffect(() => {\n const toast = getEl();\n if (!toast || !props.renderToastItem) {\n setSetupSteps(prev => ({ ...prev, renderToastItemSet: true }));\n return;\n }\n\n queueMicrotask(() => {\n toast.setToastItem((itemProps: CourierToastItemFactoryProps): HTMLElement => {\n const reactNode = props.renderToastItem!(itemProps);\n return render(reactNode);\n });\n });\n setSetupSteps(prev => ({ ...prev, renderToastItemSet: true }));\n\n }, [props.renderToastItem, elementReady]);\n\n // Render toast item content\n useEffect(() => {\n const toast = getEl();\n if (!toast || !props.renderToastItemContent) {\n setSetupSteps(prev => ({ ...prev, renderToastItemContentSet: true }));\n return;\n }\n queueMicrotask(() => {\n toast.setToastItemContent((itemProps: CourierToastItemFactoryProps): HTMLElement => {\n const reactNode = props.renderToastItemContent!(itemProps);\n return render(reactNode);\n });\n setSetupSteps(prev => ({ ...prev, renderToastItemContentSet: true }));\n });\n }, [props.renderToastItemContent, elementReady]);\n\n const children = (\n /* @ts-ignore */\n <courier-toast\n ref={handleRef}\n style={props.style}\n light-theme={props.lightTheme ? JSON.stringify(props.lightTheme) : undefined}\n dark-theme={props.darkTheme ? JSON.stringify(props.darkTheme) : undefined}\n mode={props.mode}\n auto-dismiss={props.autoDismiss}\n auto-dismiss-timeout-ms={props.autoDismissTimeoutMs}\n dismiss-button={props.dismissButton}\n />\n );\n\n return (\n <CourierClientComponent children={children} />\n );\n});\n","import React from 'react';\nimport { Courier, CourierProps, InboxMessage } from '@trycourier/courier-js';\nimport { CourierInboxDatastore, CourierInboxDataStoreListener, InboxDataSet, CourierInboxFeed } from '@trycourier/courier-ui-inbox';\nimport { CourierToastDatastore, CourierToastDatastoreListener } from '@trycourier/courier-ui-toast';\n\ntype AuthenticationHooks = {\n userId?: string,\n signIn: (props: CourierProps) => void,\n signOut: () => void\n}\n\ntype InboxHooks = {\n load: (props?: { canUseCache: boolean }) => Promise<void>,\n fetchNextPageOfMessages: (props: { datasetId: string }) => Promise<InboxDataSet | null>,\n setPaginationLimit: (limit: number) => void,\n readMessage: (message: InboxMessage) => Promise<void>,\n unreadMessage: (message: InboxMessage) => Promise<void>,\n clickMessage: (message: InboxMessage) => Promise<void>,\n archiveMessage: (message: InboxMessage) => Promise<void>,\n openMessage: (message: InboxMessage) => Promise<void>,\n unarchiveMessage: (message: InboxMessage) => Promise<void>,\n readAllMessages: () => Promise<void>,\n registerFeeds: (feeds: CourierInboxFeed[]) => void,\n listenForUpdates: () => Promise<void>,\n feeds: Record<string, InboxDataSet>,\n totalUnreadCount?: number,\n error?: Error\n}\n\ntype ToastHooks = {\n addMessage: (message: InboxMessage) => void;\n removeMessage: (message: InboxMessage) => void;\n error?: Error,\n}\n\n// A hook for managing the shared state of Courier\n// If you want to use more functions, checkout the Courier JS SDK which\n// can be used directly by importing from '@trycourier/courier-js'\nexport const useCourier = () => {\n\n // Authentication Functions\n const signIn = (props: CourierProps) => Courier.shared.signIn(props);\n const signOut = () => Courier.shared.signOut();\n\n // Inbox Functions\n const loadInbox = (props?: { canUseCache: boolean }) => CourierInboxDatastore.shared.load(props);\n const fetchNextPageOfMessages = (props: { datasetId: string }) => CourierInboxDatastore.shared.fetchNextPageOfMessages(props);\n const setPaginationLimit = (limit: number) => Courier.shared.paginationLimit = limit;\n const readMessage = (message: InboxMessage) => CourierInboxDatastore.shared.readMessage({ message });\n const unreadMessage = (message: InboxMessage) => CourierInboxDatastore.shared.unreadMessage({ message });\n const clickMessage = (message: InboxMessage) => CourierInboxDatastore.shared.clickMessage({ message });\n const archiveMessage = (message: InboxMessage) => CourierInboxDatastore.shared.archiveMessage({ message });\n const openMessage = (message: InboxMessage) => CourierInboxDatastore.shared.openMessage({ message });\n const unarchiveMessage = (message: InboxMessage) => CourierInboxDatastore.shared.unarchiveMessage({ message });\n const readAllMessages = () => CourierInboxDatastore.shared.readAllMessages();\n const registerFeeds = (feeds: CourierInboxFeed[]) => CourierInboxDatastore.shared.registerFeeds(feeds);\n const listenForUpdates = () => CourierInboxDatastore.shared.listenForUpdates();\n\n // State\n const [auth, setAuth] = React.useState<AuthenticationHooks>({\n userId: undefined,\n signIn,\n signOut\n });\n\n const [inbox, setInbox] = React.useState<InboxHooks>({\n load: loadInbox,\n fetchNextPageOfMessages,\n setPaginationLimit,\n readMessage,\n unreadMessage,\n clickMessage,\n archiveMessage,\n openMessage,\n unarchiveMessage,\n readAllMessages,\n registerFeeds,\n listenForUpdates,\n feeds: {}\n });\n\n const addToastMessage = (message: InboxMessage) => CourierToastDatastore.shared.addMessage(message);\n const removeToastMessage = (message: InboxMessage) => CourierToastDatastore.shared.removeMessage(message);\n\n const [toast, setToast] = React.useState<ToastHooks>({\n addMessage: addToastMessage,\n removeMessage: removeToastMessage,\n });\n\n React.useEffect(() => {\n\n // Add a listener to the Courier instance\n const listener = Courier.shared.addAuthenticationListener(() => refreshAuth());\n\n // Add inbox data store listener\n const inboxListener = new CourierInboxDataStoreListener({\n onError: (error: Error) => refreshInbox(error),\n onDataSetChange: () => refreshInbox(),\n onPageAdded: () => refreshInbox(),\n onMessageAdd: () => refreshInbox(),\n onMessageRemove: () => refreshInbox(),\n onMessageUpdate: () => refreshInbox(),\n onUnreadCountChange: () => refreshInbox(),\n onTotalUnreadCountChange: () => refreshInbox()\n });\n CourierInboxDatastore.shared.addDataStoreListener(inboxListener);\n\n const toastListener = new CourierToastDatastoreListener({\n onMessageAdd: () => refreshToast(),\n onMessageRemove: () => refreshToast(),\n onError: (error: Error) => refreshToast(error),\n });\n CourierToastDatastore.shared.addDatastoreListener(toastListener);\n\n // Set initial values\n refreshAuth();\n refreshInbox();\n refreshToast();\n\n // Remove listeners when the component unmounts\n return () => {\n listener.remove();\n inboxListener.remove();\n toastListener.remove();\n };\n }, []);\n\n const refreshAuth = () => {\n const options = Courier.shared.client?.options;\n setAuth({\n userId: options?.userId,\n signIn,\n signOut\n });\n }\n\n const refreshInbox = (error?: Error) => {\n const datastore = CourierInboxDatastore.shared;\n const allDatasets = datastore.getDatasets();\n setInbox({\n load: loadInbox,\n fetchNextPageOfMessages,\n setPaginationLimit,\n readMessage,\n unreadMessage,\n clickMessage,\n archiveMessage,\n openMessage,\n unarchiveMessage,\n readAllMessages,\n registerFeeds,\n listenForUpdates,\n feeds: allDatasets,\n totalUnreadCount: datastore.totalUnreadCount,\n error: error,\n });\n }\n\n const refreshToast = (error?: Error) => {\n setToast({\n addMessage: addToastMessage,\n removeMessage: removeToastMessage,\n error,\n });\n };\n\n return {\n shared: Courier.shared,\n auth: auth,\n inbox: inbox,\n toast: toast,\n };\n};\n"],"names":["CourierClientComponent","children","isMounted","setIsMounted","useState","useEffect","window","CourierRenderContext","createContext","CourierInboxComponent","forwardRef","props","ref","render","useContext","Error","inboxRef","useRef","elementReady","setElementReady","feedsSetRef","getEl","current","inbox","onMessageClick","onMessageActionClick","onMessageLongPress","renderHeader","queueMicrotask","setHeader","headerProps","reactNode","renderListItem","setListItem","itemProps","renderEmptyState","setEmptyState","emptyStateProps","renderLoadingState","setLoadingState","loadingStateProps","renderErrorState","setErrorState","errorStateProps","renderPaginationItem","setPaginationItem","paginationProps","feeds","setFeeds","jsx","el","height","lightTheme","JSON","stringify","darkTheme","mode","CourierInboxPopupMenuComponent","menu","renderMenuButton","setMenuButton","buttonProps","popupAlignment","popupWidth","popupHeight","left","top","right","bottom","CourierToastComponent","setupSteps","setSetupSteps","elementMounted","onItemClickSet","onItemActionClickSet","renderToastItemSet","renderToastItemContentSet","toastRef","Object","values","every","step","onReady","prev","toast","onToastItemClick","onToastItemActionClick","renderToastItem","setToastItem","renderToastItemContent","setToastItemContent","style","autoDismiss","autoDismissTimeoutMs","dismissButton","signIn","Courier","shared","signOut","loadInbox","CourierInboxDatastore","load","fetchNextPageOfMessages","setPaginationLimit","limit","paginationLimit","readMessage","message","unreadMessage","clickMessage","archiveMessage","openMessage","unarchiveMessage","readAllMessages","registerFeeds","listenForUpdates","auth","setAuth","React","userId","setInbox","addToastMessage","CourierToastDatastore","addMessage","removeToastMessage","removeMessage","setToast","listener","addAuthenticationListener","refreshAuth","inboxListener","CourierInboxDataStoreListener","onError","error","refreshInbox","onDataSetChange","onPageAdded","onMessageAdd","onMessageRemove","onMessageUpdate","onUnreadCountChange","onTotalUnreadCountChange","addDataStoreListener","toastListener","CourierToastDatastoreListener","refreshToast","addDatastoreListener","remove","options","client","datastore","allDatasets","getDatasets","totalUnreadCount"],"mappings":"gQASaA,EAAuD,EAAGC,eACrE,MAAOC,EAAWC,GAAgBC,EAAAA,UAAS,GAO3C,OALAC,EAAAA,WAAU,KACRF,GAAa,EAAI,GAChB,IAGmB,oBAAXG,OACF,KAGJJ,oBAIKD,aAHD,IAGU,ECHRM,EAAuBC,EAAAA,cAA+B,MC+BtDC,EAAwBC,EAAAA,YAAmD,CAACC,EAAOC,KAC9F,MAAMC,EAASC,EAAAA,WAAWP,GAC1B,IAAKM,EACH,MAAM,IAAIE,MAAM,sFAIlB,MAAMC,EAAWC,EAAAA,OAAmC,OAC7CC,EAAcC,GAAmBf,EAAAA,UAAS,GAC3CgB,EAAcH,EAAAA,QAAO,GA2B3B,SAASI,IACP,OAAOL,EAASM,OAClB,CAGAjB,EAAAA,WAAU,KACR,MAAMkB,EAAQF,IACTE,GACLA,EAAMC,eAAeb,EAAMa,eAAc,GACxC,CAACb,EAAMa,eAAgBN,IAG1Bb,EAAAA,WAAU,KACR,MAAMkB,EAAQF,IACTE,GACLA,EAAME,qBAAqBd,EAAMc,qBAAoB,GACpD,CAACd,EAAMc,qBAAsBP,IAGhCb,EAAAA,WAAU,KACR,MAA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vC/B,EAAQ,CACNE,OAAQ,MAAA6B,OAAA,EAAAA,EAAS7B,OACjBxB,SACAG,WACD,EAGGoC,EAAgBD,IACpB,MAAMiB,EAAYlD,EAAAA,sBAAsBH,OAClCsD,EAAcD,EAAUE,cAC9BhC,EAAS,CACPnB,KAAMF,EACNG,0BACAC,qBACAG,cACAE,gBACAC,eACAC,iBACAC,cACAC,mBACAC,kBACAC,gBACAC,mBACApE,MAAOwG,EACPE,iBAAkBH,EAAUG,iBAC5BpB,SACD,EAGGY,EAAgBZ,IACpBP,EAAS,CACPH,WAAYF,EACZI,cAAeD,EACfS,SACD,EAGH,MAAO,CACLpC,OAAQD,EAAAA,QAAQC,OAChBmB,OACA7F,QACA6D,QAAA"}
package/dist/index.mjs CHANGED
@@ -16,6 +16,8 @@ const useCourier = () => {
16
16
  const openMessage = (message) => CourierInboxDatastore.shared.openMessage({ message });
17
17
  const unarchiveMessage = (message) => CourierInboxDatastore.shared.unarchiveMessage({ message });
18
18
  const readAllMessages = () => CourierInboxDatastore.shared.readAllMessages();
19
+ const registerFeeds = (feeds) => CourierInboxDatastore.shared.registerFeeds(feeds);
20
+ const listenForUpdates = () => CourierInboxDatastore.shared.listenForUpdates();
19
21
  const [auth, setAuth] = React.useState({
20
22
  userId: void 0,
21
23
  signIn,
@@ -31,7 +33,10 @@ const useCourier = () => {
31
33
  archiveMessage,
32
34
  openMessage,
33
35
  unarchiveMessage,
34
- readAllMessages
36
+ readAllMessages,
37
+ registerFeeds,
38
+ listenForUpdates,
39
+ feeds: {}
35
40
  });
36
41
  const addToastMessage = (message) => CourierToastDatastore.shared.addMessage(message);
37
42
  const removeToastMessage = (message) => CourierToastDatastore.shared.removeMessage(message);
@@ -48,7 +53,8 @@ const useCourier = () => {
48
53
  onMessageAdd: () => refreshInbox(),
49
54
  onMessageRemove: () => refreshInbox(),
50
55
  onMessageUpdate: () => refreshInbox(),
51
- onUnreadCountChange: () => refreshInbox()
56
+ onUnreadCountChange: () => refreshInbox(),
57
+ onTotalUnreadCountChange: () => refreshInbox()
52
58
  });
53
59
  CourierInboxDatastore.shared.addDataStoreListener(inboxListener);
54
60
  const toastListener = new CourierToastDatastoreListener({
@@ -77,6 +83,7 @@ const useCourier = () => {
77
83
  };
78
84
  const refreshInbox = (error) => {
79
85
  const datastore = CourierInboxDatastore.shared;
86
+ const allDatasets = datastore.getDatasets();
80
87
  setInbox({
81
88
  load: loadInbox,
82
89
  fetchNextPageOfMessages,
@@ -88,9 +95,10 @@ const useCourier = () => {
88
95
  openMessage,
89
96
  unarchiveMessage,
90
97
  readAllMessages,
91
- inbox: datastore.inboxDataSet,
92
- archive: datastore.archiveDataSet,
93
- unreadCount: datastore.unreadCount,
98
+ registerFeeds,
99
+ listenForUpdates,
100
+ feeds: allDatasets,
101
+ totalUnreadCount: datastore.totalUnreadCount,
94
102
  error
95
103
  });
96
104
  };
@@ -129,6 +137,7 @@ const CourierInboxComponent = forwardRef((props, ref) => {
129
137
  }
130
138
  const inboxRef = useRef(null);
131
139
  const [elementReady, setElementReady] = useState(false);
140
+ const feedsSetRef = useRef(false);
132
141
  function handleRef(el) {
133
142
  if (ref) {
134
143
  if (typeof ref === "function") {
@@ -220,11 +229,12 @@ const CourierInboxComponent = forwardRef((props, ref) => {
220
229
  }, [props.renderPaginationItem, elementReady]);
221
230
  useEffect(() => {
222
231
  const inbox = getEl();
223
- if (!inbox) return;
232
+ if (!inbox || !props.feeds || feedsSetRef.current) return;
233
+ feedsSetRef.current = true;
224
234
  queueMicrotask(() => {
225
- inbox.setFeedType(props.feedType || "inbox");
235
+ inbox.setFeeds(props.feeds);
226
236
  });
227
- }, [props.feedType, elementReady]);
237
+ }, [props.feeds, elementReady]);
228
238
  const children = (
229
239
  /* @ts-ignore */
230
240
  /* @__PURE__ */ jsx(
@@ -248,6 +258,7 @@ const CourierInboxPopupMenuComponent = forwardRef(
248
258
  }
249
259
  const inboxRef = useRef(null);
250
260
  const [elementReady, setElementReady] = useState(false);
261
+ const feedsSetRef = useRef(false);
251
262
  function handleRef(el) {
252
263
  if (ref) {
253
264
  if (typeof ref === "function") {
@@ -262,18 +273,6 @@ const CourierInboxPopupMenuComponent = forwardRef(
262
273
  function getEl() {
263
274
  return inboxRef.current;
264
275
  }
265
- const lastFeedTypeRef = useRef(void 0);
266
- useEffect(() => {
267
- const menu = getEl();
268
- if (!menu) return;
269
- if (props.feedType !== lastFeedTypeRef.current) {
270
- lastFeedTypeRef.current = props.feedType;
271
- queueMicrotask(() => {
272
- var _a;
273
- (_a = menu.setFeedType) == null ? void 0 : _a.call(menu, props.feedType ?? "inbox");
274
- });
275
- }
276
- }, [props.feedType, elementReady]);
277
276
  useEffect(() => {
278
277
  const menu = getEl();
279
278
  if (!menu) return;
@@ -359,6 +358,14 @@ const CourierInboxPopupMenuComponent = forwardRef(
359
358
  });
360
359
  });
361
360
  }, [props.renderMenuButton, elementReady]);
361
+ useEffect(() => {
362
+ const menu = getEl();
363
+ if (!menu || !props.feeds || feedsSetRef.current) return;
364
+ feedsSetRef.current = true;
365
+ queueMicrotask(() => {
366
+ menu.setFeeds(props.feeds);
367
+ });
368
+ }, [props.feeds, elementReady]);
362
369
  const children = (
363
370
  /* @ts-ignore */
364
371
  /* @__PURE__ */ jsx(
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../src/hooks/use-courier.tsx","../src/components/courier-client-component.tsx","../src/context/render-context.ts","../src/components/courier-inbox-component.tsx","../src/components/courier-inbox-popup-menu-component.tsx","../src/components/courier-toast-component.tsx"],"sourcesContent":["import React from 'react';\nimport { Courier, CourierProps, InboxMessage } from '@trycourier/courier-js';\nimport { CourierInboxDatastore, CourierInboxDataStoreListener, CourierInboxFeedType, InboxDataSet } from '@trycourier/courier-ui-inbox';\nimport { CourierToastDatastore, CourierToastDatastoreListener } from '@trycourier/courier-ui-toast';\n\ntype AuthenticationHooks = {\n userId?: string,\n signIn: (props: CourierProps) => void,\n signOut: () => void\n}\n\ntype InboxHooks = {\n load: (props?: { canUseCache: boolean }) => Promise<void>,\n fetchNextPageOfMessages: (props: { feedType: CourierInboxFeedType }) => Promise<InboxDataSet | null>,\n setPaginationLimit: (limit: number) => void,\n readMessage: (message: InboxMessage) => Promise<void>,\n unreadMessage: (message: InboxMessage) => Promise<void>,\n clickMessage: (message: InboxMessage) => Promise<void>,\n archiveMessage: (message: InboxMessage) => Promise<void>,\n openMessage: (message: InboxMessage) => Promise<void>,\n unarchiveMessage: (message: InboxMessage) => Promise<void>,\n readAllMessages: () => Promise<void>,\n inbox?: InboxDataSet,\n archive?: InboxDataSet,\n unreadCount?: number,\n error?: Error\n}\n\ntype ToastHooks = {\n addMessage: (message: InboxMessage) => void;\n removeMessage: (message: InboxMessage) => void;\n error?: Error,\n}\n\n// A hook for managing the shared state of Courier\n// If you want to use more functions, checkout the Courier JS SDK which\n// can be used directly by importing from '@trycourier/courier-js'\nexport const useCourier = () => {\n\n // Authentication Functions\n const signIn = (props: CourierProps) => Courier.shared.signIn(props);\n const signOut = () => Courier.shared.signOut();\n\n // Inbox Functions\n const loadInbox = (props?: { canUseCache: boolean }) => CourierInboxDatastore.shared.load(props);\n const fetchNextPageOfMessages = (props: { feedType: CourierInboxFeedType }) => CourierInboxDatastore.shared.fetchNextPageOfMessages(props);\n const setPaginationLimit = (limit: number) => Courier.shared.paginationLimit = limit;\n const readMessage = (message: InboxMessage) => CourierInboxDatastore.shared.readMessage({ message });\n const unreadMessage = (message: InboxMessage) => CourierInboxDatastore.shared.unreadMessage({ message });\n const clickMessage = (message: InboxMessage) => CourierInboxDatastore.shared.clickMessage({ message });\n const archiveMessage = (message: InboxMessage) => CourierInboxDatastore.shared.archiveMessage({ message });\n const openMessage = (message: InboxMessage) => CourierInboxDatastore.shared.openMessage({ message });\n const unarchiveMessage = (message: InboxMessage) => CourierInboxDatastore.shared.unarchiveMessage({ message });\n const readAllMessages = () => CourierInboxDatastore.shared.readAllMessages();\n\n // State\n const [auth, setAuth] = React.useState<AuthenticationHooks>({\n userId: undefined,\n signIn,\n signOut\n });\n\n const [inbox, setInbox] = React.useState<InboxHooks>({\n load: loadInbox,\n fetchNextPageOfMessages,\n setPaginationLimit,\n readMessage,\n unreadMessage,\n clickMessage,\n archiveMessage,\n openMessage,\n unarchiveMessage,\n readAllMessages\n });\n\n const addToastMessage = (message: InboxMessage) => CourierToastDatastore.shared.addMessage(message);\n const removeToastMessage = (message: InboxMessage) => CourierToastDatastore.shared.removeMessage(message);\n\n const [toast, setToast] = React.useState<ToastHooks>({\n addMessage: addToastMessage,\n removeMessage: removeToastMessage,\n });\n\n React.useEffect(() => {\n\n // Add a listener to the Courier instance\n const listener = Courier.shared.addAuthenticationListener(() => refreshAuth());\n\n // Add inbox data store listener\n const inboxListener = new CourierInboxDataStoreListener({\n onError: (error: Error) => refreshInbox(error),\n onDataSetChange: () => refreshInbox(),\n onPageAdded: () => refreshInbox(),\n onMessageAdd: () => refreshInbox(),\n onMessageRemove: () => refreshInbox(),\n onMessageUpdate: () => refreshInbox(),\n onUnreadCountChange: () => refreshInbox()\n });\n CourierInboxDatastore.shared.addDataStoreListener(inboxListener);\n\n const toastListener = new CourierToastDatastoreListener({\n onMessageAdd: () => refreshToast(),\n onMessageRemove: () => refreshToast(),\n onError: (error: Error) => refreshToast(error),\n });\n CourierToastDatastore.shared.addDatastoreListener(toastListener);\n\n // Set initial values\n refreshAuth();\n refreshInbox();\n refreshToast();\n\n // Remove listeners when the component unmounts\n return () => {\n listener.remove();\n inboxListener.remove();\n toastListener.remove();\n };\n }, []);\n\n const refreshAuth = () => {\n const options = Courier.shared.client?.options;\n setAuth({\n userId: options?.userId,\n signIn,\n signOut\n });\n }\n\n const refreshInbox = (error?: Error) => {\n const datastore = CourierInboxDatastore.shared;\n setInbox({\n load: loadInbox,\n fetchNextPageOfMessages,\n setPaginationLimit,\n readMessage,\n unreadMessage,\n clickMessage,\n archiveMessage,\n openMessage,\n unarchiveMessage,\n readAllMessages,\n inbox: datastore.inboxDataSet,\n archive: datastore.archiveDataSet,\n unreadCount: datastore.unreadCount,\n error: error,\n });\n }\n\n const refreshToast = (error?: Error) => {\n setToast({\n addMessage: addToastMessage,\n removeMessage: removeToastMessage,\n error,\n });\n };\n\n return {\n shared: Courier.shared,\n auth: auth,\n inbox: inbox,\n toast: toast,\n };\n};\n","import React, { useState, useEffect } from 'react';\n\ninterface CourierClientProps {\n children: React.ReactNode;\n}\n\n// This class prevents issues with server side rendering react components\n// It will force the component to only render client side\n// A future update could support server side rendering if there is enough demand\nexport const CourierClientComponent: React.FC<CourierClientProps> = ({ children }) => {\n const [isMounted, setIsMounted] = useState(false);\n\n useEffect(() => {\n setIsMounted(true);\n }, []);\n\n // During SSR, render nothing or fallback\n if (typeof window === 'undefined') {\n return null;\n }\n\n if (!isMounted) {\n return null;\n }\n\n return <>{children}</>;\n};","import { createContext, ReactNode } from \"react\";\n\ntype RenderFn = (node: ReactNode) => HTMLElement;\n\n/**\n * Context providing a function to render a React component.\n *\n * Courier's React package renders as follows:\n *\n * - React engine (client application)\n * - Courier React components\n * - Courier web components\n * - [Optional] User-provided React components (ex. a list item)\n *\n * By default, React will not render the user-provided React components within Courier's\n * web components. We instead manually render the user-provided React components and inject\n * them into the Courier web components.\n *\n * Client rendering changed between React 17 and 18, so the SDKs provide React version-specific\n * rendering functions. See\n * https://18.react.dev/blog/2022/03/08/react-18-upgrade-guide#updates-to-client-rendering-apis.\n */\nexport const CourierRenderContext = createContext<RenderFn | null>(null);\n","import { useRef, useEffect, forwardRef, ReactNode, useContext, useState } from \"react\";\nimport { CourierInboxListItemActionFactoryProps, CourierInboxListItemFactoryProps, CourierInboxTheme, CourierInbox as CourierInboxElement, CourierInboxHeaderFactoryProps, CourierInboxStateEmptyFactoryProps, CourierInboxStateLoadingFactoryProps, CourierInboxStateErrorFactoryProps, CourierInboxPaginationItemFactoryProps, CourierInboxFeedType } from \"@trycourier/courier-ui-inbox\";\nimport { CourierComponentThemeMode } from \"@trycourier/courier-ui-core\";\nimport { CourierClientComponent } from \"./courier-client-component\";\nimport { CourierRenderContext } from \"../context/render-context\";\n\nexport interface CourierInboxProps {\n /** Height of the inbox container. Defaults to \"auto\" and will resize itself based on it's children. */\n height?: string;\n\n /** Theme object for light mode */\n lightTheme?: CourierInboxTheme;\n\n /** Theme object for dark mode */\n darkTheme?: CourierInboxTheme;\n\n /** Theme mode: \"light\", \"dark\", or \"system\". Defaults to \"system\" */\n mode?: CourierComponentThemeMode;\n\n /** Type of feed to display in the inbox (\"inbox\" or \"archive\"). Defaults to \"inbox\" */\n feedType?: CourierInboxFeedType;\n\n /** Callback fired when a message is clicked. */\n onMessageClick?: (props: CourierInboxListItemFactoryProps) => void;\n\n /** Callback fired when a message action (e.g., button) is clicked. */\n onMessageActionClick?: (props: CourierInboxListItemActionFactoryProps) => void;\n\n /** Callback fired when a message is long-pressed (for mobile/gesture support). Only works on devices that support touch. */\n onMessageLongPress?: (props: CourierInboxListItemFactoryProps) => void;\n\n /** Allows you to pass a custom component as the header. */\n renderHeader?: (props: CourierInboxHeaderFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the list item. */\n renderListItem?: (props: CourierInboxListItemFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the empty state. */\n renderEmptyState?: (props: CourierInboxStateEmptyFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the loading state. */\n renderLoadingState?: (props: CourierInboxStateLoadingFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the error state. */\n renderErrorState?: (props: CourierInboxStateErrorFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the pagination list item. */\n renderPaginationItem?: (props: CourierInboxPaginationItemFactoryProps | undefined | null) => ReactNode;\n}\n\nexport const CourierInboxComponent = forwardRef<CourierInboxElement, CourierInboxProps>((props, ref) => {\n const render = useContext(CourierRenderContext);\n if (!render) {\n throw new Error(\"RenderContext not found. Ensure CourierInbox is wrapped in a CourierRenderContext.\");\n }\n\n // Element ref for use in effects, updated by handleRef.\n const inboxRef = useRef<CourierInboxElement | null>(null);\n const [elementReady, setElementReady] = useState(false);\n\n // Callback ref passed to rendered component, used to propagate the DOM element's ref to the parent component.\n // We use a callback ref (rather than a React.RefObject) since we want the parent ref to be up-to-date with\n // rendered component. Updating the parent ref via useEffect does not work, since mutating a RefObject\n // does not trigger useEffect (see https://stackoverflow.com/a/60476525).\n function handleRef(el: CourierInboxElement | null) {\n if (ref) {\n\n // Propagate ref to ref callback functions\n if (typeof ref === 'function') {\n ref(el);\n } else {\n // Propagate ref to ref objects\n // @ts-ignore - RefObject.current is readonly in React 17, however it's not frozen and is equivalent the widened type MutableRefObject\n (ref as React.RefObject<CourierInboxElement | null>).current = el;\n }\n }\n\n // Store the element for use in effects\n inboxRef.current = el;\n\n // Update element ready state\n setElementReady(!!el);\n }\n\n // Helper to get the current element\n function getEl(): CourierInboxElement | null {\n return inboxRef.current;\n }\n\n // Handle message click\n useEffect(() => {\n const inbox = getEl();\n if (!inbox) return;\n inbox.onMessageClick(props.onMessageClick);\n }, [props.onMessageClick, elementReady]);\n\n // Handle message action click\n useEffect(() => {\n const inbox = getEl();\n if (!inbox) return;\n inbox.onMessageActionClick(props.onMessageActionClick);\n }, [props.onMessageActionClick, elementReady]);\n\n // Handle message long press\n useEffect(() => {\n const inbox = getEl();\n if (!inbox) return;\n inbox.onMessageLongPress(props.onMessageLongPress);\n }, [props.onMessageLongPress, elementReady]);\n\n // Render header\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderHeader) return;\n queueMicrotask(() => {\n inbox.setHeader((headerProps?: CourierInboxHeaderFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderHeader!(headerProps);\n return render(reactNode);\n });\n });\n }, [props.renderHeader, elementReady]);\n\n // Render list item\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderListItem) return;\n queueMicrotask(() => {\n inbox.setListItem((itemProps?: CourierInboxListItemFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderListItem!(itemProps);\n return render(reactNode);\n });\n });\n }, [props.renderListItem, elementReady]);\n\n // Render empty state\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderEmptyState) return;\n queueMicrotask(() => {\n inbox.setEmptyState((emptyStateProps?: CourierInboxStateEmptyFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderEmptyState!(emptyStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderEmptyState, elementReady]);\n\n // Render loading state\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderLoadingState) return;\n queueMicrotask(() => {\n inbox.setLoadingState((loadingStateProps?: CourierInboxStateLoadingFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderLoadingState!(loadingStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderLoadingState, elementReady]);\n\n // Render error state\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderErrorState) return;\n queueMicrotask(() => {\n inbox.setErrorState((errorStateProps?: CourierInboxStateErrorFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderErrorState!(errorStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderErrorState, elementReady]);\n\n // Render pagination item\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderPaginationItem) return;\n queueMicrotask(() => {\n inbox.setPaginationItem((paginationProps?: CourierInboxPaginationItemFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderPaginationItem!(paginationProps);\n return render(reactNode);\n });\n });\n }, [props.renderPaginationItem, elementReady]);\n\n // Set feed type\n useEffect(() => {\n const inbox = getEl();\n if (!inbox) return;\n queueMicrotask(() => {\n inbox.setFeedType(props.feedType || 'inbox');\n });\n }, [props.feedType, elementReady]);\n\n const children = (\n /* @ts-ignore */\n <courier-inbox\n ref={handleRef}\n height={props.height}\n light-theme={props.lightTheme ? JSON.stringify(props.lightTheme) : undefined}\n dark-theme={props.darkTheme ? JSON.stringify(props.darkTheme) : undefined}\n mode={props.mode}\n />\n );\n\n return (\n <CourierClientComponent children={children} />\n );\n});\n","import { useEffect, useRef, forwardRef, ReactNode, useContext, useState } from 'react';\nimport {\n CourierInboxFeedType,\n CourierInboxHeaderFactoryProps,\n CourierInboxListItemActionFactoryProps,\n CourierInboxListItemFactoryProps,\n CourierInboxMenuButtonFactoryProps,\n CourierInboxPopupMenu as CourierInboxPopupMenuElement,\n CourierInboxPaginationItemFactoryProps,\n CourierInboxPopupAlignment,\n CourierInboxStateEmptyFactoryProps,\n CourierInboxStateErrorFactoryProps,\n CourierInboxStateLoadingFactoryProps,\n CourierInboxTheme,\n} from '@trycourier/courier-ui-inbox';\nimport { CourierComponentThemeMode } from '@trycourier/courier-ui-core';\nimport { CourierClientComponent } from './courier-client-component';\nimport { CourierRenderContext } from '../context/render-context';\n\nexport interface CourierInboxPopupMenuProps {\n /** Alignment of the popup menu: 'top-right', 'top-left', 'top-center', 'bottom-right', 'bottom-left', 'bottom-center', 'center-right', 'center-left', 'center-center'. */\n popupAlignment?: CourierInboxPopupAlignment;\n\n /** Width of the popup menu container. */\n popupWidth?: string;\n\n /** Height of the popup menu container. */\n popupHeight?: string;\n\n /** CSS left position for the popup menu. */\n left?: string;\n\n /** CSS top position for the popup menu. */\n top?: string;\n\n /** CSS right position for the popup menu. */\n right?: string;\n\n /** CSS bottom position for the popup menu. */\n bottom?: string;\n\n /** Theme object for light mode. */\n lightTheme?: CourierInboxTheme;\n\n /** Theme object for dark mode. */\n darkTheme?: CourierInboxTheme;\n\n /** Theme mode: 'light', 'dark', or 'system'. */\n mode?: CourierComponentThemeMode;\n\n /** Type of feed to display in the popup menu ('inbox' or 'archive'). */\n feedType?: CourierInboxFeedType;\n\n /** Callback fired when a message is clicked. */\n onMessageClick?: (props: CourierInboxListItemFactoryProps) => void;\n\n /** Callback fired when a message action (e.g., button) is clicked. */\n onMessageActionClick?: (props: CourierInboxListItemActionFactoryProps) => void;\n\n /** Callback fired when a message is long-pressed (for mobile/gesture support). */\n onMessageLongPress?: (props: CourierInboxListItemFactoryProps) => void;\n\n /** Allows you to pass a custom component as the header. */\n renderHeader?: (props: CourierInboxHeaderFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the list item. */\n renderListItem?: (props: CourierInboxListItemFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the empty state. */\n renderEmptyState?: (props: CourierInboxStateEmptyFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the loading state. */\n renderLoadingState?: (props: CourierInboxStateLoadingFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the error state. */\n renderErrorState?: (props: CourierInboxStateErrorFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the pagination list item. */\n renderPaginationItem?: (props: CourierInboxPaginationItemFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the menu button. */\n renderMenuButton?: (props: CourierInboxMenuButtonFactoryProps | undefined | null) => ReactNode;\n}\n\nexport const CourierInboxPopupMenuComponent = forwardRef<CourierInboxPopupMenuElement, CourierInboxPopupMenuProps>(\n (props, ref) => {\n const render = useContext(CourierRenderContext);\n if (!render) {\n throw new Error(\"RenderContext not found. Ensure CourierInboxPopupMenu is wrapped in a CourierRenderContext.\");\n }\n\n // Element ref for use in effects, updated by handleRef.\n const inboxRef = useRef<CourierInboxPopupMenuElement | null>(null);\n const [elementReady, setElementReady] = useState(false);\n\n // Callback ref passed to rendered component, used to propagate the DOM element's ref to the parent component.\n // We use a callback ref (rather than a React.RefObject) since we want the parent ref to be up-to-date with\n // rendered component. Updating the parent ref via useEffect does not work, since mutating a RefObject\n // does not trigger useEffect (see https://stackoverflow.com/a/60476525).\n function handleRef(el: CourierInboxPopupMenuElement | null) {\n if (ref) {\n if (typeof ref === 'function') {\n ref(el);\n } else {\n // @ts-ignore - RefObject.current is readonly in React 17, however it's not frozen and is equivalent the widened type MutableRefObject\n (ref as React.RefObject<CourierInboxPopupMenuElement | null>).current = el;\n }\n }\n\n // Store the element for use in effects\n inboxRef.current = el;\n\n // Update element ready state\n setElementReady(!!el);\n }\n\n // Helper to get the current element\n function getEl(): CourierInboxPopupMenuElement | null {\n return inboxRef.current;\n }\n\n // Use a ref to track the last set feedType to prevent duplicate state changes\n const lastFeedTypeRef = useRef<CourierInboxFeedType | undefined>(undefined);\n\n useEffect(() => {\n const menu = getEl();\n if (!menu) return;\n // Only set feedType if it has changed from the last set value\n if (props.feedType !== lastFeedTypeRef.current) {\n lastFeedTypeRef.current = props.feedType;\n queueMicrotask(() => {\n menu.setFeedType?.(props.feedType ?? 'inbox');\n });\n }\n }, [props.feedType, elementReady]);\n\n // Handle message click\n useEffect(() => {\n const menu = getEl();\n if (!menu) return;\n menu.onMessageClick(props.onMessageClick);\n }, [props.onMessageClick, elementReady]);\n\n // Handle message action click\n useEffect(() => {\n const menu = getEl();\n if (!menu) return;\n menu.onMessageActionClick(props.onMessageActionClick);\n }, [props.onMessageActionClick, elementReady]);\n\n // Handle message long press\n useEffect(() => {\n const menu = getEl();\n if (!menu) return;\n menu.onMessageLongPress(props.onMessageLongPress);\n }, [props.onMessageLongPress, elementReady]);\n\n // Render header\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderHeader) return;\n queueMicrotask(() => {\n menu.setHeader((headerProps?: CourierInboxHeaderFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderHeader!(headerProps);\n return render(reactNode);\n });\n });\n }, [props.renderHeader, elementReady]);\n\n // Render list item\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderListItem) return;\n queueMicrotask(() => {\n menu.setListItem((itemProps?: CourierInboxListItemFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderListItem!(itemProps);\n return render(reactNode);\n });\n });\n }, [props.renderListItem, elementReady]);\n\n // Render empty state\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderEmptyState) return;\n queueMicrotask(() => {\n menu.setEmptyState((emptyStateProps?: CourierInboxStateEmptyFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderEmptyState!(emptyStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderEmptyState, elementReady]);\n\n // Render loading state\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderLoadingState) return;\n queueMicrotask(() => {\n menu.setLoadingState((loadingStateProps?: CourierInboxStateLoadingFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderLoadingState!(loadingStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderLoadingState, elementReady]);\n\n // Render error state\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderErrorState) return;\n queueMicrotask(() => {\n menu.setErrorState((errorStateProps?: CourierInboxStateErrorFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderErrorState!(errorStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderErrorState, elementReady]);\n\n // Render pagination item\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderPaginationItem) return;\n queueMicrotask(() => {\n menu.setPaginationItem((paginationProps?: CourierInboxPaginationItemFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderPaginationItem!(paginationProps);\n return render(reactNode);\n });\n });\n }, [props.renderPaginationItem, elementReady]);\n\n // Render menu button\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderMenuButton) return;\n queueMicrotask(() => {\n menu.setMenuButton((buttonProps?: CourierInboxMenuButtonFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderMenuButton!(buttonProps);\n return render(reactNode);\n });\n });\n }, [props.renderMenuButton, elementReady]);\n\n const children = (\n /* @ts-ignore */\n <courier-inbox-popup-menu\n ref={handleRef}\n popup-alignment={props.popupAlignment}\n popup-width={props.popupWidth}\n popup-height={props.popupHeight}\n left={props.left}\n top={props.top}\n right={props.right}\n bottom={props.bottom}\n light-theme={props.lightTheme ? JSON.stringify(props.lightTheme) : undefined}\n dark-theme={props.darkTheme ? JSON.stringify(props.darkTheme) : undefined}\n mode={props.mode}\n />\n );\n\n return (\n <CourierClientComponent children={children} />\n );\n }\n);\n","import { useRef, useEffect, forwardRef, ReactNode, useContext, CSSProperties, useState } from \"react\";\nimport { CourierToastTheme, CourierToast as CourierToastElement, CourierToastItemFactoryProps } from \"@trycourier/courier-ui-toast\";\nimport { CourierComponentThemeMode } from \"@trycourier/courier-ui-core\";\nimport { CourierClientComponent } from \"./courier-client-component\";\nimport { CourierRenderContext } from \"../context/render-context\";\nimport { CourierToastDismissButtonOption, CourierToastItemClickEvent, CourierToastItemActionClickEvent } from \"@trycourier/courier-ui-toast\";\n\n/** Props that may be passed to the CourierToast component. */\nexport interface CourierToastProps {\n /**\n * Styles applied to the CourierToast component.\n *\n * By default, the component has the following styles:\n *\n * ```css\n * position: \"fixed\";\n * width: \"380px\";\n * top: \"30px\";\n * right: \"30px\";\n * z-index: 999;\n * ```\n *\n * Setting styles directly on the component is useful to customize the component's\n * position and layout. Setting `height` is effectively a no-op, as `height`\n * will be dynamically set by the component as toast items are added and removed.\n */\n style?: CSSProperties;\n\n /** Theme object used to render the component when light mode is used. */\n lightTheme?: CourierToastTheme;\n\n /** Theme object used to render the component when dark mode is used. */\n darkTheme?: CourierToastTheme;\n\n /** Manually set the theme mode to one of \"light\", \"dark\", or \"system\". Defaults to \"system\". */\n mode?: CourierComponentThemeMode;\n\n /** Enable toasts to auto-dismiss, including a timer bar at the top of the toast. Defaults to false. */\n autoDismiss?: boolean;\n\n /**\n * The timeout before a toast auto-dismisses, if {@link CourierToastProps.autoDismiss} is enabled.\n * Defaults to 5000ms.\n */\n autoDismissTimeoutMs?: number;\n\n /**\n * Set the dismiss button's visibility.\n *\n * Defaults to \"auto\", which makes the button always visible if `autoDismiss` is false\n * and visible on hover if `autoDismiss` is true.\n */\n dismissButton?: CourierToastDismissButtonOption;\n\n /** Callback function invoked when a toast item is clicked. */\n onToastItemClick?: (props: CourierToastItemClickEvent) => void;\n\n /** Callback function invoked when a toast item action button is clicked. */\n onToastItemActionClick?: (props: CourierToastItemActionClickEvent) => void;\n\n /**\n * Callback function invoked when the component is ready to receive messages.\n *\n * Use onReady to ensure CourierToast has applied event listeners and\n * render props passed to the component before toasts are presented.\n *\n * @example\n * ```tsx\n * const [toastReady, setToastReady] = useState(false);\n * const courier = useCourier();\n *\n * useEffect(() => {\n * if (toastReady) {\n * courier.shared.signIn({ userId, jwt });\n * }\n * }, [toastReady]);\n *\n * return <CourierToast onReady={setToastReady} renderToastItem={myCustomItem} />\n * ```\n */\n onReady?: (ready: boolean) => void;\n\n /** Render prop specifying how to render an entire toast item. */\n renderToastItem?: (props: CourierToastItemFactoryProps) => ReactNode;\n\n /**\n * Render prop specifying how to render a toast item's content.\n *\n * The toast item's container, including the stack, auto-dismiss timer, and dismiss button\n * are still present when this prop is set.\n *\n * See {@link CourierToastProps.dismissButton} to customize the dismiss button's visibility and\n * {@link CourierToastProps.renderToastItem} to customize the entire toast item, including\n * its container.\n */\n renderToastItemContent?: (props: CourierToastItemFactoryProps) => ReactNode;\n}\n\nexport const CourierToastComponent = forwardRef<CourierToastElement, CourierToastProps>((props, ref) => {\n const render = useContext(CourierRenderContext);\n if (!render) {\n throw new Error(\"RenderContext not found. Ensure CourierToast is wrapped in a CourierRenderContext.\");\n }\n\n // Track ready state for each of the useEffects that is called for a prop set on CourierToastComponent\n // which must be translated into an imperative call on <courier-toast>.\n // When all the steps are complete, props.onReady is called to indicate the component is ready to receive toasts.\n const [setupSteps, setSetupSteps] = useState({\n elementMounted: false,\n onItemClickSet: false,\n onItemActionClickSet: false,\n renderToastItemSet: false,\n renderToastItemContentSet: false\n });\n const [elementReady, setElementReady] = useState(false);\n\n // Element ref for use in effects, updated by handleRef.\n const toastRef = useRef<CourierToastElement | null>(null);\n\n // Callback ref passed to rendered component, used to propagate the DOM element's ref to the parent component.\n // We use a callback ref (rather than a React.RefObject) since we want the parent ref to be up-to-date with\n // rendered component. Updating the parent ref via useEffect does not work, since mutating a RefObject\n // does not trigger useEffect (see https://stackoverflow.com/a/60476525).\n function handleRef(el: CourierToastElement | null) {\n if (ref) {\n\n // Propagate ref to ref callback functions\n if (typeof ref === 'function') {\n ref(el);\n } else {\n // Propagate ref to ref objects\n // @ts-ignore - RefObject.current is readonly in React 17, however it's not frozen and is equivalent the widened type MutableRefObject\n (ref as React.RefObject<CourierToastElement | null>).current = el;\n }\n }\n\n // Store the element for use in effects\n toastRef.current = el;\n\n // Update element ready state\n setElementReady(!!el);\n }\n\n // Helper to get the current element\n function getEl(): CourierToastElement | null {\n return toastRef.current;\n }\n\n // Check if all setup steps are complete and fire onReady\n useEffect(() => {\n const allStepsComplete = Object.values(setupSteps).every(step => step);\n if (allStepsComplete && props.onReady) {\n props.onReady(true);\n }\n }, [setupSteps, props.onReady]);\n\n // Track when element is mounted\n useEffect(() => {\n if (elementReady) {\n setSetupSteps(prev => ({ ...prev, elementMounted: true }));\n }\n }, [elementReady]);\n\n // Handle toast item click\n useEffect(() => {\n const toast = getEl();\n if (!toast) return;\n toast.onToastItemClick(props.onToastItemClick);\n setSetupSteps(prev => ({ ...prev, onItemClickSet: true }));\n }, [props.onToastItemClick, elementReady]);\n\n // Handle toast item action click\n useEffect(() => {\n const toast = getEl();\n if (!toast) return;\n toast.onToastItemActionClick(props.onToastItemActionClick);\n setSetupSteps(prev => ({ ...prev, onItemActionClickSet: true }));\n }, [props.onToastItemActionClick, elementReady]);\n\n // Render toast item\n useEffect(() => {\n const toast = getEl();\n if (!toast || !props.renderToastItem) {\n setSetupSteps(prev => ({ ...prev, renderToastItemSet: true }));\n return;\n }\n\n queueMicrotask(() => {\n toast.setToastItem((itemProps: CourierToastItemFactoryProps): HTMLElement => {\n const reactNode = props.renderToastItem!(itemProps);\n return render(reactNode);\n });\n });\n setSetupSteps(prev => ({ ...prev, renderToastItemSet: true }));\n\n }, [props.renderToastItem, elementReady]);\n\n // Render toast item content\n useEffect(() => {\n const toast = getEl();\n if (!toast || !props.renderToastItemContent) {\n setSetupSteps(prev => ({ ...prev, renderToastItemContentSet: true }));\n return;\n }\n queueMicrotask(() => {\n toast.setToastItemContent((itemProps: CourierToastItemFactoryProps): HTMLElement => {\n const reactNode = props.renderToastItemContent!(itemProps);\n return render(reactNode);\n });\n setSetupSteps(prev => ({ ...prev, renderToastItemContentSet: true }));\n });\n }, [props.renderToastItemContent, elementReady]);\n\n const children = (\n /* @ts-ignore */\n <courier-toast\n ref={handleRef}\n style={props.style}\n light-theme={props.lightTheme ? JSON.stringify(props.lightTheme) : undefined}\n dark-theme={props.darkTheme ? JSON.stringify(props.darkTheme) : undefined}\n mode={props.mode}\n auto-dismiss={props.autoDismiss}\n auto-dismiss-timeout-ms={props.autoDismissTimeoutMs}\n dismiss-button={props.dismissButton}\n />\n );\n\n return (\n <CourierClientComponent children={children} />\n );\n});\n"],"names":[],"mappings":";;;;;AAqCO,MAAM,aAAa,MAAM;AAG9B,QAAM,SAAS,CAAC,UAAwB,QAAQ,OAAO,OAAO,KAAK;AACnE,QAAM,UAAU,MAAM,QAAQ,OAAO,QAAA;AAGrC,QAAM,YAAY,CAAC,UAAqC,sBAAsB,OAAO,KAAK,KAAK;AAC/F,QAAM,0BAA0B,CAAC,UAA8C,sBAAsB,OAAO,wBAAwB,KAAK;AACzI,QAAM,qBAAqB,CAAC,UAAkB,QAAQ,OAAO,kBAAkB;AAC/E,QAAM,cAAc,CAAC,YAA0B,sBAAsB,OAAO,YAAY,EAAE,SAAS;AACnG,QAAM,gBAAgB,CAAC,YAA0B,sBAAsB,OAAO,cAAc,EAAE,SAAS;AACvG,QAAM,eAAe,CAAC,YAA0B,sBAAsB,OAAO,aAAa,EAAE,SAAS;AACrG,QAAM,iBAAiB,CAAC,YAA0B,sBAAsB,OAAO,eAAe,EAAE,SAAS;AACzG,QAAM,cAAc,CAAC,YAA0B,sBAAsB,OAAO,YAAY,EAAE,SAAS;AACnG,QAAM,mBAAmB,CAAC,YAA0B,sBAAsB,OAAO,iBAAiB,EAAE,SAAS;AAC7G,QAAM,kBAAkB,MAAM,sBAAsB,OAAO,gBAAA;AAG3D,QAAM,CAAC,MAAM,OAAO,IAAI,MAAM,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nB,YAAM,oBAAoB,CAAC,cAAyD;AAClF,cAAM,YAAY,MAAM,uBAAwB,SAAS;AACzD,eAAO,OAAO,SAAS;AAAA,MACzB,CAAC;AACD,oBAAc,WAAS,EAAE,GAAG,MAAM,2BAA2B,OAAO;AAAA,IACtE,CAAC;AAAA,EACH,GAAG,CAAC,MAAM,wBAAwB,YAAY,CAAC;AAE/C,QAAM;AAAA;AAAA,IAEJ;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,KAAK;AAAA,QACL,OAAO,MAAM;AAAA,QACb,eAAa,MAAM,aAAa,KAAK,UAAU,MAAM,UAAU,IAAI;AAAA,QACnE,cAAY,MAAM,YAAY,KAAK,UAAU,MAAM,SAAS,IAAI;AAAA,QAChE,MAAM,MAAM;AAAA,QACZ,gBAAc,MAAM;AAAA,QACpB,2BAAyB,MAAM;AAAA,QAC/B,kBAAgB,MAAM;AAAA,MAAA;AAAA,IAAA;AAAA;AAI1B,SACE,oBAAC,0BAAuB,UAAoB;AAEhD,CAAC;"}
1
+ {"version":3,"file":"index.mjs","sources":["../src/hooks/use-courier.tsx","../src/components/courier-client-component.tsx","../src/context/render-context.ts","../src/components/courier-inbox-component.tsx","../src/components/courier-inbox-popup-menu-component.tsx","../src/components/courier-toast-component.tsx"],"sourcesContent":["import React from 'react';\nimport { Courier, CourierProps, InboxMessage } from '@trycourier/courier-js';\nimport { CourierInboxDatastore, CourierInboxDataStoreListener, InboxDataSet, CourierInboxFeed } from '@trycourier/courier-ui-inbox';\nimport { CourierToastDatastore, CourierToastDatastoreListener } from '@trycourier/courier-ui-toast';\n\ntype AuthenticationHooks = {\n userId?: string,\n signIn: (props: CourierProps) => void,\n signOut: () => void\n}\n\ntype InboxHooks = {\n load: (props?: { canUseCache: boolean }) => Promise<void>,\n fetchNextPageOfMessages: (props: { datasetId: string }) => Promise<InboxDataSet | null>,\n setPaginationLimit: (limit: number) => void,\n readMessage: (message: InboxMessage) => Promise<void>,\n unreadMessage: (message: InboxMessage) => Promise<void>,\n clickMessage: (message: InboxMessage) => Promise<void>,\n archiveMessage: (message: InboxMessage) => Promise<void>,\n openMessage: (message: InboxMessage) => Promise<void>,\n unarchiveMessage: (message: InboxMessage) => Promise<void>,\n readAllMessages: () => Promise<void>,\n registerFeeds: (feeds: CourierInboxFeed[]) => void,\n listenForUpdates: () => Promise<void>,\n feeds: Record<string, InboxDataSet>,\n totalUnreadCount?: number,\n error?: Error\n}\n\ntype ToastHooks = {\n addMessage: (message: InboxMessage) => void;\n removeMessage: (message: InboxMessage) => void;\n error?: Error,\n}\n\n// A hook for managing the shared state of Courier\n// If you want to use more functions, checkout the Courier JS SDK which\n// can be used directly by importing from '@trycourier/courier-js'\nexport const useCourier = () => {\n\n // Authentication Functions\n const signIn = (props: CourierProps) => Courier.shared.signIn(props);\n const signOut = () => Courier.shared.signOut();\n\n // Inbox Functions\n const loadInbox = (props?: { canUseCache: boolean }) => CourierInboxDatastore.shared.load(props);\n const fetchNextPageOfMessages = (props: { datasetId: string }) => CourierInboxDatastore.shared.fetchNextPageOfMessages(props);\n const setPaginationLimit = (limit: number) => Courier.shared.paginationLimit = limit;\n const readMessage = (message: InboxMessage) => CourierInboxDatastore.shared.readMessage({ message });\n const unreadMessage = (message: InboxMessage) => CourierInboxDatastore.shared.unreadMessage({ message });\n const clickMessage = (message: InboxMessage) => CourierInboxDatastore.shared.clickMessage({ message });\n const archiveMessage = (message: InboxMessage) => CourierInboxDatastore.shared.archiveMessage({ message });\n const openMessage = (message: InboxMessage) => CourierInboxDatastore.shared.openMessage({ message });\n const unarchiveMessage = (message: InboxMessage) => CourierInboxDatastore.shared.unarchiveMessage({ message });\n const readAllMessages = () => CourierInboxDatastore.shared.readAllMessages();\n const registerFeeds = (feeds: CourierInboxFeed[]) => CourierInboxDatastore.shared.registerFeeds(feeds);\n const listenForUpdates = () => CourierInboxDatastore.shared.listenForUpdates();\n\n // State\n const [auth, setAuth] = React.useState<AuthenticationHooks>({\n userId: undefined,\n signIn,\n signOut\n });\n\n const [inbox, setInbox] = React.useState<InboxHooks>({\n load: loadInbox,\n fetchNextPageOfMessages,\n setPaginationLimit,\n readMessage,\n unreadMessage,\n clickMessage,\n archiveMessage,\n openMessage,\n unarchiveMessage,\n readAllMessages,\n registerFeeds,\n listenForUpdates,\n feeds: {}\n });\n\n const addToastMessage = (message: InboxMessage) => CourierToastDatastore.shared.addMessage(message);\n const removeToastMessage = (message: InboxMessage) => CourierToastDatastore.shared.removeMessage(message);\n\n const [toast, setToast] = React.useState<ToastHooks>({\n addMessage: addToastMessage,\n removeMessage: removeToastMessage,\n });\n\n React.useEffect(() => {\n\n // Add a listener to the Courier instance\n const listener = Courier.shared.addAuthenticationListener(() => refreshAuth());\n\n // Add inbox data store listener\n const inboxListener = new CourierInboxDataStoreListener({\n onError: (error: Error) => refreshInbox(error),\n onDataSetChange: () => refreshInbox(),\n onPageAdded: () => refreshInbox(),\n onMessageAdd: () => refreshInbox(),\n onMessageRemove: () => refreshInbox(),\n onMessageUpdate: () => refreshInbox(),\n onUnreadCountChange: () => refreshInbox(),\n onTotalUnreadCountChange: () => refreshInbox()\n });\n CourierInboxDatastore.shared.addDataStoreListener(inboxListener);\n\n const toastListener = new CourierToastDatastoreListener({\n onMessageAdd: () => refreshToast(),\n onMessageRemove: () => refreshToast(),\n onError: (error: Error) => refreshToast(error),\n });\n CourierToastDatastore.shared.addDatastoreListener(toastListener);\n\n // Set initial values\n refreshAuth();\n refreshInbox();\n refreshToast();\n\n // Remove listeners when the component unmounts\n return () => {\n listener.remove();\n inboxListener.remove();\n toastListener.remove();\n };\n }, []);\n\n const refreshAuth = () => {\n const options = Courier.shared.client?.options;\n setAuth({\n userId: options?.userId,\n signIn,\n signOut\n });\n }\n\n const refreshInbox = (error?: Error) => {\n const datastore = CourierInboxDatastore.shared;\n const allDatasets = datastore.getDatasets();\n setInbox({\n load: loadInbox,\n fetchNextPageOfMessages,\n setPaginationLimit,\n readMessage,\n unreadMessage,\n clickMessage,\n archiveMessage,\n openMessage,\n unarchiveMessage,\n readAllMessages,\n registerFeeds,\n listenForUpdates,\n feeds: allDatasets,\n totalUnreadCount: datastore.totalUnreadCount,\n error: error,\n });\n }\n\n const refreshToast = (error?: Error) => {\n setToast({\n addMessage: addToastMessage,\n removeMessage: removeToastMessage,\n error,\n });\n };\n\n return {\n shared: Courier.shared,\n auth: auth,\n inbox: inbox,\n toast: toast,\n };\n};\n","import React, { useState, useEffect } from 'react';\n\ninterface CourierClientProps {\n children: React.ReactNode;\n}\n\n// This class prevents issues with server side rendering react components\n// It will force the component to only render client side\n// A future update could support server side rendering if there is enough demand\nexport const CourierClientComponent: React.FC<CourierClientProps> = ({ children }) => {\n const [isMounted, setIsMounted] = useState(false);\n\n useEffect(() => {\n setIsMounted(true);\n }, []);\n\n // During SSR, render nothing or fallback\n if (typeof window === 'undefined') {\n return null;\n }\n\n if (!isMounted) {\n return null;\n }\n\n return <>{children}</>;\n};","import { createContext, ReactNode } from \"react\";\n\ntype RenderFn = (node: ReactNode) => HTMLElement;\n\n/**\n * Context providing a function to render a React component.\n *\n * Courier's React package renders as follows:\n *\n * - React engine (client application)\n * - Courier React components\n * - Courier web components\n * - [Optional] User-provided React components (ex. a list item)\n *\n * By default, React will not render the user-provided React components within Courier's\n * web components. We instead manually render the user-provided React components and inject\n * them into the Courier web components.\n *\n * Client rendering changed between React 17 and 18, so the SDKs provide React version-specific\n * rendering functions. See\n * https://18.react.dev/blog/2022/03/08/react-18-upgrade-guide#updates-to-client-rendering-apis.\n */\nexport const CourierRenderContext = createContext<RenderFn | null>(null);\n","import { useRef, useEffect, forwardRef, ReactNode, useContext, useState } from \"react\";\nimport { CourierInboxListItemActionFactoryProps, CourierInboxListItemFactoryProps, CourierInboxTheme, CourierInbox as CourierInboxElement, CourierInboxHeaderFactoryProps, CourierInboxStateEmptyFactoryProps, CourierInboxStateLoadingFactoryProps, CourierInboxStateErrorFactoryProps, CourierInboxPaginationItemFactoryProps, CourierInboxFeed } from \"@trycourier/courier-ui-inbox\";\nimport { CourierComponentThemeMode } from \"@trycourier/courier-ui-core\";\nimport { CourierClientComponent } from \"./courier-client-component\";\nimport { CourierRenderContext } from \"../context/render-context\";\n\nexport interface CourierInboxProps {\n /** Height of the inbox container. Defaults to \"auto\" and will resize itself based on it's children. */\n height?: string;\n\n /** Theme object for light mode */\n lightTheme?: CourierInboxTheme;\n\n /** Theme object for dark mode */\n darkTheme?: CourierInboxTheme;\n\n /** Theme mode: \"light\", \"dark\", or \"system\". Defaults to \"system\" */\n mode?: CourierComponentThemeMode;\n\n /** Type of feed to display in the inbox. Defaults to \"inbox\" */\n feedType?: string;\n\n /** Array of feeds to display in the inbox. Each feed contains tabs with different filters. */\n feeds?: CourierInboxFeed[];\n\n /** Callback fired when a message is clicked. */\n onMessageClick?: (props: CourierInboxListItemFactoryProps) => void;\n\n /** Callback fired when a message action (e.g., button) is clicked. */\n onMessageActionClick?: (props: CourierInboxListItemActionFactoryProps) => void;\n\n /** Callback fired when a message is long-pressed (for mobile/gesture support). Only works on devices that support touch. */\n onMessageLongPress?: (props: CourierInboxListItemFactoryProps) => void;\n\n /** Allows you to pass a custom component as the header. */\n renderHeader?: (props: CourierInboxHeaderFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the list item. */\n renderListItem?: (props: CourierInboxListItemFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the empty state. */\n renderEmptyState?: (props: CourierInboxStateEmptyFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the loading state. */\n renderLoadingState?: (props: CourierInboxStateLoadingFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the error state. */\n renderErrorState?: (props: CourierInboxStateErrorFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the pagination list item. */\n renderPaginationItem?: (props: CourierInboxPaginationItemFactoryProps | undefined | null) => ReactNode;\n}\n\nexport const CourierInboxComponent = forwardRef<CourierInboxElement, CourierInboxProps>((props, ref) => {\n const render = useContext(CourierRenderContext);\n if (!render) {\n throw new Error(\"RenderContext not found. Ensure CourierInbox is wrapped in a CourierRenderContext.\");\n }\n\n // Element ref for use in effects, updated by handleRef.\n const inboxRef = useRef<CourierInboxElement | null>(null);\n const [elementReady, setElementReady] = useState(false);\n const feedsSetRef = useRef(false);\n\n // Callback ref passed to rendered component, used to propagate the DOM element's ref to the parent component.\n // We use a callback ref (rather than a React.RefObject) since we want the parent ref to be up-to-date with\n // rendered component. Updating the parent ref via useEffect does not work, since mutating a RefObject\n // does not trigger useEffect (see https://stackoverflow.com/a/60476525).\n function handleRef(el: CourierInboxElement | null) {\n if (ref) {\n\n // Propagate ref to ref callback functions\n if (typeof ref === 'function') {\n ref(el);\n } else {\n // Propagate ref to ref objects\n // @ts-ignore - RefObject.current is readonly in React 17, however it's not frozen and is equivalent the widened type MutableRefObject\n (ref as React.RefObject<CourierInboxElement | null>).current = el;\n }\n }\n\n // Store the element for use in effects\n inboxRef.current = el;\n\n // Update element ready state\n setElementReady(!!el);\n }\n\n // Helper to get the current element\n function getEl(): CourierInboxElement | null {\n return inboxRef.current;\n }\n\n // Handle message click\n useEffect(() => {\n const inbox = getEl();\n if (!inbox) return;\n inbox.onMessageClick(props.onMessageClick);\n }, [props.onMessageClick, elementReady]);\n\n // Handle message action click\n useEffect(() => {\n const inbox = getEl();\n if (!inbox) return;\n inbox.onMessageActionClick(props.onMessageActionClick);\n }, [props.onMessageActionClick, elementReady]);\n\n // Handle message long press\n useEffect(() => {\n const inbox = getEl();\n if (!inbox) return;\n inbox.onMessageLongPress(props.onMessageLongPress);\n }, [props.onMessageLongPress, elementReady]);\n\n // Render header\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderHeader) return;\n queueMicrotask(() => {\n inbox.setHeader((headerProps?: CourierInboxHeaderFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderHeader!(headerProps);\n return render(reactNode);\n });\n });\n }, [props.renderHeader, elementReady]);\n\n // Render list item\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderListItem) return;\n queueMicrotask(() => {\n inbox.setListItem((itemProps?: CourierInboxListItemFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderListItem!(itemProps);\n return render(reactNode);\n });\n });\n }, [props.renderListItem, elementReady]);\n\n // Render empty state\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderEmptyState) return;\n queueMicrotask(() => {\n inbox.setEmptyState((emptyStateProps?: CourierInboxStateEmptyFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderEmptyState!(emptyStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderEmptyState, elementReady]);\n\n // Render loading state\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderLoadingState) return;\n queueMicrotask(() => {\n inbox.setLoadingState((loadingStateProps?: CourierInboxStateLoadingFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderLoadingState!(loadingStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderLoadingState, elementReady]);\n\n // Render error state\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderErrorState) return;\n queueMicrotask(() => {\n inbox.setErrorState((errorStateProps?: CourierInboxStateErrorFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderErrorState!(errorStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderErrorState, elementReady]);\n\n // Render pagination item\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderPaginationItem) return;\n queueMicrotask(() => {\n inbox.setPaginationItem((paginationProps?: CourierInboxPaginationItemFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderPaginationItem!(paginationProps);\n return render(reactNode);\n });\n });\n }, [props.renderPaginationItem, elementReady]);\n\n // Set feeds (only once when element is ready)\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.feeds || feedsSetRef.current) return;\n feedsSetRef.current = true;\n queueMicrotask(() => {\n inbox.setFeeds(props.feeds!);\n });\n }, [props.feeds, elementReady]);\n\n const children = (\n /* @ts-ignore */\n <courier-inbox\n ref={handleRef}\n height={props.height}\n light-theme={props.lightTheme ? JSON.stringify(props.lightTheme) : undefined}\n dark-theme={props.darkTheme ? JSON.stringify(props.darkTheme) : undefined}\n mode={props.mode}\n />\n );\n\n return (\n <CourierClientComponent children={children} />\n );\n});\n","import { useEffect, useRef, forwardRef, ReactNode, useContext, useState } from 'react';\nimport {\n CourierInboxHeaderFactoryProps,\n CourierInboxListItemActionFactoryProps,\n CourierInboxListItemFactoryProps,\n CourierInboxMenuButtonFactoryProps,\n CourierInboxPopupMenu as CourierInboxPopupMenuElement,\n CourierInboxPaginationItemFactoryProps,\n CourierInboxPopupAlignment,\n CourierInboxStateEmptyFactoryProps,\n CourierInboxStateErrorFactoryProps,\n CourierInboxStateLoadingFactoryProps,\n CourierInboxTheme,\n CourierInboxFeed,\n} from '@trycourier/courier-ui-inbox';\nimport { CourierComponentThemeMode } from '@trycourier/courier-ui-core';\nimport { CourierClientComponent } from './courier-client-component';\nimport { CourierRenderContext } from '../context/render-context';\n\nexport interface CourierInboxPopupMenuProps {\n /** Alignment of the popup menu: 'top-right', 'top-left', 'top-center', 'bottom-right', 'bottom-left', 'bottom-center', 'center-right', 'center-left', 'center-center'. */\n popupAlignment?: CourierInboxPopupAlignment;\n\n /** Width of the popup menu container. */\n popupWidth?: string;\n\n /** Height of the popup menu container. */\n popupHeight?: string;\n\n /** CSS left position for the popup menu. */\n left?: string;\n\n /** CSS top position for the popup menu. */\n top?: string;\n\n /** CSS right position for the popup menu. */\n right?: string;\n\n /** CSS bottom position for the popup menu. */\n bottom?: string;\n\n /** Theme object for light mode. */\n lightTheme?: CourierInboxTheme;\n\n /** Theme object for dark mode. */\n darkTheme?: CourierInboxTheme;\n\n /** Theme mode: 'light', 'dark', or 'system'. */\n mode?: CourierComponentThemeMode;\n\n /** Array of feeds to display in the inbox. Each feed contains tabs with different filters. */\n feeds?: CourierInboxFeed[];\n\n /** Callback fired when a message is clicked. */\n onMessageClick?: (props: CourierInboxListItemFactoryProps) => void;\n\n /** Callback fired when a message action (e.g., button) is clicked. */\n onMessageActionClick?: (props: CourierInboxListItemActionFactoryProps) => void;\n\n /** Callback fired when a message is long-pressed (for mobile/gesture support). */\n onMessageLongPress?: (props: CourierInboxListItemFactoryProps) => void;\n\n /** Allows you to pass a custom component as the header. */\n renderHeader?: (props: CourierInboxHeaderFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the list item. */\n renderListItem?: (props: CourierInboxListItemFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the empty state. */\n renderEmptyState?: (props: CourierInboxStateEmptyFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the loading state. */\n renderLoadingState?: (props: CourierInboxStateLoadingFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the error state. */\n renderErrorState?: (props: CourierInboxStateErrorFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the pagination list item. */\n renderPaginationItem?: (props: CourierInboxPaginationItemFactoryProps | undefined | null) => ReactNode;\n\n /** Allows you to pass a custom component as the menu button. */\n renderMenuButton?: (props: CourierInboxMenuButtonFactoryProps | undefined | null) => ReactNode;\n}\n\nexport const CourierInboxPopupMenuComponent = forwardRef<CourierInboxPopupMenuElement, CourierInboxPopupMenuProps>(\n (props, ref) => {\n const render = useContext(CourierRenderContext);\n if (!render) {\n throw new Error(\"RenderContext not found. Ensure CourierInboxPopupMenu is wrapped in a CourierRenderContext.\");\n }\n\n // Element ref for use in effects, updated by handleRef.\n const inboxRef = useRef<CourierInboxPopupMenuElement | null>(null);\n const [elementReady, setElementReady] = useState(false);\n const feedsSetRef = useRef(false);\n\n // Callback ref passed to rendered component, used to propagate the DOM element's ref to the parent component.\n // We use a callback ref (rather than a React.RefObject) since we want the parent ref to be up-to-date with\n // rendered component. Updating the parent ref via useEffect does not work, since mutating a RefObject\n // does not trigger useEffect (see https://stackoverflow.com/a/60476525).\n function handleRef(el: CourierInboxPopupMenuElement | null) {\n if (ref) {\n if (typeof ref === 'function') {\n ref(el);\n } else {\n // @ts-ignore - RefObject.current is readonly in React 17, however it's not frozen and is equivalent the widened type MutableRefObject\n (ref as React.RefObject<CourierInboxPopupMenuElement | null>).current = el;\n }\n }\n\n // Store the element for use in effects\n inboxRef.current = el;\n\n // Update element ready state\n setElementReady(!!el);\n }\n\n // Helper to get the current element\n function getEl(): CourierInboxPopupMenuElement | null {\n return inboxRef.current;\n }\n\n // Handle message click\n useEffect(() => {\n const menu = getEl();\n if (!menu) return;\n menu.onMessageClick(props.onMessageClick);\n }, [props.onMessageClick, elementReady]);\n\n // Handle message action click\n useEffect(() => {\n const menu = getEl();\n if (!menu) return;\n menu.onMessageActionClick(props.onMessageActionClick);\n }, [props.onMessageActionClick, elementReady]);\n\n // Handle message long press\n useEffect(() => {\n const menu = getEl();\n if (!menu) return;\n menu.onMessageLongPress(props.onMessageLongPress);\n }, [props.onMessageLongPress, elementReady]);\n\n // Render header\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderHeader) return;\n queueMicrotask(() => {\n menu.setHeader((headerProps?: CourierInboxHeaderFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderHeader!(headerProps);\n return render(reactNode);\n });\n });\n }, [props.renderHeader, elementReady]);\n\n // Render list item\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderListItem) return;\n queueMicrotask(() => {\n menu.setListItem((itemProps?: CourierInboxListItemFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderListItem!(itemProps);\n return render(reactNode);\n });\n });\n }, [props.renderListItem, elementReady]);\n\n // Render empty state\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderEmptyState) return;\n queueMicrotask(() => {\n menu.setEmptyState((emptyStateProps?: CourierInboxStateEmptyFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderEmptyState!(emptyStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderEmptyState, elementReady]);\n\n // Render loading state\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderLoadingState) return;\n queueMicrotask(() => {\n menu.setLoadingState((loadingStateProps?: CourierInboxStateLoadingFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderLoadingState!(loadingStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderLoadingState, elementReady]);\n\n // Render error state\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderErrorState) return;\n queueMicrotask(() => {\n menu.setErrorState((errorStateProps?: CourierInboxStateErrorFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderErrorState!(errorStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderErrorState, elementReady]);\n\n // Render pagination item\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderPaginationItem) return;\n queueMicrotask(() => {\n menu.setPaginationItem((paginationProps?: CourierInboxPaginationItemFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderPaginationItem!(paginationProps);\n return render(reactNode);\n });\n });\n }, [props.renderPaginationItem, elementReady]);\n\n // Render menu button\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderMenuButton) return;\n queueMicrotask(() => {\n menu.setMenuButton((buttonProps?: CourierInboxMenuButtonFactoryProps | undefined | null): HTMLElement => {\n const reactNode = props.renderMenuButton!(buttonProps);\n return render(reactNode);\n });\n });\n }, [props.renderMenuButton, elementReady]);\n\n // Set feeds (only once when element is ready)\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.feeds || feedsSetRef.current) return;\n feedsSetRef.current = true;\n queueMicrotask(() => {\n menu.setFeeds(props.feeds!);\n });\n }, [props.feeds, elementReady]);\n\n const children = (\n /* @ts-ignore */\n <courier-inbox-popup-menu\n ref={handleRef}\n popup-alignment={props.popupAlignment}\n popup-width={props.popupWidth}\n popup-height={props.popupHeight}\n left={props.left}\n top={props.top}\n right={props.right}\n bottom={props.bottom}\n light-theme={props.lightTheme ? JSON.stringify(props.lightTheme) : undefined}\n dark-theme={props.darkTheme ? JSON.stringify(props.darkTheme) : undefined}\n mode={props.mode}\n />\n );\n\n return (\n <CourierClientComponent children={children} />\n );\n }\n);\n","import { useRef, useEffect, forwardRef, ReactNode, useContext, CSSProperties, useState } from \"react\";\nimport { CourierToastTheme, CourierToast as CourierToastElement, CourierToastItemFactoryProps } from \"@trycourier/courier-ui-toast\";\nimport { CourierComponentThemeMode } from \"@trycourier/courier-ui-core\";\nimport { CourierClientComponent } from \"./courier-client-component\";\nimport { CourierRenderContext } from \"../context/render-context\";\nimport { CourierToastDismissButtonOption, CourierToastItemClickEvent, CourierToastItemActionClickEvent } from \"@trycourier/courier-ui-toast\";\n\n/** Props that may be passed to the CourierToast component. */\nexport interface CourierToastProps {\n /**\n * Styles applied to the CourierToast component.\n *\n * By default, the component has the following styles:\n *\n * ```css\n * position: \"fixed\";\n * width: \"380px\";\n * top: \"30px\";\n * right: \"30px\";\n * z-index: 999;\n * ```\n *\n * Setting styles directly on the component is useful to customize the component's\n * position and layout. Setting `height` is effectively a no-op, as `height`\n * will be dynamically set by the component as toast items are added and removed.\n */\n style?: CSSProperties;\n\n /** Theme object used to render the component when light mode is used. */\n lightTheme?: CourierToastTheme;\n\n /** Theme object used to render the component when dark mode is used. */\n darkTheme?: CourierToastTheme;\n\n /** Manually set the theme mode to one of \"light\", \"dark\", or \"system\". Defaults to \"system\". */\n mode?: CourierComponentThemeMode;\n\n /** Enable toasts to auto-dismiss, including a timer bar at the top of the toast. Defaults to false. */\n autoDismiss?: boolean;\n\n /**\n * The timeout before a toast auto-dismisses, if {@link CourierToastProps.autoDismiss} is enabled.\n * Defaults to 5000ms.\n */\n autoDismissTimeoutMs?: number;\n\n /**\n * Set the dismiss button's visibility.\n *\n * Defaults to \"auto\", which makes the button always visible if `autoDismiss` is false\n * and visible on hover if `autoDismiss` is true.\n */\n dismissButton?: CourierToastDismissButtonOption;\n\n /** Callback function invoked when a toast item is clicked. */\n onToastItemClick?: (props: CourierToastItemClickEvent) => void;\n\n /** Callback function invoked when a toast item action button is clicked. */\n onToastItemActionClick?: (props: CourierToastItemActionClickEvent) => void;\n\n /**\n * Callback function invoked when the component is ready to receive messages.\n *\n * Use onReady to ensure CourierToast has applied event listeners and\n * render props passed to the component before toasts are presented.\n *\n * @example\n * ```tsx\n * const [toastReady, setToastReady] = useState(false);\n * const courier = useCourier();\n *\n * useEffect(() => {\n * if (toastReady) {\n * courier.shared.signIn({ userId, jwt });\n * }\n * }, [toastReady]);\n *\n * return <CourierToast onReady={setToastReady} renderToastItem={myCustomItem} />\n * ```\n */\n onReady?: (ready: boolean) => void;\n\n /** Render prop specifying how to render an entire toast item. */\n renderToastItem?: (props: CourierToastItemFactoryProps) => ReactNode;\n\n /**\n * Render prop specifying how to render a toast item's content.\n *\n * The toast item's container, including the stack, auto-dismiss timer, and dismiss button\n * are still present when this prop is set.\n *\n * See {@link CourierToastProps.dismissButton} to customize the dismiss button's visibility and\n * {@link CourierToastProps.renderToastItem} to customize the entire toast item, including\n * its container.\n */\n renderToastItemContent?: (props: CourierToastItemFactoryProps) => ReactNode;\n}\n\nexport const CourierToastComponent = forwardRef<CourierToastElement, CourierToastProps>((props, ref) => {\n const render = useContext(CourierRenderContext);\n if (!render) {\n throw new Error(\"RenderContext not found. Ensure CourierToast is wrapped in a CourierRenderContext.\");\n }\n\n // Track ready state for each of the useEffects that is called for a prop set on CourierToastComponent\n // which must be translated into an imperative call on <courier-toast>.\n // When all the steps are complete, props.onReady is called to indicate the component is ready to receive toasts.\n const [setupSteps, setSetupSteps] = useState({\n elementMounted: false,\n onItemClickSet: false,\n onItemActionClickSet: false,\n renderToastItemSet: false,\n renderToastItemContentSet: false\n });\n const [elementReady, setElementReady] = useState(false);\n\n // Element ref for use in effects, updated by handleRef.\n const toastRef = useRef<CourierToastElement | null>(null);\n\n // Callback ref passed to rendered component, used to propagate the DOM element's ref to the parent component.\n // We use a callback ref (rather than a React.RefObject) since we want the parent ref to be up-to-date with\n // rendered component. Updating the parent ref via useEffect does not work, since mutating a RefObject\n // does not trigger useEffect (see https://stackoverflow.com/a/60476525).\n function handleRef(el: CourierToastElement | null) {\n if (ref) {\n\n // Propagate ref to ref callback functions\n if (typeof ref === 'function') {\n ref(el);\n } else {\n // Propagate ref to ref objects\n // @ts-ignore - RefObject.current is readonly in React 17, however it's not frozen and is equivalent the widened type MutableRefObject\n (ref as React.RefObject<CourierToastElement | null>).current = el;\n }\n }\n\n // Store the element for use in effects\n toastRef.current = el;\n\n // Update element ready state\n setElementReady(!!el);\n }\n\n // Helper to get the current element\n function getEl(): CourierToastElement | null {\n return toastRef.current;\n }\n\n // Check if all setup steps are complete and fire onReady\n useEffect(() => {\n const allStepsComplete = Object.values(setupSteps).every(step => step);\n if (allStepsComplete && props.onReady) {\n props.onReady(true);\n }\n }, [setupSteps, props.onReady]);\n\n // Track when element is mounted\n useEffect(() => {\n if (elementReady) {\n setSetupSteps(prev => ({ ...prev, elementMounted: true }));\n }\n }, [elementReady]);\n\n // Handle toast item click\n useEffect(() => {\n const toast = getEl();\n if (!toast) return;\n toast.onToastItemClick(props.onToastItemClick);\n setSetupSteps(prev => ({ ...prev, onItemClickSet: true }));\n }, [props.onToastItemClick, elementReady]);\n\n // Handle toast item action click\n useEffect(() => {\n const toast = getEl();\n if (!toast) return;\n toast.onToastItemActionClick(props.onToastItemActionClick);\n setSetupSteps(prev => ({ ...prev, onItemActionClickSet: true }));\n }, [props.onToastItemActionClick, elementReady]);\n\n // Render toast item\n useEffect(() => {\n const toast = getEl();\n if (!toast || !props.renderToastItem) {\n setSetupSteps(prev => ({ ...prev, renderToastItemSet: true }));\n return;\n }\n\n queueMicrotask(() => {\n toast.setToastItem((itemProps: CourierToastItemFactoryProps): HTMLElement => {\n const reactNode = props.renderToastItem!(itemProps);\n return render(reactNode);\n });\n });\n setSetupSteps(prev => ({ ...prev, renderToastItemSet: true }));\n\n }, [props.renderToastItem, elementReady]);\n\n // Render toast item content\n useEffect(() => {\n const toast = getEl();\n if (!toast || !props.renderToastItemContent) {\n setSetupSteps(prev => ({ ...prev, renderToastItemContentSet: true }));\n return;\n }\n queueMicrotask(() => {\n toast.setToastItemContent((itemProps: CourierToastItemFactoryProps): HTMLElement => {\n const reactNode = props.renderToastItemContent!(itemProps);\n return render(reactNode);\n });\n setSetupSteps(prev => ({ ...prev, renderToastItemContentSet: true }));\n });\n }, [props.renderToastItemContent, elementReady]);\n\n const children = (\n /* @ts-ignore */\n <courier-toast\n ref={handleRef}\n style={props.style}\n light-theme={props.lightTheme ? JSON.stringify(props.lightTheme) : undefined}\n dark-theme={props.darkTheme ? JSON.stringify(props.darkTheme) : undefined}\n mode={props.mode}\n auto-dismiss={props.autoDismiss}\n auto-dismiss-timeout-ms={props.autoDismissTimeoutMs}\n dismiss-button={props.dismissButton}\n />\n );\n\n return (\n <CourierClientComponent children={children} />\n );\n});\n"],"names":[],"mappings":";;;;;AAsCO,MAAM,aAAa,MAAM;AAG9B,QAAM,SAAS,CAAC,UAAwB,QAAQ,OAAO,OAAO,KAAK;AACnE,QAAM,UAAU,MAAM,QAAQ,OAAO,QAAA;AAGrC,QAAM,YAAY,CAAC,UAAqC,sBAAsB,OAAO,KAAK,KAAK;AAC/F,QAAM,0BAA0B,CAAC,UAAiC,sBAAsB,OAAO,wBAAwB,KAAK;AAC5H,QAAM,qBAAqB,CAAC,UAAkB,QAAQ,OAAO,kBAAkB;AAC/E,QAAM,cAAc,CAAC,YAA0B,sBAAsB,OAAO,YAAY,EAAE,SAAS;AACnG,QAAM,gBAAgB,CAAC,YAA0B,sBAAsB,OAAO,cAAc,EAAE,SAAS;AACvG,QAAM,eAAe,CAAC,YAA0B,sBAAsB,OAAO,aAAa,EAAE,SAAS;AACrG,QAAM,iBAAiB,CAAC,YAA0B,sBAAsB,OAAO,eAAe,EAAE,SAAS;AACzG,QAAM,cAAc,CAAC,YAA0B,sBAAsB,OAAO,YAAY,EAAE,SAAS;AACnG,QAAM,mBAAmB,CAAC,YAA0B,sBAAsB,OAAO,iBAAiB,EAAE,SAAS;AAC7G,QAAM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AAO,SAAS;AAAA,MACzB,CAAC;AAAA,IACH,CAAC;AACD,kBAAc,WAAS,EAAE,GAAG,MAAM,oBAAoB,OAAO;AAAA,EAE/D,GAAG,CAAC,MAAM,iBAAiB,YAAY,CAAC;AAGxC,YAAU,MAAM;AACd,UAAM,QAAQ,MAAA;AACd,QAAI,CAAC,SAAS,CAAC,MAAM,wBAAwB;AAC3C,oBAAc,WAAS,EAAE,GAAG,MAAM,2BAA2B,OAAO;AACpE;AAAA,IACF;AACA,mBAAe,MAAM;AACnB,YAAM,oBAAoB,CAAC,cAAyD;AAClF,cAAM,YAAY,MAAM,uBAAwB,SAAS;AACzD,eAAO,OAAO,SAAS;AAAA,MACzB,CAAC;AACD,oBAAc,WAAS,EAAE,GAAG,MAAM,2BAA2B,OAAO;AAAA,IACtE,CAAC;AAAA,EACH,GAAG,CAAC,MAAM,wBAAwB,YAAY,CAAC;AAE/C,QAAM;AAAA;AAAA,IAEJ;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,KAAK;AAAA,QACL,OAAO,MAAM;AAAA,QACb,eAAa,MAAM,aAAa,KAAK,UAAU,MAAM,UAAU,IAAI;AAAA,QACnE,cAAY,MAAM,YAAY,KAAK,UAAU,MAAM,SAAS,IAAI;AAAA,QAChE,MAAM,MAAM;AAAA,QACZ,gBAAc,MAAM;AAAA,QACpB,2BAAyB,MAAM;AAAA,QAC/B,kBAAgB,MAAM;AAAA,MAAA;AAAA,IAAA;AAAA;AAI1B,SACE,oBAAC,0BAAuB,UAAoB;AAEhD,CAAC;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trycourier/courier-react-components",
3
- "version": "1.2.4",
3
+ "version": "2.0.1",
4
4
  "description": "React components for the Courier web UI",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -23,16 +23,16 @@
23
23
  "url": "https://github.com/trycourier/courier-web"
24
24
  },
25
25
  "dependencies": {
26
- "@trycourier/courier-js": "2.1.3",
27
- "@trycourier/courier-ui-core": "1.0.14",
28
- "@trycourier/courier-ui-inbox": "1.2.3",
29
- "@trycourier/courier-ui-toast": "1.0.4"
26
+ "@trycourier/courier-js": "3.0.0",
27
+ "@trycourier/courier-ui-core": "2.0.0",
28
+ "@trycourier/courier-ui-inbox": "2.1.0",
29
+ "@trycourier/courier-ui-toast": "2.0.0"
30
30
  },
31
31
  "devDependencies": {
32
- "@trycourier/courier-js": "2.1.3",
33
- "@trycourier/courier-ui-core": "1.0.14",
34
- "@trycourier/courier-ui-inbox": "1.2.3",
35
- "@trycourier/courier-ui-toast": "1.0.4",
32
+ "@trycourier/courier-js": "3.0.0",
33
+ "@trycourier/courier-ui-core": "2.0.0",
34
+ "@trycourier/courier-ui-inbox": "2.1.0",
35
+ "@trycourier/courier-ui-toast": "2.0.0",
36
36
  "@types/react": "17.0.2",
37
37
  "@types/react-dom": "17.0.2",
38
38
  "react": "17.0.2",