@trycourier/courier-react 8.0.28 → 8.0.29-alpha.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.
package/README.md CHANGED
@@ -402,9 +402,78 @@ export default function App() {
402
402
  }
403
403
  ```
404
404
 
405
+ ### Available Hooks
406
+
407
+ ```ts
408
+ import { useCourier } from '@trycourier/courier-react';
409
+
410
+ const { auth, inbox } = useCourier();
411
+
412
+ // Sign in & Sign out
413
+ useEffect(() => {
414
+ auth.signIn({
415
+ userId: '$YOUR_USER_ID',
416
+ jwt: jwt,
417
+ });
418
+
419
+ // To sign out, call:
420
+ auth.signOut();
421
+ }, [auth]);
422
+
423
+ // Log the signed-in user
424
+ useEffect(() => {
425
+ console.log('Current Courier User: ', auth.userId);
426
+ }, [auth.userId]);
427
+
428
+ // Inbox Hooks
429
+ useEffect(() => {
430
+
431
+ // Set how many messages get fetched when getting another page
432
+ inbox.setPaginationLimit(20);
433
+
434
+ // Reload a specific dataset in the inbox
435
+ inbox.load({ feedType: 'inbox', canUseCache: true });
436
+
437
+ // Fetch the next page of messages
438
+ inbox.fetchNextPageOfMessages({ feedType: 'inbox' }).then((data) => {
439
+ if (data) {
440
+ console.log('Next page of messages:', data);
441
+ }
442
+ });
443
+
444
+ // Mark all messages as read
445
+ inbox.readAllMessages();
446
+
447
+ // Log unread count and errors
448
+ if (inbox.unreadCount !== undefined) {
449
+ console.log('Unread messages:', inbox.unreadCount);
450
+ }
451
+
452
+ if (inbox.error) {
453
+ console.error('Inbox error:', inbox.error);
454
+ }
455
+
456
+ // Log inbox and archive datasets
457
+ if (inbox.inbox) {
458
+ console.log('Inbox dataset:', inbox.inbox);
459
+ }
460
+
461
+ if (inbox.archive) {
462
+ console.log('Archive dataset:', inbox.archive);
463
+ }
464
+
465
+ }, [
466
+ inbox,
467
+ inbox.inbox,
468
+ inbox.archive,
469
+ inbox.unreadCount,
470
+ inbox.error,
471
+ ]);
472
+ ```
473
+
405
474
  > **Not using React?** We suggest you use [@trycourier/courier-ui-inbox](../courier-ui-inbox/README.md) package instead.
406
475
 
407
- # **Share feedback with Courier**
476
+ ## **Share feedback with Courier**
408
477
 
409
478
  We want to make this the best SDK for managing notifications! Have an idea or feedback about our SDKs? Let us know!
410
479
 
@@ -23,4 +23,4 @@ import { CourierInboxPopupMenuProps } from '@trycourier/courier-react-components
23
23
  * return <CourierInboxPopupMenu />;
24
24
  * ```
25
25
  */
26
- export declare const CourierInboxPopupMenu: import('../../../../node_modules/react').ForwardRefExoticComponent<CourierInboxPopupMenuProps & import('../../../../node_modules/react').RefAttributes<CourierInboxPopupMenuElement>>;
26
+ export declare const CourierInboxPopupMenu: import('react').ForwardRefExoticComponent<CourierInboxPopupMenuProps & import('react').RefAttributes<CourierInboxPopupMenuElement>>;
@@ -21,4 +21,4 @@ import { CourierInboxProps } from '@trycourier/courier-react-components';
21
21
  * return <CourierInbox />;
