@trycourier/courier-react-17 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
@@ -392,4 +392,79 @@ export default function App() {
392
392
  }
393
393
  ```
394
394
 
395
+ ### Available Hooks
396
+
397
+ ```ts
398
+ import { useCourier } from '@trycourier/courier-react';
399
+
400
+ const { auth, inbox } = useCourier();
401
+
402
+ // Sign in & Sign out
403
+ useEffect(() => {
404
+ auth.signIn({
405
+ userId: '$YOUR_USER_ID',
406
+ jwt: jwt,
407
+ });
408
+
409
+ // To sign out, call:
410
+ auth.signOut();
411
+ }, [auth]);
412
+
413
+ // Log the signed-in user
414
+ useEffect(() => {
415
+ console.log('Current Courier User: ', auth.userId);
416
+ }, [auth.userId]);
417
+
418
+ // Inbox Hooks
419
+ useEffect(() => {
420
+
421
+ // Set how many messages get fetched when getting another page
422
+ inbox.setPaginationLimit(20);
423
+
424
+ // Reload a specific dataset in the inbox
425
+ inbox.load({ feedType: 'inbox', canUseCache: true });
426
+
427
+ // Fetch the next page of messages
428
+ inbox.fetchNextPageOfMessages({ feedType: 'inbox' }).then((data) => {
429
+ if (data) {
430
+ console.log('Next page of messages:', data);
431
+ }
432
+ });
433
+
434
+ // Mark all messages as read
435
+ inbox.readAllMessages();
436
+
437
+ // Log unread count and errors
438
+ if (inbox.unreadCount !== undefined) {
439
+ console.log('Unread messages:', inbox.unreadCount);
440
+ }
441
+
442
+ if (inbox.error) {
443
+ console.error('Inbox error:', inbox.error);
444
+ }
445
+
446
+ // Log inbox and archive datasets
447
+ if (inbox.inbox) {
448
+ console.log('Inbox dataset:', inbox.inbox);
449
+ }
450
+
451
+ if (inbox.archive) {
452
+ console.log('Archive dataset:', inbox.archive);
453
+ }
454
+
455
+ }, [
456
+ inbox,
457
+ inbox.inbox,
458
+ inbox.archive,
459
+ inbox.unreadCount,
460
+ inbox.error,
461
+ ]);
462
+ ```
463
+
395
464
  > **Not using React?** We suggest you use [@trycourier/courier-ui-inbox](../courier-ui-inbox/README.md) package instead.
465
+
466
+ ## **Share feedback with Courier**
467
+
468
+ We want to make this the best SDK for managing notifications! Have an idea or feedback about our SDKs? Let us know!
469
+
470
+ [Courier Web Issues](https://github.com/trycourier/courier-web/issues)
@@ -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=({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},a=r.createContext(null),i=r.forwardRef(((t,n)=>{const s=r.useContext(a);if(!s)throw new Error("RenderContext not found. Ensure CourierInbox is wrapped in a CourierRenderContext.");const i=r.useRef(null);function u(){return i.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 d=e.jsx("courier-inbox",{ref:function(e){n&&("function"==typeof n?n(e):n.current=e),i.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(o,{children:d})})),u=r.forwardRef(((t,n)=>{const s=r.useContext(a);if(!s)throw new Error("RenderContext not found. Ensure CourierInboxPopupMenu is wrapped in a CourierRenderContext.");const i=r.useRef(null);function u(){return i.current}const d=r.useRef(void 0);r.useEffect((()=>{const e=u();e&&t.feedType!==d.current&&(d.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 c=e.jsx("courier-inbox-popup-menu",{ref:function(e){n&&("function"==typeof n?n(e):n.current=e),i.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(o,{children:c})}));function d(e){const r=document.createElement("div");s.render(e,r);const t=r.firstElementChild;if(!(t instanceof HTMLElement))throw new Error("reactNodeToHTMLElement must return a single JSX element that renders to an HTMLElement (e.g., <div>)");return t}const c=r.forwardRef(((r,t)=>e.jsx(a.Provider,{value:d,children:e.jsx(i,{...r,ref:t})})));c.displayName="CourierInbox";const g=r.forwardRef(((r,t)=>e.jsx(a.Provider,{value:d,children:e.jsx(u,{...r,ref:t})})));g.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=c,exports.CourierInboxPopupMenu=g,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}),d=e=>n.CourierInboxDatastore.shared.unreadMessage({message:e}),c=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:d,clickMessage:c,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:d,clickMessage:c,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("@trycourier/courier-ui-inbox");function i(e){const r=document.createElement("div");o.render(e,r);const t=r.firstElementChild;if(!(t instanceof HTMLElement))throw new Error("reactNodeToHTMLElement must return a single JSX element that renders to an HTMLElement (e.g., <div>)");return t}const u=r.forwardRef(((r,o)=>e.jsx(t.CourierRenderContext.Provider,{value:i,children:e.jsx(t.CourierInboxComponent,{...r,ref:o})})));u.displayName="CourierInbox";const a=r.forwardRef(((r,o)=>e.jsx(t.CourierRenderContext.Provider,{value:i,children:e.jsx(t.CourierInboxPopupMenuComponent,{...r,ref:o})})));a.displayName="CourierInboxPopupMenu",Object.defineProperty(exports,"useCourier",{enumerable:!0,get:()=>t.useCourier}),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=u,exports.CourierInboxPopupMenu=a;
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 { render } from \"react-dom\";\n\n/**\n * Converts a React node to an HTMLElement.\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 render(node, container);\n\n const element = container.firstElementChild;\n if (!(element instanceof HTMLElement)) {\n throw new Error(\n 'reactNodeToHTMLElement 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","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":"6OAuFMA,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,WAAU,KACR,MAAMgB,EAAQF,IACTE,GACLA,EAAME,qBAAqBX,EAAMW,qBAAoB,GACpD,CAACX,EAAMW,uBACVlB,EAAAA,WAAU,KACR,MAAMgB,EAAQF,IACTE,GACLA,EAAMG,mBAAmBZ,EAAMY,mBAAkB,GAChD,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qBX,GAClDD,IACAK,IACO,KACLP,EAASe,SACTZ,EAAcY,QAAM,CACtB,GACC,IACH,MAAMb,EAAc,KAClB,IAAInD,EACJ,MAAMiE,EAA0C,OAA/BjE,EAAK0B,UAAQC,OAAOuC,aAAkB,EAASlE,EAAGiE,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,kBACAhF,MAAOwG,EAAUC,aACjBC,QAASF,EAAUG,eACnBC,YAAaJ,EAAUI,YACvBhB,SACD,EAEH,MAAO,CACL5B,OAAQD,EAAAA,QAAQC,OAChBiB,OACAjF,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 { render } from \"react-dom\";\n\n/**\n * Converts a React node to an HTMLElement.\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 render(node, container);\n\n const element = container.firstElementChild;\n if (!(element instanceof HTMLElement)) {\n throw new Error(\n 'reactNodeToHTMLElement 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","render","element","firstElementChild","HTMLElement","Error","CourierInbox","forwardRef","props","ref","jsx","CourierRenderContext","Provider","value","children","CourierInboxComponent","displayName","CourierInboxPopupMenu","CourierInboxPopupMenuComponent"],"mappings":"2PAQO,SAASA,EAAuBC,GACrC,MAAMC,EAAYC,SAASC,cAAc,OAEzCC,EAAAA,OAAOJ,EAAMC,GAEb,MAAMI,EAAUJ,EAAUK,kBAC1B,KAAMD,aAAmBE,aACvB,MAAM,IAAIC,MACR,wGAIJ,OAAOH,CACT,CCKO,MAAMI,EAAeC,EAAAA,YAAmD,CAACC,EAAOC,MAEnFC,IAACC,EAAAA,qBAAqBC,SAArB,CAA8BC,MAAOjB,EACpCkB,WAAAJ,IAACK,EAAAA,sBAAA,IAA0BP,EAAOC,YAKxCH,EAAaU,YAAc,eCNpB,MAAMC,EAAwBV,EAAAA,YAAqE,CAACC,EAAOC,MAE9GC,IAACC,EAAAA,qBAAqBC,SAArB,CAA8BC,MAAOjB,EACpCkB,WAAAJ,IAACQ,EAAAA,+BAAA,IAAmCV,EAAOC,YAKjDQ,EAAsBD,YAAc"}
package/dist/index.mjs CHANGED
@@ -1,361 +1,9 @@
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 { render } from "react-dom";
7
- const useCourier = () => {
8
- const signIn = (props) => Courier.shared.signIn(props);
9
- const signOut = () => Courier.shared.signOut();
10
- const loadInbox = (props) => CourierInboxDatastore.shared.load(props);
11
- const fetchNextPageOfMessages = (props) => CourierInboxDatastore.shared.fetchNextPageOfMessages(props);
12
- const setPaginationLimit = (limit) => Courier.shared.paginationLimit = limit;
13
- const readMessage = (message) => CourierInboxDatastore.shared.readMessage({ message });
14
- const unreadMessage = (message) => CourierInboxDatastore.shared.unreadMessage({ message });
15
- const clickMessage2 = (message) => CourierInboxDatastore.shared.clickMessage({ message });
16
- const archiveMessage2 = (message) => CourierInboxDatastore.shared.archiveMessage({ message });
17
- const openMessage2 = (message) => CourierInboxDatastore.shared.openMessage({ message });
18
- const unarchiveMessage = (message) => CourierInboxDatastore.shared.unarchiveMessage({ message });
19
- const readAllMessages = () => CourierInboxDatastore.shared.readAllMessages();
20
- const [auth, setAuth] = React.useState({
21
- userId: void 0,
22
- signIn,
23
- signOut
24
- });
25
- const [inbox, setInbox] = React.useState({
26
- load: loadInbox,
27
- fetchNextPageOfMessages,
28
- setPaginationLimit,
29
- readMessage,
30
- unreadMessage,
31
- clickMessage: clickMessage2,
32
- archiveMessage: archiveMessage2,
33
- openMessage: openMessage2,
34
- unarchiveMessage,
35
- readAllMessages
36
- });
37
- React.useEffect(() => {
38
- const listener = Courier.shared.addAuthenticationListener(() => refreshAuth());
39
- const inboxListener = new CourierInboxDataStoreListener({
40
- onError: (error) => refreshInbox(error),
41
- onDataSetChange: () => refreshInbox(),
42
- onPageAdded: () => refreshInbox(),
43
- onMessageAdd: () => refreshInbox(),
44
- onMessageRemove: () => refreshInbox(),
45
- onMessageUpdate: () => refreshInbox(),
46
- onUnreadCountChange: () => refreshInbox()
47
- });
48
- CourierInboxDatastore.shared.addDataStoreListener(inboxListener);
49
- refreshAuth();
50
- refreshInbox();
51
- return () => {
52
- listener.remove();
53
- inboxListener.remove();
54
- };
55
- }, []);
56
- const refreshAuth = () => {
57
- var _a;
58
- const options = (_a = Courier.shared.client) == null ? void 0 : _a.options;
59
- setAuth({
60
- userId: options == null ? void 0 : options.userId,
61
- signIn,
62
- signOut
63
- });
64
- };
65
- const refreshInbox = (error) => {
66
- const datastore = CourierInboxDatastore.shared;
67
- setInbox({
68
- load: loadInbox,
69
- fetchNextPageOfMessages,
70
- setPaginationLimit,
71
- readMessage,
72
- unreadMessage,
73
- clickMessage: clickMessage2,
74
- archiveMessage: archiveMessage2,
75
- openMessage: openMessage2,
76
- unarchiveMessage,
77
- readAllMessages,
78
- inbox: datastore.inboxDataSet,
79
- archive: datastore.archiveDataSet,
80
- unreadCount: datastore.unreadCount,
81
- error
82
- });
83
- };
84
- return {
85
- shared: Courier.shared,
86
- auth,
87
- inbox
88
- };
89
- };
90
- const CourierClientComponent = ({ children }) => {
91
- const [isMounted, setIsMounted] = useState(false);
92
- useEffect(() => {
93
- setIsMounted(true);
94
- }, []);
95
- if (typeof window === "undefined") {
96
- return null;
97
- }
98
- if (!isMounted) {
99
- return null;
100
- }
101
- return /* @__PURE__ */ jsx(Fragment, { children });
102
- };
103
- const CourierRenderContext = createContext(null);
104
- const CourierInboxComponent = forwardRef((props, ref) => {
105
- const render2 = useContext(CourierRenderContext);
106
- if (!render2) {
107
- throw new Error("RenderContext not found. Ensure CourierInbox is wrapped in a CourierRenderContext.");
108
- }
109
- const inboxRef = useRef(null);
110
- function handleRef(el) {
111
- if (ref) {
112
- if (typeof ref === "function") {
113
- ref(el);
114
- } else {
115
- ref.current = el;
116
- }
117
- }
118
- inboxRef.current = el;
119
- }
120
- function getEl() {
121
- return inboxRef.current;
122
- }
123
- useEffect(() => {
124
- const inbox = getEl();
125
- if (!inbox) return;
126
- inbox.onMessageClick(props.onMessageClick);
127
- }, [props.onMessageClick]);
128
- useEffect(() => {
129
- const inbox = getEl();
130
- if (!inbox) return;
131
- inbox.onMessageActionClick(props.onMessageActionClick);
132
- }, [props.onMessageActionClick]);
133
- useEffect(() => {
134
- const inbox = getEl();
135
- if (!inbox) return;
136
- inbox.onMessageLongPress(props.onMessageLongPress);
137
- }, [props.onMessageLongPress]);
138
- useEffect(() => {
139
- const inbox = getEl();
140
- if (!inbox || !props.renderHeader) return;
141
- queueMicrotask(() => {
142
- inbox.setHeader((headerProps) => {
143
- const reactNode = props.renderHeader(headerProps);
144
- return render2(reactNode);
145
- });
146
- });
147
- }, [props.renderHeader]);
148
- useEffect(() => {
149
- const inbox = getEl();
150
- if (!inbox || !props.renderListItem) return;
151
- queueMicrotask(() => {
152
- inbox.setListItem((itemProps) => {
153
- const reactNode = props.renderListItem(itemProps);
154
- return render2(reactNode);
155
- });
156
- });
157
- }, [props.renderListItem]);
158
- useEffect(() => {
159
- const inbox = getEl();
160
- if (!inbox || !props.renderEmptyState) return;
161
- queueMicrotask(() => {
162
- inbox.setEmptyState((emptyStateProps) => {
163
- const reactNode = props.renderEmptyState(emptyStateProps);
164
- return render2(reactNode);
165
- });
166
- });
167
- }, [props.renderEmptyState]);
168
- useEffect(() => {
169
- const inbox = getEl();
170
- if (!inbox || !props.renderLoadingState) return;
171
- queueMicrotask(() => {
172
- inbox.setLoadingState((loadingStateProps) => {
173
- const reactNode = props.renderLoadingState(loadingStateProps);
174
- return render2(reactNode);
175
- });
176
- });
177
- }, [props.renderLoadingState]);
178
- useEffect(() => {
179
- const inbox = getEl();
180
- if (!inbox || !props.renderErrorState) return;
181
- queueMicrotask(() => {
182
- inbox.setErrorState((errorStateProps) => {
183
- const reactNode = props.renderErrorState(errorStateProps);
184
- return render2(reactNode);
185
- });
186
- });
187
- }, [props.renderErrorState]);
188
- useEffect(() => {
189
- const inbox = getEl();
190
- if (!inbox || !props.renderPaginationItem) return;
191
- queueMicrotask(() => {
192
- inbox.setPaginationItem((paginationProps) => {
193
- const reactNode = props.renderPaginationItem(paginationProps);
194
- return render2(reactNode);
195
- });
196
- });
197
- }, [props.renderPaginationItem]);
198
- useEffect(() => {
199
- const inbox = getEl();
200
- if (!inbox) return;
201
- queueMicrotask(() => {
202
- inbox.setFeedType(props.feedType || "inbox");
203
- });
204
- }, [props.feedType]);
205
- const children = (
206
- /* @ts-ignore */
207
- /* @__PURE__ */ jsx(
208
- "courier-inbox",
209
- {
210
- ref: handleRef,
211
- height: props.height,
212
- "light-theme": props.lightTheme ? JSON.stringify(props.lightTheme) : void 0,
213
- "dark-theme": props.darkTheme ? JSON.stringify(props.darkTheme) : void 0,
214
- mode: props.mode
215
- }
216
- )
217
- );
218
- return /* @__PURE__ */ jsx(CourierClientComponent, { children });
219
- });
220
- const CourierInboxPopupMenuComponent = forwardRef(
221
- (props, ref) => {
222
- const render2 = useContext(CourierRenderContext);
223
- if (!render2) {
224
- throw new Error("RenderContext not found. Ensure CourierInboxPopupMenu is wrapped in a CourierRenderContext.");
225
- }
226
- const inboxRef = useRef(null);
227
- function handleRef(el) {
228
- if (ref) {
229
- if (typeof ref === "function") {
230
- ref(el);
231
- } else {
232
- ref.current = el;
233
- }
234
- }
235
- inboxRef.current = el;
236
- }
237
- function getEl() {
238
- return inboxRef.current;
239
- }
240
- const lastFeedTypeRef = useRef(void 0);
241
- useEffect(() => {
242
- const menu = getEl();
243
- if (!menu) return;
244
- if (props.feedType !== lastFeedTypeRef.current) {
245
- lastFeedTypeRef.current = props.feedType;
246
- queueMicrotask(() => {
247
- var _a;
248
- (_a = menu.setFeedType) == null ? void 0 : _a.call(menu, props.feedType ?? "inbox");
249
- });
250
- }
251
- }, [props.feedType]);
252
- useEffect(() => {
253
- const menu = getEl();
254
- if (!menu) return;
255
- menu.onMessageClick(props.onMessageClick);
256
- }, [props.onMessageClick]);
257
- useEffect(() => {
258
- const menu = getEl();
259
- if (!menu) return;
260
- menu.onMessageActionClick(props.onMessageActionClick);
261
- }, [props.onMessageActionClick]);
262
- useEffect(() => {
263
- const menu = getEl();
264
- if (!menu) return;
265
- menu.onMessageLongPress(props.onMessageLongPress);
266
- }, [props.onMessageLongPress]);
267
- useEffect(() => {
268
- const menu = getEl();
269
- if (!menu || !props.renderHeader) return;
270
- queueMicrotask(() => {
271
- menu.setHeader((headerProps) => {
272
- const reactNode = props.renderHeader(headerProps);
273
- return render2(reactNode);
274
- });
275
- });
276
- }, [props.renderHeader]);
277
- useEffect(() => {
278
- const menu = getEl();
279
- if (!menu || !props.renderListItem) return;
280
- queueMicrotask(() => {
281
- menu.setListItem((itemProps) => {
282
- const reactNode = props.renderListItem(itemProps);
283
- return render2(reactNode);
284
- });
285
- });
286
- }, [props.renderListItem]);
287
- useEffect(() => {
288
- const menu = getEl();
289
- if (!menu || !props.renderEmptyState) return;
290
- queueMicrotask(() => {
291
- menu.setEmptyState((emptyStateProps) => {
292
- const reactNode = props.renderEmptyState(emptyStateProps);
293
- return render2(reactNode);
294
- });
295
- });
296
- }, [props.renderEmptyState]);
297
- useEffect(() => {
298
- const menu = getEl();
299
- if (!menu || !props.renderLoadingState) return;
300
- queueMicrotask(() => {
301
- menu.setLoadingState((loadingStateProps) => {
302
- const reactNode = props.renderLoadingState(loadingStateProps);
303
- return render2(reactNode);
304
- });
305
- });
306
- }, [props.renderLoadingState]);
307
- useEffect(() => {
308
- const menu = getEl();
309
- if (!menu || !props.renderErrorState) return;
310
- queueMicrotask(() => {
311
- menu.setErrorState((errorStateProps) => {
312
- const reactNode = props.renderErrorState(errorStateProps);
313
- return render2(reactNode);
314
- });
315
- });
316
- }, [props.renderErrorState]);
317
- useEffect(() => {
318
- const menu = getEl();
319
- if (!menu || !props.renderPaginationItem) return;
320
- queueMicrotask(() => {
321
- menu.setPaginationItem((paginationProps) => {
322
- const reactNode = props.renderPaginationItem(paginationProps);
323
- return render2(reactNode);
324
- });
325
- });
326
- }, [props.renderPaginationItem]);
327
- useEffect(() => {
328
- const menu = getEl();
329
- if (!menu || !props.renderMenuButton) return;
330
- queueMicrotask(() => {
331
- menu.setMenuButton((buttonProps) => {
332
- const reactNode = props.renderMenuButton(buttonProps);
333
- return render2(reactNode);
334
- });
335
- });
336
- }, [props.renderMenuButton]);
337
- const children = (
338
- /* @ts-ignore */
339
- /* @__PURE__ */ jsx(
340
- "courier-inbox-popup-menu",
341
- {
342
- ref: handleRef,
343
- "popup-alignment": props.popupAlignment,
344
- "popup-width": props.popupWidth,
345
- "popup-height": props.popupHeight,
346
- left: props.left,
347
- top: props.top,
348
- right: props.right,
349
- bottom: props.bottom,
350
- "light-theme": props.lightTheme ? JSON.stringify(props.lightTheme) : void 0,
351
- "dark-theme": props.darkTheme ? JSON.stringify(props.darkTheme) : void 0,
352
- mode: props.mode
353
- }
354
- )
355
- );
356
- return /* @__PURE__ */ jsx(CourierClientComponent, { children });
357
- }
358
- );
6
+ import { archiveMessage, clickMessage, defaultDarkTheme, defaultLightTheme, markAsRead, markAsUnread, mergeTheme, openMessage } from "@trycourier/courier-ui-inbox";
359
7
  function reactNodeToHTMLElement(node) {
360
8
  const container = document.createElement("div");
361
9
  render(node, 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 { render } from \"react-dom\";\n\n/**\n * Converts a React node to an HTMLElement.\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 render(node, container);\n\n const element = container.firstElementChild;\n if (!(element instanceof HTMLElement)) {\n throw new Error(\n 'reactNodeToHTMLElement 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","render"],"mappings":";;;;;;AAIK,MAAC,aAAa,MAAM;AACvB,QAAM,SAAS,CAAC,UAAU,QAAQ,OAAO,OAAO,KAAK;AACrD,QAAM,UAAU,MAAM,QAAQ,OAAO,QAAO;AAC5C,QAAM,YAAY,CAAC,UAAU,sBAAsB,OAAO,KAAK,KAAK;AACpE,QAAM,0BAA0B,CAAC,UAAU,sBAAsB,OAAO,wBAAwB,KAAK;AACrG,QAAM,qBAAqB,CAAC,UAAU,QAAQ,OAAO,kBAAkB;AACvE,QAAM,cAAc,CAAC,YAAY,sBAAsB,OAAO,YAAY,EAAE,SAAS;AACrF,QAAM,gBAAgB,CAAC,YAAY,sBAAsB,OAAO,cAAc,EAAE,SAAS;AACzF,QAAMA,gBAAe,CAAC,YAAY,sBAAsB,OAAO,aAAa,EAAE,SAAS;AACvF,QAAMC,kBAAiB,CAAC,YAAY,sBAAsB,OAAO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S,uBAAuB,MAA8B;AACnE,QAAM,YAAY,SAAS,cAAc,KAAK;AAE9C,SAAO,MAAM,SAAS;AAEtB,QAAM,UAAU,UAAU;AAC1B,MAAI,EAAE,mBAAmB,cAAc;AACrC,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAAA,EAEJ;AAEA,SAAO;AACT;ACKO,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
+ {"version":3,"file":"index.mjs","sources":["../src/utils/render.tsx","../src/components/courier-inbox.tsx","../src/components/courier-inbox-popup-menu.tsx"],"sourcesContent":["import { ReactNode } from \"react\";\nimport { render } from \"react-dom\";\n\n/**\n * Converts a React node to an HTMLElement.\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 render(node, container);\n\n const element = container.firstElementChild;\n if (!(element instanceof HTMLElement)) {\n throw new Error(\n 'reactNodeToHTMLElement 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":";;;;;;AAQO,SAAS,uBAAuB,MAA8B;AACnE,QAAM,YAAY,SAAS,cAAc,KAAK;AAE9C,SAAO,MAAM,SAAS;AAEtB,QAAM,UAAU,UAAU;AAC1B,MAAI,EAAE,mBAAmB,cAAc;AACrC,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAAA,EAEJ;AAEA,SAAO;AACT;ACKO,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
  * @param node - The React node to convert.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trycourier/courier-react-17",
3
- "version": "8.0.28",
3
+ "version": "8.0.29-alpha.1",
4
4
  "description": "React 17 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": "^12.1.5",
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": "17.0.2",
46
46
  "@types/react-dom": "17.0.2",