@trycourier/courier-react-17 8.0.25

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 ADDED
@@ -0,0 +1,394 @@
1
+ # `@trycourier/courier-react-17`
2
+
3
+ ![courier-react-17](https://github.com/user-attachments/assets/e886b445-d106-4dab-afca-82183e0fcbe7)
4
+
5
+ ## 1. Install
6
+
7
+ ```sh
8
+ npm install @trycourier/courier-react-17@beta
9
+ ```
10
+
11
+ > **Using React 18+?** Check out the [@trycourier/courier-react](../courier-react/) package.
12
+ >
13
+ > **Not using React?** Use the [@trycourier/courier-ui-inbox](../courier-ui-inbox/README.md) package instead.
14
+
15
+ ## 2. Authenticate
16
+
17
+ To use the SDK, you need to generate a JWT (JSON Web Token) for your user. **This JWT should always be generated by your backend server, never in client-side code.**
18
+
19
+ **How it works:**
20
+
21
+ 1. **Your frontend calls your backend:**
22
+ - When your app needs to authenticate a user, your frontend should make a request to your own backend (e.g., `/api/generate-courier-jwt`).
23
+
24
+ 2. **Your backend calls Courier to issue a JWT:**
25
+ - In your backend endpoint, use your [Courier API Key](https://app.courier.com/settings/api-keys) to call the [Courier JWT Token Endpoint](https://www.courier.com/docs/reference/auth/issue-token) and generate a JWT for the user.
26
+ - Your backend then returns the JWT to your frontend.
27
+
28
+ To quickly test JWT generation (for development only), you can use the following cURL command to call Courier's API directly. **Do not use this in production or from client-side code.**
29
+
30
+ ```sh
31
+ curl --request POST \
32
+ --url https://api.courier.com/auth/issue-token \
33
+ --header 'Accept: application/json' \
34
+ --header 'Authorization: Bearer $YOUR_API_KEY' \
35
+ --header 'Content-Type: application/json' \
36
+ --data \
37
+ '{
38
+ "scope": "user_id:$YOUR_USER_ID write:user-tokens inbox:read:messages inbox:write:events read:preferences write:preferences read:brands",
39
+ "expires_in": "$YOUR_NUMBER days"
40
+ }'
41
+ ```
42
+
43
+ ## 3. Add Inbox Component
44
+
45
+ ### `CourierInbox`
46
+
47
+ <img width="688" alt="Screenshot 2025-06-25 at 5 17 47 PM" src="https://github.com/user-attachments/assets/1655f43b-cc61-473f-9204-8dffeae21042" />
48
+
49
+ ```ts
50
+ import { useEffect } from 'react';
51
+ import { CourierInbox, useCourier } from '@trycourier/courier-react-17';
52
+
53
+ export default function App() {
54
+
55
+ const courier = useCourier();
56
+
57
+ useEffect(() => {
58
+ // Generate a JWT for your user (do this on your backend server)
59
+ const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'; // Replace with actual JWT
60
+
61
+ // Authenticate the user with the inbox
62
+ courier.shared.signIn({
63
+ userId: $YOUR_USER_ID,
64
+ jwt: jwt,
65
+ });
66
+ }, []);
67
+
68
+ return <CourierInbox />;
69
+
70
+ }
71
+ ```
72
+
73
+ ### `CourierInboxPopupMenu`
74
+
75
+ <img width="605" alt="Screenshot 2025-06-25 at 5 21 53 PM" src="https://github.com/user-attachments/assets/1c5497ba-a860-4d7e-8cf7-5b56a65cea51" />
76
+
77
+ ```ts
78
+ import { useEffect } from 'react';
79
+ import { CourierInbox, useCourier } from '@trycourier/courier-react-17';
80
+
81
+ export default function App() {
82
+
83
+ const courier = useCourier();
84
+
85
+ useEffect(() => {
86
+ // Generate a JWT for your user (do this on your backend server)
87
+ const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'; // Replace with actual JWT
88
+
89
+ // Authenticate the user with the inbox
90
+ courier.shared.signIn({
91
+ userId: $YOUR_USER_ID,
92
+ jwt: jwt,
93
+ });
94
+ }, []);
95
+
96
+ return (
97
+ <div style={{ padding: '24px' }}>
98
+ <CourierInboxPopupMenu />
99
+ </div>
100
+ );
101
+
102
+ }
103
+ ```
104
+
105
+ ## Server Side Rendering Frameworks
106
+
107
+ `courier-react-17` only supports client side rendering. Frameworks like Next.js must be explicitly client-side rendered where the Courier components are used.
108
+
109
+ ## Handle Clicks and Presses
110
+
111
+ ```ts
112
+ import { useEffect } from 'react';
113
+ import { CourierInbox, useCourier, type CourierInboxListItemFactoryProps, type CourierInboxListItemActionFactoryProps } from '@trycourier/courier-react-17';
114
+
115
+ export default function App() {
116
+
117
+ const courier = useCourier();
118
+
119
+ useEffect(() => {
120
+ // Generate a JWT for your user (do this on your backend server)
121
+ const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'; // Replace with actual JWT
122
+
123
+ // Authenticate the user with the inbox
124
+ courier.shared.signIn({
125
+ userId: $YOUR_USER_ID,
126
+ jwt: jwt,
127
+ });
128
+ }, []);
129
+
130
+ return (
131
+ <CourierInbox
132
+ onMessageClick={({ message, index }: CourierInboxListItemFactoryProps) => {
133
+ alert("Message clicked at index " + index + ":\n" + JSON.stringify(message, null, 2));
134
+ }}
135
+ onMessageActionClick={({ message, action, index }: CourierInboxListItemActionFactoryProps) => {
136
+ alert(
137
+ "Message action clicked at index " + index + ":\n" +
138
+ "Action: " + JSON.stringify(action, null, 2) + "\n" +
139
+ "Message: " + JSON.stringify(message, null, 2)
140
+ );
141
+ }}
142
+ onMessageLongPress={({ message, index }: CourierInboxListItemFactoryProps) => {
143
+ // Handle message long presses. **Only works on devices that support javascript's touch events. This will not work with a mouse cursor.**
144
+ alert("Message long pressed at index " + index + ":\n" + JSON.stringify(message, null, 2));
145
+ }}
146
+ />
147
+ );
148
+
149
+ }
150
+ ```
151
+
152
+ ## Styles and Theming
153
+
154
+ ### Light & Dark Themes
155
+
156
+ The fastest way to style the Inbox to match your app. This example shows unread indicator styling, but you can customize fonts, icons, text, and more.
157
+
158
+ > **🎨 Theme Reference:** [All available theme values](../courier-ui-inbox/docs/theme.md)
159
+
160
+ <img width="688" alt="Screenshot 2025-06-25 at 5 38 07 PM" src="https://github.com/user-attachments/assets/d1440494-ee66-4ff6-850b-c1a13691cf2f" />
161
+
162
+ ```ts
163
+ import { CourierInbox, ..., type CourierInboxTheme } from '@trycourier/courier-react-17';
164
+
165
+ export default function App() {
166
+ ...
167
+
168
+ const theme: CourierInboxTheme = {
169
+ inbox: {
170
+ header: {
171
+ filters: {
172
+ unreadIndicator: {
173
+ backgroundColor: '#8B5CF6',
174
+ },
175
+ },
176
+ },
177
+ list: {
178
+ item: {
179
+ unreadIndicatorColor: '#8B5CF6',
180
+ },
181
+ },
182
+ },
183
+ };
184
+
185
+ return <CourierInbox lightTheme={theme} darkTheme={theme} mode="light" />;
186
+ }
187
+ ```
188
+
189
+ ### Popup Alignment, Positioning, and Dimensions
190
+
191
+ ```ts
192
+ export default function App() {
193
+
194
+ ...
195
+
196
+ return (
197
+ <div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', padding: '100px' }}>
198
+ <CourierInboxPopupMenu
199
+ popupAlignment="top-right" // 'top-right' | 'top-left' | 'top-center' | 'bottom-right' | 'bottom-left' | 'bottom-center' | 'center-right' | 'center-left' | 'center-center'
200
+ popupWidth="340px"
201
+ popupHeight="400px"
202
+ top="44px"
203
+ right="44px"
204
+ />
205
+ </div>
206
+ );
207
+
208
+ }
209
+ ```
210
+
211
+ ### Custom height `CourierInbox`
212
+
213
+ > **Important:** The default `CourierInbox` height is auto. It will set it's height based on it's children.
214
+
215
+ ```ts
216
+ <CourierInbox height='50vh' />
217
+ ```
218
+
219
+ ## Custom Elements
220
+
221
+ Customize the inbox UI with any element you want.
222
+
223
+ ### List Items
224
+
225
+ <img width="688" alt="Screenshot 2025-06-25 at 6 25 17 PM" src="https://github.com/user-attachments/assets/075a568b-5538-4116-bb3d-752ecc5dea2c" />
226
+
227
+ ```ts
228
+ import { CourierInbox, ..., type CourierInboxListItemFactoryProps } from '@trycourier/courier-react-17'
229
+
230
+ const CustomListItem = ({ message, index }: CourierInboxListItemFactoryProps) => (
231
+ <pre style={{
232
+ padding: '24px',
233
+ borderBottom: '1px solid #e0e0e0',
234
+ margin: '0'
235
+ }}>
236
+ {JSON.stringify({ message, index }, null, 2)}
237
+ </pre>
238
+ );
239
+
240
+ export default function App() {
241
+
242
+ ...
243
+
244
+ return (
245
+ <CourierInbox
246
+ renderListItem={(props: CourierInboxListItemFactoryProps) => {
247
+ return <CustomListItem {...props} />
248
+ }}
249
+ />
250
+ );
251
+
252
+ }
253
+ ```
254
+
255
+ ### Header
256
+
257
+ <img width="688" alt="Screenshot 2025-06-25 at 6 35 59 PM" src="https://github.com/user-attachments/assets/25d45ac1-32e6-4e98-baf1-d0df34cef72a" />
258
+
259
+ ```ts
260
+ import { CourierInbox, ..., type CourierInboxHeaderFactoryProps } from '@trycourier/courier-react-17'
261
+
262
+ const CustomHeader = (props: CourierInboxHeaderFactoryProps) => (
263
+ <div style={{
264
+ background: 'red',
265
+ fontSize: '24px',
266
+ padding: '24px',
267
+ width: '100%'
268
+ }}>
269
+ {props.feedType}
270
+ </div>
271
+ );
272
+
273
+ export default function App() {
274
+
275
+ ...
276
+
277
+ return (
278
+ <CourierInbox
279
+ renderHeader={(props: CourierInboxHeaderFactoryProps) => {
280
+ return <CustomHeader {...props} />
281
+ }}
282
+ />
283
+ );
284
+
285
+ }
286
+ ```
287
+
288
+ ### Popup Menu Button
289
+
290
+ <img width="606" alt="Screenshot 2025-06-25 at 6 40 38 PM" src="https://github.com/user-attachments/assets/dfb0daca-f11d-420f-9dc7-0c14b49ab7db" />
291
+
292
+ ```ts
293
+ import { CourierInboxPopupMenu, ..., type CourierInboxMenuButtonFactoryProps } from '@trycourier/courier-react-17'
294
+
295
+ const CustomMenuButton = ({ unreadCount }: CourierInboxMenuButtonFactoryProps) => (
296
+ <button>
297
+ Open the Inbox Popup. Unread message count: {unreadCount}
298
+ </button>
299
+ );
300
+
301
+ export default function App() {
302
+
303
+ ...
304
+
305
+ return (
306
+ <div style={{ padding: '24px' }}>
307
+ <CourierInboxPopupMenu
308
+ renderMenuButton={(props: CourierInboxMenuButtonFactoryProps) => {
309
+ return <CustomMenuButton {...props} />
310
+ }}
311
+ />
312
+ </div>
313
+ );
314
+
315
+ }
316
+ ```
317
+
318
+ ### Loading, Empty, Error & Pagination
319
+
320
+ ```ts
321
+ import {
322
+ CourierInbox,
323
+ ...,
324
+ type CourierInboxStateEmptyFactoryProps,
325
+ type CourierInboxStateLoadingFactoryProps,
326
+ type CourierInboxStateErrorFactoryProps,
327
+ type CourierInboxPaginationItemFactoryProps
328
+ } from '@trycourier/courier-react-17'
329
+
330
+ const CustomLoadingState = ({ feedType }: CourierInboxStateLoadingFactoryProps) => (
331
+ <div style={{
332
+ padding: '24px',
333
+ background: 'red',
334
+ textAlign: 'center'
335
+ }}>
336
+ Custom Loading State
337
+ </div>
338
+ );
339
+
340
+ const CustomEmptyState = ({ feedType }: CourierInboxStateEmptyFactoryProps) => (
341
+ <div style={{
342
+ padding: '24px',
343
+ background: 'green',
344
+ textAlign: 'center'
345
+ }}>
346
+ Custom Empty State
347
+ </div>
348
+ );
349
+
350
+ const CustomErrorState = ({ feedType, error }: CourierInboxStateErrorFactoryProps) => (
351
+ <div style={{
352
+ padding: '24px',
353
+ background: 'blue',
354
+ textAlign: 'center'
355
+ }}>
356
+ Custom Error State: {error.message}
357
+ </div>
358
+ );
359
+
360
+ const CustomPaginationItem = ({ feedType }: CourierInboxPaginationItemFactoryProps) => (
361
+ <div style={{
362
+ padding: '24px',
363
+ background: 'yellow',
364
+ textAlign: 'center'
365
+ }}>
366
+ Custom Pagination Item
367
+ </div>
368
+ );
369
+
370
+ export default function App() {
371
+
372
+ ...
373
+
374
+ return (
375
+ <CourierInbox
376
+ renderLoadingState={(props: CourierInboxStateLoadingFactoryProps) => {
377
+ return <CustomLoadingState {...props} />
378
+ }}
379
+ renderEmptyState={(props: CourierInboxStateEmptyFactoryProps) => {
380
+ return <CustomEmptyState {...props} />
381
+ }}
382
+ renderErrorState={(props: CourierInboxStateErrorFactoryProps) => {
383
+ return <CustomErrorState {...props} />
384
+ }}
385
+ renderPaginationItem={(props: CourierInboxPaginationItemFactoryProps) => {
386
+ return <CustomPaginationItem {...props} />
387
+ }}
388
+ />
389
+ );
390
+
391
+ }
392
+ ```
393
+
394
+ > **Not using React?** We suggest you use [@trycourier/courier-ui-inbox](../courier-ui-inbox/README.md) package instead.
@@ -0,0 +1,26 @@
1
+ import { CourierInboxPopupMenu as CourierInboxPopupMenuElement } from '@trycourier/courier-ui-inbox';
2
+ import { CourierInboxPopupMenuProps } from '@trycourier/courier-react-components';
3
+ /**
4
+ * CourierInboxPopupMenu React component.
5
+ *
6
+ * This component is used to display a popup menu for a message in the inbox.
7
+ *
8
+ * @example
9
+ * ```tsx
10
+ * const courier = useCourier();
11
+ *
12
+ * useEffect(() => {
13
+ * // Generate a JWT for your user (do this on your backend server)
14
+ * const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'; // Replace with actual JWT
15
+ *
16
+ * // Authenticate the user with the inbox
17
+ * courier.shared.signIn({
18
+ * userId: $YOUR_USER_ID,
19
+ * jwt: jwt,
20
+ * });
21
+ * }, []);
22
+ *
23
+ * return <CourierInboxPopupMenu />;
24
+ * ```
25
+ */
26
+ export declare const CourierInboxPopupMenu: import('../../../../node_modules/react').ForwardRefExoticComponent<CourierInboxPopupMenuProps & import('../../../../node_modules/react').RefAttributes<CourierInboxPopupMenuElement>>;
@@ -0,0 +1,24 @@
1
+ import { CourierInbox as CourierInboxElement } from '@trycourier/courier-ui-inbox';
2
+ import { CourierInboxProps } from '@trycourier/courier-react-components';
3
+ /**
4
+ * CourierInbox React component.
5
+ *
6
+ * @example
7
+ * ```tsx
8
+ * const courier = useCourier();
9
+ *
10
+ * useEffect(() => {
11
+ * // Generate a JWT for your user (do this on your backend server)
12
+ * const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'; // Replace with actual JWT
13
+ *
14
+ * // Authenticate the user with the inbox
15
+ * courier.shared.signIn({
16
+ * userId: $YOUR_USER_ID,
17
+ * jwt: jwt,
18
+ * });
19
+ * }, []);
20
+ *
21
+ * return <CourierInbox />;
22
+ * ```
23
+ */
24
+ export declare const CourierInbox: import('../../../../node_modules/react').ForwardRefExoticComponent<CourierInboxProps & import('../../../../node_modules/react').RefAttributes<CourierInboxElement>>;
package/dist/index.cjs ADDED
@@ -0,0 +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}};
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +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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QACJ"}
@@ -0,0 +1,12 @@
1
+ export { CourierInbox } from './components/courier-inbox';
2
+ export { CourierInboxPopupMenu } from './components/courier-inbox-popup-menu';
3
+ export { useCourier } from '@trycourier/courier-react-components';
4
+ export type { CourierInboxProps, CourierInboxPopupMenuProps, } from '@trycourier/courier-react-components';
5
+ export type { CourierProps, CourierClientOptions, CourierBrand, CourierApiUrls, CourierUserPreferences, CourierUserPreferencesStatus, CourierUserPreferencesChannel, CourierUserPreferencesPaging, CourierUserPreferencesTopic, CourierUserPreferencesTopicResponse, CourierDevice, CourierToken, CourierGetInboxMessageResponse, CourierGetInboxMessagesResponse, InboxMessage, InboxAction, InboxMessageEventEnvelope, } from '@trycourier/courier-js';
6
+ export { markAsRead, markAsUnread, clickMessage, archiveMessage, openMessage } from '@trycourier/courier-ui-inbox';
7
+ export type { CourierInboxHeaderFactoryProps, CourierInboxStateLoadingFactoryProps, CourierInboxStateEmptyFactoryProps, CourierInboxStateErrorFactoryProps, CourierInboxListItemFactoryProps, CourierInboxListItemActionFactoryProps, CourierInboxPaginationItemFactoryProps, CourierInboxMenuButtonFactoryProps, CourierInboxFeedType } from '@trycourier/courier-ui-inbox';
8
+ export type { CourierInboxTheme, CourierInboxFontTheme, CourierInboxIconTheme, CourierInboxFilterItemTheme, CourierInboxUnreadCountIndicatorTheme, CourierInboxUnreadDotIndicatorTheme, CourierInboxIconButtonTheme, CourierInboxButtonTheme, CourierInboxMenuButtonTheme, CourierInboxPopupTheme, CourierInboxListItemTheme, CourierInboxSkeletonLoadingStateTheme, CourierInboxInfoStateTheme, CourierMenuItemTheme, CourierFilterMenuTheme, CourierActionMenuTheme } from '@trycourier/courier-ui-inbox';
9
+ export { defaultLightTheme, defaultDarkTheme, mergeTheme } from '@trycourier/courier-ui-inbox';
10
+ export type { CourierInbox as CourierInboxElement } from '@trycourier/courier-ui-inbox';
11
+ export type { CourierInboxPopupMenu as CourierInboxPopupMenuElement } from '@trycourier/courier-ui-inbox';
12
+ export type { CourierComponentThemeMode } from '@trycourier/courier-ui-core';
package/dist/index.mjs ADDED
@@ -0,0 +1,391 @@
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";
6
+ 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
+ );
359
+ function reactNodeToHTMLElement(node) {
360
+ const container = document.createElement("div");
361
+ render(node, container);
362
+ const element = container.firstElementChild;
363
+ if (!(element instanceof HTMLElement)) {
364
+ throw new Error(
365
+ "reactNodeToHTMLElement must return a single JSX element that renders to an HTMLElement (e.g., <div>)"
366
+ );
367
+ }
368
+ return element;
369
+ }
370
+ const CourierInbox = forwardRef((props, ref) => {
371
+ return /* @__PURE__ */ jsx(CourierRenderContext.Provider, { value: reactNodeToHTMLElement, children: /* @__PURE__ */ jsx(CourierInboxComponent, { ...props, ref }) });
372
+ });
373
+ CourierInbox.displayName = "CourierInbox";
374
+ const CourierInboxPopupMenu = forwardRef((props, ref) => {
375
+ return /* @__PURE__ */ jsx(CourierRenderContext.Provider, { value: reactNodeToHTMLElement, children: /* @__PURE__ */ jsx(CourierInboxPopupMenuComponent, { ...props, ref }) });
376
+ });
377
+ CourierInboxPopupMenu.displayName = "CourierInboxPopupMenu";
378
+ export {
379
+ CourierInbox,
380
+ CourierInboxPopupMenu,
381
+ archiveMessage,
382
+ clickMessage,
383
+ defaultDarkTheme,
384
+ defaultLightTheme,
385
+ markAsRead,
386
+ markAsUnread,
387
+ mergeTheme,
388
+ openMessage,
389
+ useCourier
390
+ };
391
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +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,OA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e,MAAM;AAAA,UACrB,gBAAgB,MAAM;AAAA,UACtB,MAAM,MAAM;AAAA,UACZ,KAAK,MAAM;AAAA,UACX,OAAO,MAAM;AAAA,UACb,QAAQ,MAAM;AAAA,UACd,eAAe,MAAM,aAAa,KAAK,UAAU,MAAM,UAAU,IAAI;AAAA,UACrE,cAAc,MAAM,YAAY,KAAK,UAAU,MAAM,SAAS,IAAI;AAAA,UAClE,MAAM,MAAM;AAAA,QACtB;AAAA,MACA;AAAA;AAEI,WAAuB,oBAAI,wBAAwB,EAAE,UAAU;AAAA,EACjE;AACF;AC3VO,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;"}
@@ -0,0 +1,7 @@
1
+ import { ReactNode } from '../../../../node_modules/react';
2
+ /**
3
+ * Converts a React node to an HTMLElement.
4
+ * @param node - The React node to convert.
5
+ * @returns The converted HTMLElement.
6
+ */
7
+ export declare function reactNodeToHTMLElement(node: ReactNode): HTMLElement;
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@trycourier/courier-react-17",
3
+ "version": "8.0.25",
4
+ "description": "React 17 components for the Courier web UI",
5
+ "main": "dist/index.cjs",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "scripts": {
9
+ "dev": "vite",
10
+ "build": "cross-env NODE_ENV=production tsc && vite build --mode production",
11
+ "watch": "vite build --watch",
12
+ "preview": "vite preview",
13
+ "prepare": "npm run build",
14
+ "test": "jest",
15
+ "test:watch": "jest --watch"
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "keywords": [
21
+ "courier",
22
+ "ui",
23
+ "react",
24
+ "typescript",
25
+ "browser"
26
+ ],
27
+ "author": "Courier",
28
+ "license": "MIT",
29
+ "dependencies": {
30
+ "@trycourier/courier-js": "2.0.10",
31
+ "@trycourier/courier-react-components": "1.0.0",
32
+ "@trycourier/courier-ui-core": "1.0.12",
33
+ "@trycourier/courier-ui-inbox": "1.0.15"
34
+ },
35
+ "peerDependencies": {
36
+ "react": ">=17.0.0, <18.0.0",
37
+ "react-dom": ">=17.0.0, <18.0.0"
38
+ },
39
+ "devDependencies": {
40
+ "@testing-library/dom": "^8.20.1",
41
+ "@testing-library/jest-dom": "^6.6.3",
42
+ "@testing-library/react": "^12.1.5",
43
+ "@testing-library/user-event": "^14.6.1",
44
+ "@types/jest": "^29.5.12",
45
+ "@types/react": "17.0.2",
46
+ "@types/react-dom": "17.0.2",
47
+ "@vitejs/plugin-react": "4.4.1",
48
+ "cross-env": "^7.0.3",
49
+ "jest": "^29.7.0",
50
+ "jest-environment-jsdom": "^29.7.0",
51
+ "react": "17.0.2",
52
+ "react-dom": "17.0.2",
53
+ "ts-jest": "^29.1.2",
54
+ "vite": "6.2.6",
55
+ "vite-plugin-dts": "4.5.3"
56
+ },
57
+ "overrides": {
58
+ "react": "17.0.2",
59
+ "react-dom": "17.0.2"
60
+ },
61
+ "resolutions": {
62
+ "react": "17.0.2",
63
+ "react-dom": "17.0.2"
64
+ }
65
+ }