22
22
  * ```
23
23
  */
24
- export declare const CourierInbox: import('../../../../node_modules/react').ForwardRefExoticComponent<CourierInboxProps & import('../../../../node_modules/react').RefAttributes<CourierInboxElement>>;
24
+ export declare const CourierInbox: import('react').ForwardRefExoticComponent<CourierInboxProps & import('react').RefAttributes<CourierInboxElement>>;
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),r=require("react"),t=require("@trycourier/courier-js"),n=require("@trycourier/courier-ui-inbox"),s=require("react-dom"),o=require("react-dom/client"),a=({children:t})=>{const[n,s]=r.useState(!1);return r.useEffect((()=>{s(!0)}),[]),"undefined"==typeof window?null:n?e.jsx(e.Fragment,{children:t}):null},i=r.createContext(null),u=r.forwardRef(((t,n)=>{const s=r.useContext(i);if(!s)throw new Error("RenderContext not found. Ensure CourierInbox is wrapped in a CourierRenderContext.");const o=r.useRef(null);function u(){return o.current}r.useEffect((()=>{const e=u();e&&e.onMessageClick(t.onMessageClick)}),[t.onMessageClick]),r.useEffect((()=>{const e=u();e&&e.onMessageActionClick(t.onMessageActionClick)}),[t.onMessageActionClick]),r.useEffect((()=>{const e=u();e&&e.onMessageLongPress(t.onMessageLongPress)}),[t.onMessageLongPress]),r.useEffect((()=>{const e=u();e&&t.renderHeader&&queueMicrotask((()=>{e.setHeader((e=>{const r=t.renderHeader(e);return s(r)}))}))}),[t.renderHeader]),r.useEffect((()=>{const e=u();e&&t.renderListItem&&queueMicrotask((()=>{e.setListItem((e=>{const r=t.renderListItem(e);return s(r)}))}))}),[t.renderListItem]),r.useEffect((()=>{const e=u();e&&t.renderEmptyState&&queueMicrotask((()=>{e.setEmptyState((e=>{const r=t.renderEmptyState(e);return s(r)}))}))}),[t.renderEmptyState]),r.useEffect((()=>{const e=u();e&&t.renderLoadingState&&queueMicrotask((()=>{e.setLoadingState((e=>{const r=t.renderLoadingState(e);return s(r)}))}))}),[t.renderLoadingState]),r.useEffect((()=>{const e=u();e&&t.renderErrorState&&queueMicrotask((()=>{e.setErrorState((e=>{const r=t.renderErrorState(e);return s(r)}))}))}),[t.renderErrorState]),r.useEffect((()=>{const e=u();e&&t.renderPaginationItem&&queueMicrotask((()=>{e.setPaginationItem((e=>{const r=t.renderPaginationItem(e);return s(r)}))}))}),[t.renderPaginationItem]),r.useEffect((()=>{const e=u();e&&queueMicrotask((()=>{e.setFeedType(t.feedType||"inbox")}))}),[t.feedType]);const c=e.jsx("courier-inbox",{ref:function(e){n&&("function"==typeof n?n(e):n.current=e),o.current=e},height:t.height,"light-theme":t.lightTheme?JSON.stringify(t.lightTheme):void 0,"dark-theme":t.darkTheme?JSON.stringify(t.darkTheme):void 0,mode:t.mode});return e.jsx(a,{children:c})})),c=r.forwardRef(((t,n)=>{const s=r.useContext(i);if(!s)throw new Error("RenderContext not found. Ensure CourierInboxPopupMenu is wrapped in a CourierRenderContext.");const o=r.useRef(null);function u(){return o.current}const c=r.useRef(void 0);r.useEffect((()=>{const e=u();e&&t.feedType!==c.current&&(c.current=t.feedType,queueMicrotask((()=>{var r;null==(r=e.setFeedType)||r.call(e,t.feedType??"inbox")})))}),[t.feedType]),r.useEffect((()=>{const e=u();e&&e.onMessageClick(t.onMessageClick)}),[t.onMessageClick]),r.useEffect((()=>{const e=u();e&&e.onMessageActionClick(t.onMessageActionClick)}),[t.onMessageActionClick]),r.useEffect((()=>{const e=u();e&&e.onMessageLongPress(t.onMessageLongPress)}),[t.onMessageLongPress]),r.useEffect((()=>{const e=u();e&&t.renderHeader&&queueMicrotask((()=>{e.setHeader((e=>{const r=t.renderHeader(e);return s(r)}))}))}),[t.renderHeader]),r.useEffect((()=>{const e=u();e&&t.renderListItem&&queueMicrotask((()=>{e.setListItem((e=>{const r=t.renderListItem(e);return s(r)}))}))}),[t.renderListItem]),r.useEffect((()=>{const e=u();e&&t.renderEmptyState&&queueMicrotask((()=>{e.setEmptyState((e=>{const r=t.renderEmptyState(e);return s(r)}))}))}),[t.renderEmptyState]),r.useEffect((()=>{const e=u();e&&t.renderLoadingState&&queueMicrotask((()=>{e.setLoadingState((e=>{const r=t.renderLoadingState(e);return s(r)}))}))}),[t.renderLoadingState]),r.useEffect((()=>{const e=u();e&&t.renderErrorState&&queueMicrotask((()=>{e.setErrorState((e=>{const r=t.renderErrorState(e);return s(r)}))}))}),[t.renderErrorState]),r.useEffect((()=>{const e=u();e&&t.renderPaginationItem&&queueMicrotask((()=>{e.setPaginationItem((e=>{const r=t.renderPaginationItem(e);return s(r)}))}))}),[t.renderPaginationItem]),r.useEffect((()=>{const e=u();e&&t.renderMenuButton&&queueMicrotask((()=>{e.setMenuButton((e=>{const r=t.renderMenuButton(e);return s(r)}))}))}),[t.renderMenuButton]);const d=e.jsx("courier-inbox-popup-menu",{ref:function(e){n&&("function"==typeof n?n(e):n.current=e),o.current=e},"popup-alignment":t.popupAlignment,"popup-width":t.popupWidth,"popup-height":t.popupHeight,left:t.left,top:t.top,right:t.right,bottom:t.bottom,"light-theme":t.lightTheme?JSON.stringify(t.lightTheme):void 0,"dark-theme":t.darkTheme?JSON.stringify(t.darkTheme):void 0,mode:t.mode});return e.jsx(a,{children:d})}));function d(e){const r=document.createElement("div"),t=o.createRoot(r);s.flushSync((()=>{t.render(e)}));const n=r.firstElementChild;if(!(n instanceof HTMLElement))throw new Error("renderListItem must return a single JSX element that renders to an HTMLElement (e.g., <div>)");return n}const g=r.forwardRef(((r,t)=>e.jsx(i.Provider,{value:d,children:e.jsx(u,{...r,ref:t})})));g.displayName="CourierInbox";const f=r.forwardRef(((r,t)=>e.jsx(i.Provider,{value:d,children:e.jsx(c,{...r,ref:t})})));f.displayName="CourierInboxPopupMenu",Object.defineProperty(exports,"archiveMessage",{enumerable:!0,get:()=>n.archiveMessage}),Object.defineProperty(exports,"clickMessage",{enumerable:!0,get:()=>n.clickMessage}),Object.defineProperty(exports,"defaultDarkTheme",{enumerable:!0,get:()=>n.defaultDarkTheme}),Object.defineProperty(exports,"defaultLightTheme",{enumerable:!0,get:()=>n.defaultLightTheme}),Object.defineProperty(exports,"markAsRead",{enumerable:!0,get:()=>n.markAsRead}),Object.defineProperty(exports,"markAsUnread",{enumerable:!0,get:()=>n.markAsUnread}),Object.defineProperty(exports,"mergeTheme",{enumerable:!0,get:()=>n.mergeTheme}),Object.defineProperty(exports,"openMessage",{enumerable:!0,get:()=>n.openMessage}),exports.CourierInbox=g,exports.CourierInboxPopupMenu=f,exports.useCourier=()=>{const e=e=>t.Courier.shared.signIn(e),s=()=>t.Courier.shared.signOut(),o=e=>n.CourierInboxDatastore.shared.load(e),a=e=>n.CourierInboxDatastore.shared.fetchNextPageOfMessages(e),i=e=>t.Courier.shared.paginationLimit=e,u=e=>n.CourierInboxDatastore.shared.readMessage({message:e}),c=e=>n.CourierInboxDatastore.shared.unreadMessage({message:e}),d=e=>n.CourierInboxDatastore.shared.clickMessage({message:e}),g=e=>n.CourierInboxDatastore.shared.archiveMessage({message:e}),f=e=>n.CourierInboxDatastore.shared.openMessage({message:e}),m=e=>n.CourierInboxDatastore.shared.unarchiveMessage({message:e}),l=()=>n.CourierInboxDatastore.shared.readAllMessages(),[h,p]=r.useState({userId:void 0,signIn:e,signOut:s}),[M,x]=r.useState({load:o,fetchNextPageOfMessages:a,setPaginationLimit:i,readMessage:u,unreadMessage:c,clickMessage:d,archiveMessage:g,openMessage:f,unarchiveMessage:m,readAllMessages:l});r.useEffect((()=>{const e=t.Courier.shared.addAuthenticationListener((()=>C())),r=new n.CourierInboxDataStoreListener({onError:e=>E(e),onDataSetChange:()=>E(),onPageAdded:()=>E(),onMessageAdd:()=>E(),onMessageRemove:()=>E(),onMessageUpdate:()=>E(),onUnreadCountChange:()=>E()});return n.CourierInboxDatastore.shared.addDataStoreListener(r),C(),E(),()=>{e.remove(),r.remove()}}),[]);const C=()=>{var r;const n=null==(r=t.Courier.shared.client)?void 0:r.options;p({userId:null==n?void 0:n.userId,signIn:e,signOut:s})},E=e=>{const r=n.CourierInboxDatastore.shared;x({load:o,fetchNextPageOfMessages:a,setPaginationLimit:i,readMessage:u,unreadMessage:c,clickMessage:d,archiveMessage:g,openMessage:f,unarchiveMessage:m,readAllMessages:l,inbox:r.inboxDataSet,archive:r.archiveDataSet,unreadCount:r.unreadCount,error:e})};return{shared:t.Courier.shared,auth:h,inbox:M}};
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),r=require("react"),t=require("@trycourier/courier-react-components"),o=require("react-dom"),n=require("react-dom/client"),i=require("@trycourier/courier-ui-inbox");function u(e){const r=document.createElement("div"),t=n.createRoot(r);o.flushSync((()=>{t.render(e)}));const i=r.firstElementChild;if(!(i instanceof HTMLElement))throw new Error("renderListItem must return a single JSX element that renders to an HTMLElement (e.g., <div>)");return i}const a=r.forwardRef(((r,o)=>e.jsx(t.CourierRenderContext.Provider,{value:u,children:e.jsx(t.CourierInboxComponent,{...r,ref:o})})));a.displayName="CourierInbox";const s=r.forwardRef(((r,o)=>e.jsx(t.CourierRenderContext.Provider,{value:u,children:e.jsx(t.CourierInboxPopupMenuComponent,{...r,ref:o})})));s.displayName="CourierInboxPopupMenu",Object.defineProperty(exports,"useCourier",{enumerable:!0,get:()=>t.useCourier}),Object.defineProperty(exports,"archiveMessage",{enumerable:!0,get:()=>i.archiveMessage}),Object.defineProperty(exports,"clickMessage",{enumerable:!0,get:()=>i.clickMessage}),Object.defineProperty(exports,"defaultDarkTheme",{enumerable:!0,get:()=>i.defaultDarkTheme}),Object.defineProperty(exports,"defaultLightTheme",{enumerable:!0,get:()=>i.defaultLightTheme}),Object.defineProperty(exports,"markAsRead",{enumerable:!0,get:()=>i.markAsRead}),Object.defineProperty(exports,"markAsUnread",{enumerable:!0,get:()=>i.markAsUnread}),Object.defineProperty(exports,"mergeTheme",{enumerable:!0,get:()=>i.mergeTheme}),Object.defineProperty(exports,"openMessage",{enumerable:!0,get:()=>i.openMessage}),exports.CourierInbox=a,exports.CourierInboxPopupMenu=s;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../courier-react-components/dist/index.mjs","../src/utils/render.tsx","../src/components/courier-inbox.tsx","../src/components/courier-inbox-popup-menu.tsx"],"sourcesContent":["import { Courier } from \"@trycourier/courier-js\";\nimport { CourierInboxDatastore, CourierInboxDataStoreListener } from \"@trycourier/courier-ui-inbox\";\nimport React, { useState, useEffect, createContext, forwardRef, useContext, useRef } from \"react\";\nimport { jsx, Fragment } from \"react/jsx-runtime\";\nconst useCourier = () => {\n const signIn = (props) => Courier.shared.signIn(props);\n const signOut = () => Courier.shared.signOut();\n const loadInbox = (props) => CourierInboxDatastore.shared.load(props);\n const fetchNextPageOfMessages = (props) => CourierInboxDatastore.shared.fetchNextPageOfMessages(props);\n const setPaginationLimit = (limit) => Courier.shared.paginationLimit = limit;\n const readMessage = (message) => CourierInboxDatastore.shared.readMessage({ message });\n const unreadMessage = (message) => CourierInboxDatastore.shared.unreadMessage({ message });\n const clickMessage = (message) => CourierInboxDatastore.shared.clickMessage({ message });\n const archiveMessage = (message) => CourierInboxDatastore.shared.archiveMessage({ message });\n const openMessage = (message) => CourierInboxDatastore.shared.openMessage({ message });\n const unarchiveMessage = (message) => CourierInboxDatastore.shared.unarchiveMessage({ message });\n const readAllMessages = () => CourierInboxDatastore.shared.readAllMessages();\n const [auth, setAuth] = React.useState({\n userId: void 0,\n signIn,\n signOut\n });\n const [inbox, setInbox] = React.useState({\n load: loadInbox,\n fetchNextPageOfMessages,\n setPaginationLimit,\n readMessage,\n unreadMessage,\n clickMessage,\n archiveMessage,\n openMessage,\n unarchiveMessage,\n readAllMessages\n });\n React.useEffect(() => {\n const listener = Courier.shared.addAuthenticationListener(() => refreshAuth());\n const inboxListener = new CourierInboxDataStoreListener({\n onError: (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 refreshAuth();\n refreshInbox();\n return () => {\n listener.remove();\n inboxListener.remove();\n };\n }, []);\n const refreshAuth = () => {\n var _a;\n const options = (_a = Courier.shared.client) == null ? void 0 : _a.options;\n setAuth({\n userId: options == null ? void 0 : options.userId,\n signIn,\n signOut\n });\n };\n const refreshInbox = (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\n });\n };\n return {\n shared: Courier.shared,\n auth,\n inbox\n };\n};\nconst CourierClientComponent = ({ children }) => {\n const [isMounted, setIsMounted] = useState(false);\n useEffect(() => {\n setIsMounted(true);\n }, []);\n if (typeof window === \"undefined\") {\n return null;\n }\n if (!isMounted) {\n return null;\n }\n return /* @__PURE__ */ jsx(Fragment, { children });\n};\nconst CourierRenderContext = createContext(null);\nconst CourierInboxComponent = forwardRef((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 const inboxRef = useRef(null);\n function handleRef(el) {\n if (ref) {\n if (typeof ref === \"function\") {\n ref(el);\n } else {\n ref.current = el;\n }\n }\n inboxRef.current = el;\n }\n function getEl() {\n return inboxRef.current;\n }\n useEffect(() => {\n const inbox = getEl();\n if (!inbox) return;\n inbox.onMessageClick(props.onMessageClick);\n }, [props.onMessageClick]);\n useEffect(() => {\n const inbox = getEl();\n if (!inbox) return;\n inbox.onMessageActionClick(props.onMessageActionClick);\n }, [props.onMessageActionClick]);\n useEffect(() => {\n const inbox = getEl();\n if (!inbox) return;\n inbox.onMessageLongPress(props.onMessageLongPress);\n }, [props.onMessageLongPress]);\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderHeader) return;\n queueMicrotask(() => {\n inbox.setHeader((headerProps) => {\n const reactNode = props.renderHeader(headerProps);\n return render(reactNode);\n });\n });\n }, [props.renderHeader]);\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderListItem) return;\n queueMicrotask(() => {\n inbox.setListItem((itemProps) => {\n const reactNode = props.renderListItem(itemProps);\n return render(reactNode);\n });\n });\n }, [props.renderListItem]);\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderEmptyState) return;\n queueMicrotask(() => {\n inbox.setEmptyState((emptyStateProps) => {\n const reactNode = props.renderEmptyState(emptyStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderEmptyState]);\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderLoadingState) return;\n queueMicrotask(() => {\n inbox.setLoadingState((loadingStateProps) => {\n const reactNode = props.renderLoadingState(loadingStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderLoadingState]);\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderErrorState) return;\n queueMicrotask(() => {\n inbox.setErrorState((errorStateProps) => {\n const reactNode = props.renderErrorState(errorStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderErrorState]);\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderPaginationItem) return;\n queueMicrotask(() => {\n inbox.setPaginationItem((paginationProps) => {\n const reactNode = props.renderPaginationItem(paginationProps);\n return render(reactNode);\n });\n });\n }, [props.renderPaginationItem]);\n useEffect(() => {\n const inbox = getEl();\n if (!inbox) return;\n queueMicrotask(() => {\n inbox.setFeedType(props.feedType || \"inbox\");\n });\n }, [props.feedType]);\n const children = (\n /* @ts-ignore */\n /* @__PURE__ */ jsx(\n \"courier-inbox\",\n {\n ref: handleRef,\n height: props.height,\n \"light-theme\": props.lightTheme ? JSON.stringify(props.lightTheme) : void 0,\n \"dark-theme\": props.darkTheme ? JSON.stringify(props.darkTheme) : void 0,\n mode: props.mode\n }\n )\n );\n return /* @__PURE__ */ jsx(CourierClientComponent, { children });\n});\nconst CourierInboxPopupMenuComponent = forwardRef(\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 const inboxRef = useRef(null);\n function handleRef(el) {\n if (ref) {\n if (typeof ref === \"function\") {\n ref(el);\n } else {\n ref.current = el;\n }\n }\n inboxRef.current = el;\n }\n function getEl() {\n return inboxRef.current;\n }\n const lastFeedTypeRef = useRef(void 0);\n useEffect(() => {\n const menu = getEl();\n if (!menu) return;\n if (props.feedType !== lastFeedTypeRef.current) {\n lastFeedTypeRef.current = props.feedType;\n queueMicrotask(() => {\n var _a;\n (_a = menu.setFeedType) == null ? void 0 : _a.call(menu, props.feedType ?? \"inbox\");\n });\n }\n }, [props.feedType]);\n useEffect(() => {\n const menu = getEl();\n if (!menu) return;\n menu.onMessageClick(props.onMessageClick);\n }, [props.onMessageClick]);\n useEffect(() => {\n const menu = getEl();\n if (!menu) return;\n menu.onMessageActionClick(props.onMessageActionClick);\n }, [props.onMessageActionClick]);\n useEffect(() => {\n const menu = getEl();\n if (!menu) return;\n menu.onMessageLongPress(props.onMessageLongPress);\n }, [props.onMessageLongPress]);\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderHeader) return;\n queueMicrotask(() => {\n menu.setHeader((headerProps) => {\n const reactNode = props.renderHeader(headerProps);\n return render(reactNode);\n });\n });\n }, [props.renderHeader]);\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderListItem) return;\n queueMicrotask(() => {\n menu.setListItem((itemProps) => {\n const reactNode = props.renderListItem(itemProps);\n return render(reactNode);\n });\n });\n }, [props.renderListItem]);\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderEmptyState) return;\n queueMicrotask(() => {\n menu.setEmptyState((emptyStateProps) => {\n const reactNode = props.renderEmptyState(emptyStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderEmptyState]);\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderLoadingState) return;\n queueMicrotask(() => {\n menu.setLoadingState((loadingStateProps) => {\n const reactNode = props.renderLoadingState(loadingStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderLoadingState]);\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderErrorState) return;\n queueMicrotask(() => {\n menu.setErrorState((errorStateProps) => {\n const reactNode = props.renderErrorState(errorStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderErrorState]);\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderPaginationItem) return;\n queueMicrotask(() => {\n menu.setPaginationItem((paginationProps) => {\n const reactNode = props.renderPaginationItem(paginationProps);\n return render(reactNode);\n });\n });\n }, [props.renderPaginationItem]);\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderMenuButton) return;\n queueMicrotask(() => {\n menu.setMenuButton((buttonProps) => {\n const reactNode = props.renderMenuButton(buttonProps);\n return render(reactNode);\n });\n });\n }, [props.renderMenuButton]);\n const children = (\n /* @ts-ignore */\n /* @__PURE__ */ jsx(\n \"courier-inbox-popup-menu\",\n {\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) : void 0,\n \"dark-theme\": props.darkTheme ? JSON.stringify(props.darkTheme) : void 0,\n mode: props.mode\n }\n )\n );\n return /* @__PURE__ */ jsx(CourierClientComponent, { children });\n }\n);\nexport {\n CourierInboxComponent,\n CourierInboxPopupMenuComponent,\n CourierRenderContext,\n useCourier\n};\n//# sourceMappingURL=index.mjs.map\n","import { ReactNode } from \"react\";\nimport { flushSync } from \"react-dom\";\nimport { createRoot } from \"react-dom/client\";\n\n/**\n * Converts a React node to an HTMLElement.\n * This function uses flushSync to ensure the DOM is updated synchronously.\n * @param node - The React node to convert.\n * @returns The converted HTMLElement.\n */\nexport function reactNodeToHTMLElement(node: ReactNode): HTMLElement {\n const container = document.createElement('div');\n\n // Use React 18 root\n const root = createRoot(container);\n flushSync(() => {\n root.render(node);\n });\n\n // Wait until React mounts the content synchronously\n const element = container.firstElementChild;\n if (!(element instanceof HTMLElement)) {\n throw new Error(\n 'renderListItem must return a single JSX element that renders to an HTMLElement (e.g., <div>)'\n );\n }\n\n return element;\n}\n","import { forwardRef } from \"react\";\nimport { CourierInbox as CourierInboxElement } from \"@trycourier/courier-ui-inbox\";\nimport { CourierInboxComponent, CourierInboxProps, CourierRenderContext } from \"@trycourier/courier-react-components\";\nimport { reactNodeToHTMLElement } from \"../utils/render\";\n\n/**\n * CourierInbox React component.\n *\n * @example\n * ```tsx\n * const courier = useCourier();\n *\n * useEffect(() => {\n * // Generate a JWT for your user (do this on your backend server)\n * const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'; // Replace with actual JWT\n *\n * // Authenticate the user with the inbox\n * courier.shared.signIn({\n * userId: $YOUR_USER_ID,\n * jwt: jwt,\n * });\n * }, []);\n *\n * return <CourierInbox />;\n * ```\n */\nexport const CourierInbox = forwardRef<CourierInboxElement, CourierInboxProps>((props, ref) => {\n return (\n <CourierRenderContext.Provider value={reactNodeToHTMLElement}>\n <CourierInboxComponent {...props} ref={ref} />\n </CourierRenderContext.Provider>\n );\n});\n\nCourierInbox.displayName = 'CourierInbox';\n","import { forwardRef } from \"react\";\nimport { CourierInboxPopupMenu as CourierInboxPopupMenuElement } from \"@trycourier/courier-ui-inbox\";\nimport { CourierInboxPopupMenuComponent, CourierInboxPopupMenuProps, CourierRenderContext } from \"@trycourier/courier-react-components\";\nimport { reactNodeToHTMLElement } from \"../utils/render\";\n\n/**\n * CourierInboxPopupMenu React component.\n *\n * This component is used to display a popup menu for a message in the inbox.\n *\n * @example\n * ```tsx\n * const courier = useCourier();\n *\n * useEffect(() => {\n * // Generate a JWT for your user (do this on your backend server)\n * const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'; // Replace with actual JWT\n *\n * // Authenticate the user with the inbox\n * courier.shared.signIn({\n * userId: $YOUR_USER_ID,\n * jwt: jwt,\n * });\n * }, []);\n *\n * return <CourierInboxPopupMenu />;\n * ```\n */\nexport const CourierInboxPopupMenu = forwardRef<CourierInboxPopupMenuElement, CourierInboxPopupMenuProps>((props, ref) => {\n return (\n <CourierRenderContext.Provider value={reactNodeToHTMLElement}>\n <CourierInboxPopupMenuComponent {...props} ref={ref} />\n </CourierRenderContext.Provider>\n );\n});\n\nCourierInboxPopupMenu.displayName = 'CourierInboxPopupMenu';\n"],"names":["CourierClientComponent","children","isMounted","setIsMounted","useState","useEffect","window","Fragment","CourierRenderContext","createContext","CourierInboxComponent","forwardRef","props","ref","render","useContext","Error","inboxRef","useRef","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","reactNodeToHTMLElement","node","container","document","createElement","root","createRoot","flushSync","element","firstElementChild","HTMLElement","CourierInbox","Provider","value","displayName","CourierInboxPopupMenu","signIn","Courier","shared","signOut","loadInbox","CourierInboxDatastore","load","fetchNextPageOfMessages","setPaginationLimit","limit","paginationLimit","readMessage","message","unreadMessage","clickMessage","archiveMessage","openMessage","unarchiveMessage","readAllMessages","auth","setAuth","React","userId","setInbox","listener","addAuthenticationListener","refreshAuth","inboxListener","CourierInboxDataStoreListener","onError","error","refreshInbox","onDataSetChange","onPageAdded","onMessageAdd","onMessageRemove","onMessageUpdate","onUnreadCountChange","addDataStoreListener","remove","options","client","datastore","inboxDataSet","archive","archiveDataSet","unreadCount"],"mappings":"2QAuFMA,EAAyB,EAAGC,eAChC,MAAOC,EAAWC,GAAgBC,EAAAA,UAAS,GAI3C,OAHAC,EAAAA,WAAU,KACRF,GAAa,EAAI,GAChB,IACmB,oBAAXG,OACF,KAEJJ,QAGsBK,EAAAA,SAAU,CAAEN,aAF9B,IAEwC,EAE7CO,EAAuBC,EAAAA,cAAc,MACrCC,EAAwBC,EAAAA,YAAW,CAACC,EAAOC,KAC/C,MAAMC,EAASC,EAAAA,WAAWP,GAC1B,IAAKM,EACH,MAAM,IAAIE,MAAM,sFAElB,MAAMC,EAAWC,EAAAA,OAAO,MAWxB,SAASC,IACP,OAAOF,EAASG,OAClB,CACAf,EAAAA,WAAU,KACR,MAAMgB,EAAQF,IACTE,GACLA,EAAMC,eAAeV,EAAMU,eAAc,GACxC,CAACV,EAAMU,iBACVjB,EAAAA,W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MAC1DC,EAAgB,IAAIC,gCAA8B,CACtDC,QAAUC,GAAUC,EAAaD,GACjCE,gBAAiB,IAAMD,IACvBE,YAAa,IAAMF,IACnBG,aAAc,IAAMH,IACpBI,gBAAiB,IAAMJ,IACvBK,gBAAiB,IAAML,IACvBM,oBAAqB,IAAMN,MAK7B,OAHA1B,wBAAsBH,OAAOoC,qBAAqBX,GAClDD,IACAK,IACO,KACLP,EAASe,SACTZ,EAAcY,QAAM,CACtB,GACC,IACH,MAAMb,EAAc,KAClB,IAAItD,EACJ,MAAMoE,EAA0C,OAA/BpE,EAAK6B,UAAQC,OAAOuC,aAAkB,EAASrE,EAAGoE,QACnEpB,EAAQ,CACNE,OAAmB,MAAXkB,OAAkB,EAASA,EAAQlB,OAC3CtB,SACAG,WACD,EAEG4B,EAAgBD,IACpB,MAAMY,EAAYrC,EAAAA,sBAAsBH,OACxCqB,EAAS,CACPjB,KAAMF,EACNG,0BACAC,qBACAG,cACAE,gBACAC,eACAC,iBACAC,cACAC,mBACAC,kBACAnF,MAAO2G,EAAUC,aACjBC,QAASF,EAAUG,eACnBC,YAAaJ,EAAUI,YACvBhB,SACD,EAEH,MAAO,CACL5B,OAAQD,EAAAA,QAAQC,OAChBiB,OACApF,QACJ"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/utils/render.tsx","../src/components/courier-inbox.tsx","../src/components/courier-inbox-popup-menu.tsx"],"sourcesContent":["import { ReactNode } from \"react\";\nimport { flushSync } from \"react-dom\";\nimport { createRoot } from \"react-dom/client\";\n\n/**\n * Converts a React node to an HTMLElement.\n * This function uses flushSync to ensure the DOM is updated synchronously.\n * @param node - The React node to convert.\n * @returns The converted HTMLElement.\n */\nexport function reactNodeToHTMLElement(node: ReactNode): HTMLElement {\n const container = document.createElement('div');\n\n // Use React 18 root\n const root = createRoot(container);\n flushSync(() => {\n root.render(node);\n });\n\n // Wait until React mounts the content synchronously\n const element = container.firstElementChild;\n if (!(element instanceof HTMLElement)) {\n throw new Error(\n 'renderListItem must return a single JSX element that renders to an HTMLElement (e.g., <div>)'\n );\n }\n\n return element;\n}\n","import { forwardRef } from \"react\";\nimport { CourierInbox as CourierInboxElement } from \"@trycourier/courier-ui-inbox\";\nimport { CourierInboxComponent, CourierInboxProps, CourierRenderContext } from \"@trycourier/courier-react-components\";\nimport { reactNodeToHTMLElement } from \"../utils/render\";\n\n/**\n * CourierInbox React component.\n *\n * @example\n * ```tsx\n * const courier = useCourier();\n *\n * useEffect(() => {\n * // Generate a JWT for your user (do this on your backend server)\n * const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'; // Replace with actual JWT\n *\n * // Authenticate the user with the inbox\n * courier.shared.signIn({\n * userId: $YOUR_USER_ID,\n * jwt: jwt,\n * });\n * }, []);\n *\n * return <CourierInbox />;\n * ```\n */\nexport const CourierInbox = forwardRef<CourierInboxElement, CourierInboxProps>((props, ref) => {\n return (\n <CourierRenderContext.Provider value={reactNodeToHTMLElement}>\n <CourierInboxComponent {...props} ref={ref} />\n </CourierRenderContext.Provider>\n );\n});\n\nCourierInbox.displayName = 'CourierInbox';\n","import { forwardRef } from \"react\";\nimport { CourierInboxPopupMenu as CourierInboxPopupMenuElement } from \"@trycourier/courier-ui-inbox\";\nimport { CourierInboxPopupMenuComponent, CourierInboxPopupMenuProps, CourierRenderContext } from \"@trycourier/courier-react-components\";\nimport { reactNodeToHTMLElement } from \"../utils/render\";\n\n/**\n * CourierInboxPopupMenu React component.\n *\n * This component is used to display a popup menu for a message in the inbox.\n *\n * @example\n * ```tsx\n * const courier = useCourier();\n *\n * useEffect(() => {\n * // Generate a JWT for your user (do this on your backend server)\n * const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'; // Replace with actual JWT\n *\n * // Authenticate the user with the inbox\n * courier.shared.signIn({\n * userId: $YOUR_USER_ID,\n * jwt: jwt,\n * });\n * }, []);\n *\n * return <CourierInboxPopupMenu />;\n * ```\n */\nexport const CourierInboxPopupMenu = forwardRef<CourierInboxPopupMenuElement, CourierInboxPopupMenuProps>((props, ref) => {\n return (\n <CourierRenderContext.Provider value={reactNodeToHTMLElement}>\n <CourierInboxPopupMenuComponent {...props} ref={ref} />\n </CourierRenderContext.Provider>\n );\n});\n\nCourierInboxPopupMenu.displayName = 'CourierInboxPopupMenu';\n"],"names":["reactNodeToHTMLElement","node","container","document","createElement","root","createRoot","flushSync","render","element","firstElementChild","HTMLElement","Error","CourierInbox","forwardRef","props","ref","jsx","CourierRenderContext","Provider","value","children","CourierInboxComponent","displayName","CourierInboxPopupMenu","CourierInboxPopupMenuComponent"],"mappings":"yRAUO,SAASA,EAAuBC,GACrC,MAAMC,EAAYC,SAASC,cAAc,OAGnCC,EAAOC,EAAAA,WAAWJ,GACxBK,EAAAA,WAAU,KACRF,EAAKG,OAAOP,EAAI,IAIlB,MAAMQ,EAAUP,EAAUQ,kBAC1B,KAAMD,aAAmBE,aACvB,MAAM,IAAIC,MACR,gGAIJ,OAAOH,CACT,CCFO,MAAMI,EAAeC,EAAAA,YAAmD,CAACC,EAAOC,MAEnFC,IAACC,EAAAA,qBAAqBC,SAArB,CAA8BC,MAAOpB,EACpCqB,WAAAJ,IAACK,EAAAA,sBAAA,IAA0BP,EAAOC,YAKxCH,EAAaU,YAAc,eCNpB,MAAMC,EAAwBV,EAAAA,YAAqE,CAACC,EAAOC,MAE9GC,IAACC,EAAAA,qBAAqBC,SAArB,CAA8BC,MAAOpB,EACpCqB,WAAAJ,IAACQ,EAAAA,+BAAA,IAAmCV,EAAOC,YAKjDQ,EAAsBD,YAAc"}
package/dist/index.mjs CHANGED
@@ -1,362 +1,10 @@
1
- import { jsx, Fragment } from "react/jsx-runtime";
2
- import React, { createContext, forwardRef, useContext, useRef, useEffect, useState } from "react";
3
- import { Courier } from "@trycourier/courier-js";
4
- import { CourierInboxDatastore, CourierInboxDataStoreListener } from "@trycourier/courier-ui-inbox";
5
- import { archiveMessage, clickMessage, defaultDarkTheme, defaultLightTheme, markAsRead, markAsUnread, mergeTheme, openMessage } from "@trycourier/courier-ui-inbox";
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { forwardRef } from "react";
3
+ import { CourierRenderContext, CourierInboxComponent, CourierInboxPopupMenuComponent } from "@trycourier/courier-react-components";
4
+ import { useCourier } from "@trycourier/courier-react-components";
6
5
  import { flushSync } from "react-dom";
7
6
  import { createRoot } from "react-dom/client";
8
- const useCourier = () => {
9
- const signIn = (props) => Courier.shared.signIn(props);
10
- const signOut = () => Courier.shared.signOut();
11
- const loadInbox = (props) => CourierInboxDatastore.shared.load(props);
12
- const fetchNextPageOfMessages = (props) => CourierInboxDatastore.shared.fetchNextPageOfMessages(props);
13
- const setPaginationLimit = (limit) => Courier.shared.paginationLimit = limit;
14
- const readMessage = (message) => CourierInboxDatastore.shared.readMessage({ message });
15
- const unreadMessage = (message) => CourierInboxDatastore.shared.unreadMessage({ message });
16
- const clickMessage2 = (message) => CourierInboxDatastore.shared.clickMessage({ message });
17
- const archiveMessage2 = (message) => CourierInboxDatastore.shared.archiveMessage({ message });
18
- const openMessage2 = (message) => CourierInboxDatastore.shared.openMessage({ message });
19
- const unarchiveMessage = (message) => CourierInboxDatastore.shared.unarchiveMessage({ message });
20
- const readAllMessages = () => CourierInboxDatastore.shared.readAllMessages();
21
- const [auth, setAuth] = React.useState({
22
- userId: void 0,
23
- signIn,
24
- signOut
25
- });
26
- const [inbox, setInbox] = React.useState({
27
- load: loadInbox,
28
- fetchNextPageOfMessages,
29
- setPaginationLimit,
30
- readMessage,
31
- unreadMessage,
32
- clickMessage: clickMessage2,
33
- archiveMessage: archiveMessage2,
34
- openMessage: openMessage2,
35
- unarchiveMessage,
36
- readAllMessages
37
- });
38
- React.useEffect(() => {
39
- const listener = Courier.shared.addAuthenticationListener(() => refreshAuth());
40
- const inboxListener = new CourierInboxDataStoreListener({
41
- onError: (error) => refreshInbox(error),
42
- onDataSetChange: () => refreshInbox(),
43
- onPageAdded: () => refreshInbox(),
44
- onMessageAdd: () => refreshInbox(),
45
- onMessageRemove: () => refreshInbox(),
46
- onMessageUpdate: () => refreshInbox(),
47
- onUnreadCountChange: () => refreshInbox()
48
- });
49
- CourierInboxDatastore.shared.addDataStoreListener(inboxListener);
50
- refreshAuth();
51
- refreshInbox();
52
- return () => {
53
- listener.remove();
54
- inboxListener.remove();
55
- };
56
- }, []);
57
- const refreshAuth = () => {
58
- var _a;
59
- const options = (_a = Courier.shared.client) == null ? void 0 : _a.options;
60
- setAuth({
61
- userId: options == null ? void 0 : options.userId,
62
- signIn,
63
- signOut
64
- });
65
- };
66
- const refreshInbox = (error) => {
67
- const datastore = CourierInboxDatastore.shared;
68
- setInbox({
69
- load: loadInbox,
70
- fetchNextPageOfMessages,
71
- setPaginationLimit,
72
- readMessage,
73
- unreadMessage,
74
- clickMessage: clickMessage2,
75
- archiveMessage: archiveMessage2,
76
- openMessage: openMessage2,
77
- unarchiveMessage,
78
- readAllMessages,
79
- inbox: datastore.inboxDataSet,
80
- archive: datastore.archiveDataSet,
81
- unreadCount: datastore.unreadCount,
82
- error
83
- });
84
- };
85
- return {
86
- shared: Courier.shared,
87
- auth,
88
- inbox
89
- };
90
- };
91
- const CourierClientComponent = ({ children }) => {
92
- const [isMounted, setIsMounted] = useState(false);
93
- useEffect(() => {
94
- setIsMounted(true);
95
- }, []);
96
- if (typeof window === "undefined") {
97
- return null;
98
- }
99
- if (!isMounted) {
100
- return null;
101
- }
102
- return /* @__PURE__ */ jsx(Fragment, { children });
103
- };
104
- const CourierRenderContext = createContext(null);
105
- const CourierInboxComponent = forwardRef((props, ref) => {
106
- const render = useContext(CourierRenderContext);
107
- if (!render) {
108
- throw new Error("RenderContext not found. Ensure CourierInbox is wrapped in a CourierRenderContext.");
109
- }
110
- const inboxRef = useRef(null);
111
- function handleRef(el) {
112
- if (ref) {
113
- if (typeof ref === "function") {
114
- ref(el);
115
- } else {
116
- ref.current = el;
117
- }
118
- }
119
- inboxRef.current = el;
120
- }
121
- function getEl() {
122
- return inboxRef.current;
123
- }
124
- useEffect(() => {
125
- const inbox = getEl();
126
- if (!inbox) return;
127
- inbox.onMessageClick(props.onMessageClick);
128
- }, [props.onMessageClick]);
129
- useEffect(() => {
130
- const inbox = getEl();
131
- if (!inbox) return;
132
- inbox.onMessageActionClick(props.onMessageActionClick);
133
- }, [props.onMessageActionClick]);
134
- useEffect(() => {
135
- const inbox = getEl();
136
- if (!inbox) return;
137
- inbox.onMessageLongPress(props.onMessageLongPress);
138
- }, [props.onMessageLongPress]);
139
- useEffect(() => {
140
- const inbox = getEl();
141
- if (!inbox || !props.renderHeader) return;
142
- queueMicrotask(() => {
143
- inbox.setHeader((headerProps) => {
144
- const reactNode = props.renderHeader(headerProps);
145
- return render(reactNode);
146
- });
147
- });
148
- }, [props.renderHeader]);
149
- useEffect(() => {
150
- const inbox = getEl();
151
- if (!inbox || !props.renderListItem) return;
152
- queueMicrotask(() => {
153
- inbox.setListItem((itemProps) => {
154
- const reactNode = props.renderListItem(itemProps);
155
- return render(reactNode);
156
- });
157
- });
158
- }, [props.renderListItem]);
159
- useEffect(() => {
160
- const inbox = getEl();
161
- if (!inbox || !props.renderEmptyState) return;
162
- queueMicrotask(() => {
163
- inbox.setEmptyState((emptyStateProps) => {
164
- const reactNode = props.renderEmptyState(emptyStateProps);
165
- return render(reactNode);
166
- });
167
- });
168
- }, [props.renderEmptyState]);
169
- useEffect(() => {
170
- const inbox = getEl();
171
- if (!inbox || !props.renderLoadingState) return;
172
- queueMicrotask(() => {
173
- inbox.setLoadingState((loadingStateProps) => {
174
- const reactNode = props.renderLoadingState(loadingStateProps);
175
- return render(reactNode);
176
- });
177
- });
178
- }, [props.renderLoadingState]);
179
- useEffect(() => {
180
- const inbox = getEl();
181
- if (!inbox || !props.renderErrorState) return;
182
- queueMicrotask(() => {
183
- inbox.setErrorState((errorStateProps) => {
184
- const reactNode = props.renderErrorState(errorStateProps);
185
- return render(reactNode);
186
- });
187
- });
188
- }, [props.renderErrorState]);
189
- useEffect(() => {
190
- const inbox = getEl();
191
- if (!inbox || !props.renderPaginationItem) return;
192
- queueMicrotask(() => {
193
- inbox.setPaginationItem((paginationProps) => {
194
- const reactNode = props.renderPaginationItem(paginationProps);
195
- return render(reactNode);
196
- });
197
- });
198
- }, [props.renderPaginationItem]);
199
- useEffect(() => {
200
- const inbox = getEl();
201
- if (!inbox) return;
202
- queueMicrotask(() => {
203
- inbox.setFeedType(props.feedType || "inbox");
204
- });
205
- }, [props.feedType]);
206
- const children = (
207
- /* @ts-ignore */
208
- /* @__PURE__ */ jsx(
209
- "courier-inbox",
210
- {
211
- ref: handleRef,
212
- height: props.height,
213
- "light-theme": props.lightTheme ? JSON.stringify(props.lightTheme) : void 0,
214
- "dark-theme": props.darkTheme ? JSON.stringify(props.darkTheme) : void 0,
215
- mode: props.mode
216
- }
217
- )
218
- );
219
- return /* @__PURE__ */ jsx(CourierClientComponent, { children });
220
- });
221
- const CourierInboxPopupMenuComponent = forwardRef(
222
- (props, ref) => {
223
- const render = useContext(CourierRenderContext);
224
- if (!render) {
225
- throw new Error("RenderContext not found. Ensure CourierInboxPopupMenu is wrapped in a CourierRenderContext.");
226
- }
227
- const inboxRef = useRef(null);
228
- function handleRef(el) {
229
- if (ref) {
230
- if (typeof ref === "function") {
231
- ref(el);
232
- } else {
233
- ref.current = el;
234
- }
235
- }
236
- inboxRef.current = el;
237
- }
238
- function getEl() {
239
- return inboxRef.current;
240
- }
241
- const lastFeedTypeRef = useRef(void 0);
242
- useEffect(() => {
243
- const menu = getEl();
244
- if (!menu) return;
245
- if (props.feedType !== lastFeedTypeRef.current) {
246
- lastFeedTypeRef.current = props.feedType;
247
- queueMicrotask(() => {
248
- var _a;
249
- (_a = menu.setFeedType) == null ? void 0 : _a.call(menu, props.feedType ?? "inbox");
250
- });
251
- }
252
- }, [props.feedType]);
253
- useEffect(() => {
254
- const menu = getEl();
255
- if (!menu) return;
256
- menu.onMessageClick(props.onMessageClick);
257
- }, [props.onMessageClick]);
258
- useEffect(() => {
259
- const menu = getEl();
260
- if (!menu) return;
261
- menu.onMessageActionClick(props.onMessageActionClick);
262
- }, [props.onMessageActionClick]);
263
- useEffect(() => {
264
- const menu = getEl();
265
- if (!menu) return;
266
- menu.onMessageLongPress(props.onMessageLongPress);
267
- }, [props.onMessageLongPress]);
268
- useEffect(() => {
269
- const menu = getEl();
270
- if (!menu || !props.renderHeader) return;
271
- queueMicrotask(() => {
272
- menu.setHeader((headerProps) => {
273
- const reactNode = props.renderHeader(headerProps);
274
- return render(reactNode);
275
- });
276
- });
277
- }, [props.renderHeader]);
278
- useEffect(() => {
279
- const menu = getEl();
280
- if (!menu || !props.renderListItem) return;
281
- queueMicrotask(() => {
282
- menu.setListItem((itemProps) => {
283
- const reactNode = props.renderListItem(itemProps);
284
- return render(reactNode);
285
- });
286
- });
287
- }, [props.renderListItem]);
288
- useEffect(() => {
289
- const menu = getEl();
290
- if (!menu || !props.renderEmptyState) return;
291
- queueMicrotask(() => {
292
- menu.setEmptyState((emptyStateProps) => {
293
- const reactNode = props.renderEmptyState(emptyStateProps);
294
- return render(reactNode);
295
- });
296
- });
297
- }, [props.renderEmptyState]);
298
- useEffect(() => {
299
- const menu = getEl();
300
- if (!menu || !props.renderLoadingState) return;
301
- queueMicrotask(() => {
302
- menu.setLoadingState((loadingStateProps) => {
303
- const reactNode = props.renderLoadingState(loadingStateProps);
304
- return render(reactNode);
305
- });
306
- });
307
- }, [props.renderLoadingState]);
308
- useEffect(() => {
309
- const menu = getEl();
310
- if (!menu || !props.renderErrorState) return;
311
- queueMicrotask(() => {
312
- menu.setErrorState((errorStateProps) => {
313
- const reactNode = props.renderErrorState(errorStateProps);
314
- return render(reactNode);
315
- });
316
- });
317
- }, [props.renderErrorState]);
318
- useEffect(() => {
319
- const menu = getEl();
320
- if (!menu || !props.renderPaginationItem) return;
321
- queueMicrotask(() => {
322
- menu.setPaginationItem((paginationProps) => {
323
- const reactNode = props.renderPaginationItem(paginationProps);
324
- return render(reactNode);
325
- });
326
- });
327
- }, [props.renderPaginationItem]);
328
- useEffect(() => {
329
- const menu = getEl();
330
- if (!menu || !props.renderMenuButton) return;
331
- queueMicrotask(() => {
332
- menu.setMenuButton((buttonProps) => {
333
- const reactNode = props.renderMenuButton(buttonProps);
334
- return render(reactNode);
335
- });
336
- });
337
- }, [props.renderMenuButton]);
338
- const children = (
339
- /* @ts-ignore */
340
- /* @__PURE__ */ jsx(
341
- "courier-inbox-popup-menu",
342
- {
343
- ref: handleRef,
344
- "popup-alignment": props.popupAlignment,
345
- "popup-width": props.popupWidth,
346
- "popup-height": props.popupHeight,
347
- left: props.left,
348
- top: props.top,
349
- right: props.right,
350
- bottom: props.bottom,
351
- "light-theme": props.lightTheme ? JSON.stringify(props.lightTheme) : void 0,
352
- "dark-theme": props.darkTheme ? JSON.stringify(props.darkTheme) : void 0,
353
- mode: props.mode
354
- }
355
- )
356
- );
357
- return /* @__PURE__ */ jsx(CourierClientComponent, { children });
358
- }
359
- );
7
+ import { archiveMessage, clickMessage, defaultDarkTheme, defaultLightTheme, markAsRead, markAsUnread, mergeTheme, openMessage } from "@trycourier/courier-ui-inbox";
360
8
  function reactNodeToHTMLElement(node) {
361
9
  const container = document.createElement("div");
362
10
  const root = createRoot(container);
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../../courier-react-components/dist/index.mjs","../src/utils/render.tsx","../src/components/courier-inbox.tsx","../src/components/courier-inbox-popup-menu.tsx"],"sourcesContent":["import { Courier } from \"@trycourier/courier-js\";\nimport { CourierInboxDatastore, CourierInboxDataStoreListener } from \"@trycourier/courier-ui-inbox\";\nimport React, { useState, useEffect, createContext, forwardRef, useContext, useRef } from \"react\";\nimport { jsx, Fragment } from \"react/jsx-runtime\";\nconst useCourier = () => {\n const signIn = (props) => Courier.shared.signIn(props);\n const signOut = () => Courier.shared.signOut();\n const loadInbox = (props) => CourierInboxDatastore.shared.load(props);\n const fetchNextPageOfMessages = (props) => CourierInboxDatastore.shared.fetchNextPageOfMessages(props);\n const setPaginationLimit = (limit) => Courier.shared.paginationLimit = limit;\n const readMessage = (message) => CourierInboxDatastore.shared.readMessage({ message });\n const unreadMessage = (message) => CourierInboxDatastore.shared.unreadMessage({ message });\n const clickMessage = (message) => CourierInboxDatastore.shared.clickMessage({ message });\n const archiveMessage = (message) => CourierInboxDatastore.shared.archiveMessage({ message });\n const openMessage = (message) => CourierInboxDatastore.shared.openMessage({ message });\n const unarchiveMessage = (message) => CourierInboxDatastore.shared.unarchiveMessage({ message });\n const readAllMessages = () => CourierInboxDatastore.shared.readAllMessages();\n const [auth, setAuth] = React.useState({\n userId: void 0,\n signIn,\n signOut\n });\n const [inbox, setInbox] = React.useState({\n load: loadInbox,\n fetchNextPageOfMessages,\n setPaginationLimit,\n readMessage,\n unreadMessage,\n clickMessage,\n archiveMessage,\n openMessage,\n unarchiveMessage,\n readAllMessages\n });\n React.useEffect(() => {\n const listener = Courier.shared.addAuthenticationListener(() => refreshAuth());\n const inboxListener = new CourierInboxDataStoreListener({\n onError: (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 refreshAuth();\n refreshInbox();\n return () => {\n listener.remove();\n inboxListener.remove();\n };\n }, []);\n const refreshAuth = () => {\n var _a;\n const options = (_a = Courier.shared.client) == null ? void 0 : _a.options;\n setAuth({\n userId: options == null ? void 0 : options.userId,\n signIn,\n signOut\n });\n };\n const refreshInbox = (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\n });\n };\n return {\n shared: Courier.shared,\n auth,\n inbox\n };\n};\nconst CourierClientComponent = ({ children }) => {\n const [isMounted, setIsMounted] = useState(false);\n useEffect(() => {\n setIsMounted(true);\n }, []);\n if (typeof window === \"undefined\") {\n return null;\n }\n if (!isMounted) {\n return null;\n }\n return /* @__PURE__ */ jsx(Fragment, { children });\n};\nconst CourierRenderContext = createContext(null);\nconst CourierInboxComponent = forwardRef((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 const inboxRef = useRef(null);\n function handleRef(el) {\n if (ref) {\n if (typeof ref === \"function\") {\n ref(el);\n } else {\n ref.current = el;\n }\n }\n inboxRef.current = el;\n }\n function getEl() {\n return inboxRef.current;\n }\n useEffect(() => {\n const inbox = getEl();\n if (!inbox) return;\n inbox.onMessageClick(props.onMessageClick);\n }, [props.onMessageClick]);\n useEffect(() => {\n const inbox = getEl();\n if (!inbox) return;\n inbox.onMessageActionClick(props.onMessageActionClick);\n }, [props.onMessageActionClick]);\n useEffect(() => {\n const inbox = getEl();\n if (!inbox) return;\n inbox.onMessageLongPress(props.onMessageLongPress);\n }, [props.onMessageLongPress]);\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderHeader) return;\n queueMicrotask(() => {\n inbox.setHeader((headerProps) => {\n const reactNode = props.renderHeader(headerProps);\n return render(reactNode);\n });\n });\n }, [props.renderHeader]);\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderListItem) return;\n queueMicrotask(() => {\n inbox.setListItem((itemProps) => {\n const reactNode = props.renderListItem(itemProps);\n return render(reactNode);\n });\n });\n }, [props.renderListItem]);\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderEmptyState) return;\n queueMicrotask(() => {\n inbox.setEmptyState((emptyStateProps) => {\n const reactNode = props.renderEmptyState(emptyStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderEmptyState]);\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderLoadingState) return;\n queueMicrotask(() => {\n inbox.setLoadingState((loadingStateProps) => {\n const reactNode = props.renderLoadingState(loadingStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderLoadingState]);\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderErrorState) return;\n queueMicrotask(() => {\n inbox.setErrorState((errorStateProps) => {\n const reactNode = props.renderErrorState(errorStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderErrorState]);\n useEffect(() => {\n const inbox = getEl();\n if (!inbox || !props.renderPaginationItem) return;\n queueMicrotask(() => {\n inbox.setPaginationItem((paginationProps) => {\n const reactNode = props.renderPaginationItem(paginationProps);\n return render(reactNode);\n });\n });\n }, [props.renderPaginationItem]);\n useEffect(() => {\n const inbox = getEl();\n if (!inbox) return;\n queueMicrotask(() => {\n inbox.setFeedType(props.feedType || \"inbox\");\n });\n }, [props.feedType]);\n const children = (\n /* @ts-ignore */\n /* @__PURE__ */ jsx(\n \"courier-inbox\",\n {\n ref: handleRef,\n height: props.height,\n \"light-theme\": props.lightTheme ? JSON.stringify(props.lightTheme) : void 0,\n \"dark-theme\": props.darkTheme ? JSON.stringify(props.darkTheme) : void 0,\n mode: props.mode\n }\n )\n );\n return /* @__PURE__ */ jsx(CourierClientComponent, { children });\n});\nconst CourierInboxPopupMenuComponent = forwardRef(\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 const inboxRef = useRef(null);\n function handleRef(el) {\n if (ref) {\n if (typeof ref === \"function\") {\n ref(el);\n } else {\n ref.current = el;\n }\n }\n inboxRef.current = el;\n }\n function getEl() {\n return inboxRef.current;\n }\n const lastFeedTypeRef = useRef(void 0);\n useEffect(() => {\n const menu = getEl();\n if (!menu) return;\n if (props.feedType !== lastFeedTypeRef.current) {\n lastFeedTypeRef.current = props.feedType;\n queueMicrotask(() => {\n var _a;\n (_a = menu.setFeedType) == null ? void 0 : _a.call(menu, props.feedType ?? \"inbox\");\n });\n }\n }, [props.feedType]);\n useEffect(() => {\n const menu = getEl();\n if (!menu) return;\n menu.onMessageClick(props.onMessageClick);\n }, [props.onMessageClick]);\n useEffect(() => {\n const menu = getEl();\n if (!menu) return;\n menu.onMessageActionClick(props.onMessageActionClick);\n }, [props.onMessageActionClick]);\n useEffect(() => {\n const menu = getEl();\n if (!menu) return;\n menu.onMessageLongPress(props.onMessageLongPress);\n }, [props.onMessageLongPress]);\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderHeader) return;\n queueMicrotask(() => {\n menu.setHeader((headerProps) => {\n const reactNode = props.renderHeader(headerProps);\n return render(reactNode);\n });\n });\n }, [props.renderHeader]);\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderListItem) return;\n queueMicrotask(() => {\n menu.setListItem((itemProps) => {\n const reactNode = props.renderListItem(itemProps);\n return render(reactNode);\n });\n });\n }, [props.renderListItem]);\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderEmptyState) return;\n queueMicrotask(() => {\n menu.setEmptyState((emptyStateProps) => {\n const reactNode = props.renderEmptyState(emptyStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderEmptyState]);\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderLoadingState) return;\n queueMicrotask(() => {\n menu.setLoadingState((loadingStateProps) => {\n const reactNode = props.renderLoadingState(loadingStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderLoadingState]);\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderErrorState) return;\n queueMicrotask(() => {\n menu.setErrorState((errorStateProps) => {\n const reactNode = props.renderErrorState(errorStateProps);\n return render(reactNode);\n });\n });\n }, [props.renderErrorState]);\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderPaginationItem) return;\n queueMicrotask(() => {\n menu.setPaginationItem((paginationProps) => {\n const reactNode = props.renderPaginationItem(paginationProps);\n return render(reactNode);\n });\n });\n }, [props.renderPaginationItem]);\n useEffect(() => {\n const menu = getEl();\n if (!menu || !props.renderMenuButton) return;\n queueMicrotask(() => {\n menu.setMenuButton((buttonProps) => {\n const reactNode = props.renderMenuButton(buttonProps);\n return render(reactNode);\n });\n });\n }, [props.renderMenuButton]);\n const children = (\n /* @ts-ignore */\n /* @__PURE__ */ jsx(\n \"courier-inbox-popup-menu\",\n {\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) : void 0,\n \"dark-theme\": props.darkTheme ? JSON.stringify(props.darkTheme) : void 0,\n mode: props.mode\n }\n )\n );\n return /* @__PURE__ */ jsx(CourierClientComponent, { children });\n }\n);\nexport {\n CourierInboxComponent,\n CourierInboxPopupMenuComponent,\n CourierRenderContext,\n useCourier\n};\n//# sourceMappingURL=index.mjs.map\n","import { ReactNode } from \"react\";\nimport { flushSync } from \"react-dom\";\nimport { createRoot } from \"react-dom/client\";\n\n/**\n * Converts a React node to an HTMLElement.\n * This function uses flushSync to ensure the DOM is updated synchronously.\n * @param node - The React node to convert.\n * @returns The converted HTMLElement.\n */\nexport function reactNodeToHTMLElement(node: ReactNode): HTMLElement {\n const container = document.createElement('div');\n\n // Use React 18 root\n const root = createRoot(container);\n flushSync(() => {\n root.render(node);\n });\n\n // Wait until React mounts the content synchronously\n const element = container.firstElementChild;\n if (!(element instanceof HTMLElement)) {\n throw new Error(\n 'renderListItem must return a single JSX element that renders to an HTMLElement (e.g., <div>)'\n );\n }\n\n return element;\n}\n","import { forwardRef } from \"react\";\nimport { CourierInbox as CourierInboxElement } from \"@trycourier/courier-ui-inbox\";\nimport { CourierInboxComponent, CourierInboxProps, CourierRenderContext } from \"@trycourier/courier-react-components\";\nimport { reactNodeToHTMLElement } from \"../utils/render\";\n\n/**\n * CourierInbox React component.\n *\n * @example\n * ```tsx\n * const courier = useCourier();\n *\n * useEffect(() => {\n * // Generate a JWT for your user (do this on your backend server)\n * const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'; // Replace with actual JWT\n *\n * // Authenticate the user with the inbox\n * courier.shared.signIn({\n * userId: $YOUR_USER_ID,\n * jwt: jwt,\n * });\n * }, []);\n *\n * return <CourierInbox />;\n * ```\n */\nexport const CourierInbox = forwardRef<CourierInboxElement, CourierInboxProps>((props, ref) => {\n return (\n <CourierRenderContext.Provider value={reactNodeToHTMLElement}>\n <CourierInboxComponent {...props} ref={ref} />\n </CourierRenderContext.Provider>\n );\n});\n\nCourierInbox.displayName = 'CourierInbox';\n","import { forwardRef } from \"react\";\nimport { CourierInboxPopupMenu as CourierInboxPopupMenuElement } from \"@trycourier/courier-ui-inbox\";\nimport { CourierInboxPopupMenuComponent, CourierInboxPopupMenuProps, CourierRenderContext } from \"@trycourier/courier-react-components\";\nimport { reactNodeToHTMLElement } from \"../utils/render\";\n\n/**\n * CourierInboxPopupMenu React component.\n *\n * This component is used to display a popup menu for a message in the inbox.\n *\n * @example\n * ```tsx\n * const courier = useCourier();\n *\n * useEffect(() => {\n * // Generate a JWT for your user (do this on your backend server)\n * const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'; // Replace with actual JWT\n *\n * // Authenticate the user with the inbox\n * courier.shared.signIn({\n * userId: $YOUR_USER_ID,\n * jwt: jwt,\n * });\n * }, []);\n *\n * return <CourierInboxPopupMenu />;\n * ```\n */\nexport const CourierInboxPopupMenu = forwardRef<CourierInboxPopupMenuElement, CourierInboxPopupMenuProps>((props, ref) => {\n return (\n <CourierRenderContext.Provider value={reactNodeToHTMLElement}>\n <CourierInboxPopupMenuComponent {...props} ref={ref} />\n </CourierRenderContext.Provider>\n );\n});\n\nCourierInboxPopupMenu.displayName = 'CourierInboxPopupMenu';\n"],"names":["clickMessage","archiveMessage","openMessage"],"mappings":";;;;;;;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components/courier-inbox.tsx","../src/components/courier-inbox-popup-menu.tsx"],"sourcesContent":["import { ReactNode } from \"react\";\nimport { flushSync } from \"react-dom\";\nimport { createRoot } from \"react-dom/client\";\n\n/**\n * Converts a React node to an HTMLElement.\n * This function uses flushSync to ensure the DOM is updated synchronously.\n * @param node - The React node to convert.\n * @returns The converted HTMLElement.\n */\nexport function reactNodeToHTMLElement(node: ReactNode): HTMLElement {\n const container = document.createElement('div');\n\n // Use React 18 root\n const root = createRoot(container);\n flushSync(() => {\n root.render(node);\n });\n\n // Wait until React mounts the content synchronously\n const element = container.firstElementChild;\n if (!(element instanceof HTMLElement)) {\n throw new Error(\n 'renderListItem must return a single JSX element that renders to an HTMLElement (e.g., <div>)'\n );\n }\n\n return element;\n}\n","import { forwardRef } from \"react\";\nimport { CourierInbox as CourierInboxElement } from \"@trycourier/courier-ui-inbox\";\nimport { CourierInboxComponent, CourierInboxProps, CourierRenderContext } from \"@trycourier/courier-react-components\";\nimport { reactNodeToHTMLElement } from \"../utils/render\";\n\n/**\n * CourierInbox React component.\n *\n * @example\n * ```tsx\n * const courier = useCourier();\n *\n * useEffect(() => {\n * // Generate a JWT for your user (do this on your backend server)\n * const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'; // Replace with actual JWT\n *\n * // Authenticate the user with the inbox\n * courier.shared.signIn({\n * userId: $YOUR_USER_ID,\n * jwt: jwt,\n * });\n * }, []);\n *\n * return <CourierInbox />;\n * ```\n */\nexport const CourierInbox = forwardRef<CourierInboxElement, CourierInboxProps>((props, ref) => {\n return (\n <CourierRenderContext.Provider value={reactNodeToHTMLElement}>\n <CourierInboxComponent {...props} ref={ref} />\n </CourierRenderContext.Provider>\n );\n});\n\nCourierInbox.displayName = 'CourierInbox';\n","import { forwardRef } from \"react\";\nimport { CourierInboxPopupMenu as CourierInboxPopupMenuElement } from \"@trycourier/courier-ui-inbox\";\nimport { CourierInboxPopupMenuComponent, CourierInboxPopupMenuProps, CourierRenderContext } from \"@trycourier/courier-react-components\";\nimport { reactNodeToHTMLElement } from \"../utils/render\";\n\n/**\n * CourierInboxPopupMenu React component.\n *\n * This component is used to display a popup menu for a message in the inbox.\n *\n * @example\n * ```tsx\n * const courier = useCourier();\n *\n * useEffect(() => {\n * // Generate a JWT for your user (do this on your backend server)\n * const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'; // Replace with actual JWT\n *\n * // Authenticate the user with the inbox\n * courier.shared.signIn({\n * userId: $YOUR_USER_ID,\n * jwt: jwt,\n * });\n * }, []);\n *\n * return <CourierInboxPopupMenu />;\n * ```\n */\nexport const CourierInboxPopupMenu = forwardRef<CourierInboxPopupMenuElement, CourierInboxPopupMenuProps>((props, ref) => {\n return (\n <CourierRenderContext.Provider value={reactNodeToHTMLElement}>\n <CourierInboxPopupMenuComponent {...props} ref={ref} />\n </CourierRenderContext.Provider>\n );\n});\n\nCourierInboxPopupMenu.displayName = 'CourierInboxPopupMenu';\n"],"names":[],"mappings":";;;;;;;AAUO,SAAS,uBAAuB,MAA8B;AACnE,QAAM,YAAY,SAAS,cAAc,KAAK;AAG9C,QAAM,OAAO,WAAW,SAAS;AACjC,YAAU,MAAM;AACd,SAAK,OAAO,IAAI;AAAA,EAClB,CAAC;AAGD,QAAM,UAAU,UAAU;AAC1B,MAAI,EAAE,mBAAmB,cAAc;AACrC,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAAA,EAEJ;AAEA,SAAO;AACT;ACFO,MAAM,eAAe,WAAmD,CAAC,OAAO,QAAQ;AAC7F,SACE,oBAAC,qBAAqB,UAArB,EAA8B,OAAO,wBACpC,UAAA,oBAAC,uBAAA,EAAuB,GAAG,OAAO,IAAA,CAAU,EAAA,CAC9C;AAEJ,CAAC;AAED,aAAa,cAAc;ACNpB,MAAM,wBAAwB,WAAqE,CAAC,OAAO,QAAQ;AACxH,SACE,oBAAC,qBAAqB,UAArB,EAA8B,OAAO,wBACpC,UAAA,oBAAC,gCAAA,EAAgC,GAAG,OAAO,IAAA,CAAU,EAAA,CACvD;AAEJ,CAAC;AAED,sBAAsB,cAAc;"}
@@ -1,4 +1,4 @@
1
- import { ReactNode } from '../../../../node_modules/react';
1
+ import { ReactNode } from 'react';
2
2
  /**
3
3
  * Converts a React node to an HTMLElement.
4
4
  * This function uses flushSync to ensure the DOM is updated synchronously.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trycourier/courier-react",
3
- "version": "8.0.28",
3
+ "version": "8.0.29-alpha.1",
4
4
  "description": "The React components for the Courier web UI",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -28,6 +28,7 @@
28
28
  "license": "MIT",
29
29
  "dependencies": {
30
30
  "@trycourier/courier-js": "2.0.11",
31
+ "@trycourier/courier-react-components": "1.0.4-alpha.1",
31
32
  "@trycourier/courier-ui-core": "1.0.13",
32
33
  "@trycourier/courier-ui-inbox": "1.0.17"
33
34
  },
@@ -40,7 +41,6 @@
40
41
  "@testing-library/jest-dom": "^6.6.3",
41
42
  "@testing-library/react": "^16.3.0",
42
43
  "@testing-library/user-event": "^14.6.1",
43
- "@trycourier/courier-react-components": "1.0.3",
44
44
  "@types/jest": "^29.5.12",
45
45
  "@types/react": "19.1.8",
46
46
  "@types/react-dom": "19.1.6",