@notificationapi/react 0.0.36 → 1.0.0

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.
Files changed (72) hide show
  1. package/dist/assets/Badge.js +456 -0
  2. package/dist/assets/Box.js +57 -0
  3. package/dist/assets/ButtonBase.js +1224 -0
  4. package/dist/assets/DefaultPropsProvider.js +4368 -0
  5. package/dist/assets/Divider.js +343 -0
  6. package/dist/assets/IconButton.js +225 -0
  7. package/dist/assets/Inbox.js +3051 -0
  8. package/dist/assets/InboxHeader.js +2338 -0
  9. package/dist/assets/Notification.js +5349 -7150
  10. package/dist/assets/NotificationPreferencesPopup.js +1694 -0
  11. package/dist/assets/Paper.js +154 -0
  12. package/dist/assets/Popover.js +451 -0
  13. package/dist/assets/Portal.js +110 -0
  14. package/dist/assets/PreferenceInput.js +1545 -1366
  15. package/dist/assets/Typography.js +292 -0
  16. package/dist/assets/WebPushOptInMessage.js +794 -407
  17. package/dist/assets/channelUtils.js +33 -65
  18. package/dist/assets/createSimplePaletteValueFilter.js +17 -0
  19. package/dist/assets/createSvgIcon.js +248 -0
  20. package/dist/assets/integerPropType.js +31 -0
  21. package/dist/assets/main.css +1 -0
  22. package/dist/assets/resolveComponentProps.js +93 -0
  23. package/dist/assets/useSlotProps.js +24 -0
  24. package/dist/assets/useTheme.js +10 -0
  25. package/dist/assets/useTheme2.js +16 -0
  26. package/dist/assets/utils.js +743 -0
  27. package/dist/components/Notifications/DefaultEmpty.d.ts +3 -0
  28. package/dist/components/Notifications/DefaultEmpty.js +7 -0
  29. package/dist/components/Notifications/Inbox.d.ts +4 -4
  30. package/dist/components/Notifications/Inbox.js +9 -6450
  31. package/dist/components/Notifications/InboxHeader.d.ts +1 -1
  32. package/dist/components/Notifications/InboxHeader.js +7 -53
  33. package/dist/components/Notifications/Notification.d.ts +3 -4
  34. package/dist/components/Notifications/Notification.js +6 -5
  35. package/dist/components/Notifications/NotificationCounter.js +16 -6
  36. package/dist/components/Notifications/NotificationFeed.d.ts +1 -2
  37. package/dist/components/Notifications/NotificationFeed.js +41 -38
  38. package/dist/components/Notifications/NotificationLauncher.d.ts +1 -0
  39. package/dist/components/Notifications/NotificationLauncher.js +100 -114
  40. package/dist/components/Notifications/NotificationPopup.d.ts +3 -4
  41. package/dist/components/Notifications/NotificationPopup.js +86 -88
  42. package/dist/components/Notifications/UnreadBadge.d.ts +7 -4
  43. package/dist/components/Notifications/UnreadBadge.js +28 -20
  44. package/dist/components/Notifications/interface.d.ts +0 -4
  45. package/dist/components/Notifications/interface.js +4 -5
  46. package/dist/components/Preferences/NotificationPreferencesInline.js +14 -14
  47. package/dist/components/Preferences/NotificationPreferencesPopup.js +7 -2068
  48. package/dist/components/Preferences/PreferenceInput.js +4 -3
  49. package/dist/components/Preferences/Preferences.js +1042 -547
  50. package/dist/components/Preferences/channelUtils.js +3 -4
  51. package/dist/components/Preferences/index.js +1 -1
  52. package/dist/components/Provider/context.d.ts +27 -0
  53. package/dist/components/Provider/context.js +7 -0
  54. package/dist/components/Provider/index.d.ts +2 -25
  55. package/dist/components/Provider/index.js +90 -82
  56. package/dist/components/WebPush/WebPushOptInMessage.js +3 -4
  57. package/dist/main.d.ts +1 -0
  58. package/dist/main.js +5 -5
  59. package/package.json +25 -9
  60. package/dist/assets/AntdIcon.js +0 -200
  61. package/dist/assets/CloseOutlined.js +0 -13
  62. package/dist/assets/PurePanel.js +0 -59
  63. package/dist/assets/RightOutlined.js +0 -13
  64. package/dist/assets/button.js +0 -1660
  65. package/dist/assets/colors.js +0 -36
  66. package/dist/assets/compact-item.js +0 -860
  67. package/dist/assets/index.js +0 -271
  68. package/dist/assets/index2.js +0 -647
  69. package/dist/assets/index3.js +0 -7527
  70. package/dist/assets/pickAttrs.js +0 -42
  71. package/dist/assets/presets.js +0 -810
  72. package/dist/assets/reactNode.js +0 -20821
@@ -1,8 +1,7 @@
1
1
  import "react/jsx-runtime";
2
- import "../../assets/presets.js";
3
2
  import "../Notifications/interface.js";
4
- import { a as r, g as m } from "../../assets/channelUtils.js";
3
+ import { a as t, g as r } from "../../assets/channelUtils.js";
5
4
  export {
6
- r as getChannelIcon,
7
- m as getChannelLabel
5
+ t as getChannelIcon,
6
+ r as getChannelLabel
8
7
  };
@@ -1,4 +1,4 @@
1
- import { NotificationPreferencesPopup as r } from "./NotificationPreferencesPopup.js";
1
+ import { N as r } from "../../assets/NotificationPreferencesPopup.js";
2
2
  import { NotificationPreferencesInline as f } from "./NotificationPreferencesInline.js";
3
3
  export {
4
4
  f as NotificationPreferencesInline,
@@ -0,0 +1,27 @@
1
+ import { NotificationAPIClientSDK } from '@notificationapi/core';
2
+ import { BaseDeliveryOptions, Channels, DeliveryOptionsForEmail, DeliveryOptionsForInappWeb, GetPreferencesResponse, InAppNotification, UserAccountMetadata } from '@notificationapi/core/dist/interfaces';
3
+
4
+ export type Context = {
5
+ notifications?: InAppNotification[];
6
+ preferences?: GetPreferencesResponse;
7
+ userAccountMetaData?: {
8
+ userAccountMetadata: UserAccountMetadata;
9
+ };
10
+ webPushOptInMessage?: 'AUTOMATIC' | boolean;
11
+ loadNotifications: (initial?: boolean) => void;
12
+ markAsOpened: () => void;
13
+ markAsArchived: (ids: string[] | 'ALL') => void;
14
+ markAsUnarchived: (ids: string[] | 'ALL') => void;
15
+ markAsClicked: (ids: string[]) => void;
16
+ updateDelivery: (notificationId: string, channel: Channels, delivery: DeliveryOptionsForEmail | DeliveryOptionsForInappWeb | BaseDeliveryOptions, subNotificationId?: string) => void;
17
+ updateDeliveries: (params: {
18
+ notificationId: string;
19
+ channel: Channels;
20
+ delivery: DeliveryOptionsForEmail | DeliveryOptionsForInappWeb | BaseDeliveryOptions;
21
+ subNotificationId?: string;
22
+ }[]) => void;
23
+ getClient: () => typeof NotificationAPIClientSDK;
24
+ setWebPushOptInMessage: React.Dispatch<React.SetStateAction<'AUTOMATIC' | boolean>>;
25
+ setWebPushOptIn: React.Dispatch<React.SetStateAction<boolean>>;
26
+ };
27
+ export declare const NotificationAPIContext: import('react').Context<Context | undefined>;
@@ -0,0 +1,7 @@
1
+ import { createContext as t } from "react";
2
+ const e = t(
3
+ void 0
4
+ );
5
+ export {
6
+ e as NotificationAPIContext
7
+ };
@@ -1,31 +1,8 @@
1
1
  import { PropsWithChildren } from 'react';
2
2
  import { NotificationAPIClientSDK } from '@notificationapi/core';
3
- import { GetPreferencesResponse, InAppNotification, User, UserAccountMetadata, BaseDeliveryOptions, Channels, DeliveryOptionsForEmail, DeliveryOptionsForInappWeb } from '@notificationapi/core/dist/interfaces';
3
+ import { User } from '@notificationapi/core/dist/interfaces';
4
+ import { Context } from './context';
4
5
 
5
- export type Context = {
6
- notifications?: InAppNotification[];
7
- preferences?: GetPreferencesResponse;
8
- userAccountMetaData?: {
9
- userAccountMetadata: UserAccountMetadata;
10
- };
11
- webPushOptInMessage?: 'AUTOMATIC' | boolean;
12
- loadNotifications: (initial?: boolean) => void;
13
- markAsOpened: () => void;
14
- markAsArchived: (ids: string[] | 'ALL') => void;
15
- markAsUnarchived: (ids: string[] | 'ALL') => void;
16
- markAsClicked: (ids: string[]) => void;
17
- updateDelivery: (notificationId: string, channel: Channels, delivery: DeliveryOptionsForEmail | DeliveryOptionsForInappWeb | BaseDeliveryOptions, subNotificationId?: string) => void;
18
- updateDeliveries: (params: {
19
- notificationId: string;
20
- channel: Channels;
21
- delivery: DeliveryOptionsForEmail | DeliveryOptionsForInappWeb | BaseDeliveryOptions;
22
- subNotificationId?: string;
23
- }[]) => void;
24
- getClient: () => typeof NotificationAPIClientSDK;
25
- setWebPushOptInMessage: React.Dispatch<React.SetStateAction<'AUTOMATIC' | boolean>>;
26
- setWebPushOptIn: React.Dispatch<React.SetStateAction<boolean>>;
27
- };
28
- export declare const NotificationAPIContext: import('react').Context<Context | undefined>;
29
6
  type Props = ({
30
7
  userId: string;
31
8
  } | {
@@ -1,8 +1,9 @@
1
- import { jsx as z } from "react/jsx-runtime";
2
- import { createContext as Q, useState as I, useCallback as m, useMemo as X, useRef as T, useEffect as S, useContext as Y } from "react";
3
- const Z = async (e, r, o, a, f, b, h) => {
4
- const l = ee(a, f, b), g = await fetch(
5
- `https://${r}/${a}/users/${encodeURIComponent(
1
+ import { jsx as Q } from "react/jsx-runtime";
2
+ import { useState as I, useCallback as m, useMemo as X, useRef as T, useEffect as P, useContext as Y } from "react";
3
+ import { NotificationAPIContext as H } from "./context.js";
4
+ const Z = async (e, c, o, a, f, N, h) => {
5
+ const l = ee(a, f, N), g = await fetch(
6
+ `https://${c}/${a}/users/${encodeURIComponent(
6
7
  f
7
8
  )}/${o}`,
8
9
  {
@@ -18,7 +19,7 @@ const Z = async (e, r, o, a, f, b, h) => {
18
19
  } catch {
19
20
  return;
20
21
  }
21
- }, ee = (e, r, o) => btoa(o ? e + ":" + r + ":" + o : e + ":" + r), H = {
22
+ }, ee = (e, c, o) => btoa(o ? e + ":" + c + ":" + o : e + ":" + c), q = {
22
23
  host: "api.notificationapi.com",
23
24
  websocketHost: "ws.notificationapi.com",
24
25
  userId: "",
@@ -32,18 +33,18 @@ const Z = async (e, r, o, a, f, b, h) => {
32
33
  keepWebSocketAliveForSeconds: 86400
33
34
  // 24 hours
34
35
  }, i = {
35
- config: H,
36
+ config: q,
36
37
  init: function(e) {
37
- return this.config = { ...H, ...e }, {
38
+ return this.config = { ...q, ...e }, {
38
39
  ...this
39
40
  };
40
41
  },
41
42
  rest: {
42
- generic: function(e, r, o) {
43
+ generic: function(e, c, o) {
43
44
  return Z(
44
45
  e,
45
46
  i.config.host,
46
- r,
47
+ c,
47
48
  i.config.clientId,
48
49
  i.config.userId,
49
50
  i.config.hashedUserId,
@@ -53,10 +54,10 @@ const Z = async (e, r, o, a, f, b, h) => {
53
54
  // The functions below are nice wrappers over the generic
54
55
  // rest api function above. They must follow REST API naming:
55
56
  // Method + Resource, representing the end-point.
56
- getNotifications: function(e, r) {
57
+ getNotifications: function(e, c) {
57
58
  return i.rest.generic(
58
59
  "GET",
59
- `notifications/INAPP_WEB?count=${r}&before=${e}`
60
+ `notifications/INAPP_WEB?count=${c}&before=${e}`
60
61
  );
61
62
  },
62
63
  patchNotifications: function(e) {
@@ -87,8 +88,8 @@ const Z = async (e, r, o, a, f, b, h) => {
87
88
  object: void 0,
88
89
  connect: function() {
89
90
  let e = `wss://${i.config.websocketHost}?userId=${encodeURIComponent(i.config.userId)}&envId=${i.config.clientId}`;
90
- return i.config.hashedUserId && (e += `&userIdHash=${encodeURIComponent(i.config.hashedUserId)}`), i.websocket.object = new WebSocket(e), i.websocket.object.onmessage = (r) => {
91
- const o = JSON.parse(r.data);
91
+ return i.config.hashedUserId && (e += `&userIdHash=${encodeURIComponent(i.config.hashedUserId)}`), i.websocket.object = new WebSocket(e), i.websocket.object.onmessage = (c) => {
92
+ const o = JSON.parse(c.data);
92
93
  if (!(!o || !o.route) && o.route === "inapp_web/new_notifications") {
93
94
  const a = o;
94
95
  i.config.onNewInAppNotifications && i.config.onNewInAppNotifications(
@@ -98,8 +99,8 @@ const Z = async (e, r, o, a, f, b, h) => {
98
99
  }, i.websocket.object;
99
100
  },
100
101
  disconnect: function(e) {
101
- var r;
102
- i.websocket.object && ((r = i.websocket.object) == null || r.close(), e && e(i.websocket.object));
102
+ var c;
103
+ i.websocket.object && ((c = i.websocket.object) == null || c.close(), e && e(i.websocket.object));
103
104
  }
104
105
  },
105
106
  openWebSocket: function() {
@@ -118,31 +119,31 @@ const Z = async (e, r, o, a, f, b, h) => {
118
119
  // They may or may not do additional tasks.
119
120
  // e.g. identify simply maps to postUsers
120
121
  getInAppNotifications: async (e) => {
121
- const r = e.maxCountNeeded || i.config.getInAppDefaultCount, o = e.oldestNeeded || i.config.getInAppDefaultOldest;
122
- let a = [], f = e.before, b = !0, h = !0;
122
+ const c = e.maxCountNeeded || i.config.getInAppDefaultCount, o = e.oldestNeeded || i.config.getInAppDefaultOldest;
123
+ let a = [], f = e.before, N = !0, h = !0;
123
124
  for (; h; ) {
124
125
  const l = (await i.rest.getNotifications(
125
126
  f,
126
- r
127
+ c
127
128
  )).notifications.filter(
128
129
  (g) => !a.find((w) => w.id === g.id)
129
130
  );
130
131
  f = l.reduce(
131
132
  (g, w) => g < w.date ? g : w.date,
132
133
  e.before
133
- ), a = [...a, ...l], b = l.length > 0, h = !0, (!b || a.length >= r || f < o) && (h = !1);
134
+ ), a = [...a, ...l], N = l.length > 0, h = !0, (!N || a.length >= c || f < o) && (h = !1);
134
135
  }
135
136
  return {
136
137
  items: a,
137
- hasMore: b,
138
+ hasMore: N,
138
139
  oldestReceived: f
139
140
  };
140
141
  },
141
142
  updateInAppNotifications: async (e) => {
142
- const r = {
143
+ const c = {
143
144
  trackingIds: e.ids
144
145
  };
145
- return e.archived === !0 ? r.archived = (/* @__PURE__ */ new Date()).toISOString() : e.archived === !1 && (r.archived = null), e.clicked === !0 ? r.clicked = (/* @__PURE__ */ new Date()).toISOString() : e.clicked === !1 && (r.clicked = null), e.opened === !0 ? r.opened = (/* @__PURE__ */ new Date()).toISOString() : e.opened === !1 && (r.opened = null), i.rest.patchNotifications(r);
146
+ return e.archived === !0 ? c.archived = (/* @__PURE__ */ new Date()).toISOString() : e.archived === !1 && (c.archived = null), e.clicked === !0 ? c.clicked = (/* @__PURE__ */ new Date()).toISOString() : e.clicked === !1 && (c.clicked = null), e.opened === !0 ? c.opened = (/* @__PURE__ */ new Date()).toISOString() : e.opened === !1 && (c.opened = null), i.rest.patchNotifications(c);
146
147
  },
147
148
  getPreferences: async () => i.rest.getPreferences(),
148
149
  updateDeliveryOption: async (e) => i.rest.postPreferences([e]),
@@ -154,9 +155,7 @@ const Z = async (e, r, o, a, f, b, h) => {
154
155
  return i.rest.postUser(e);
155
156
  },
156
157
  getUserAccountMetadata: async () => i.rest.getUserAccountMetadata()
157
- }, F = Q(
158
- void 0
159
- ), te = (e) => {
158
+ }, F = typeof window < "u", te = (e) => {
160
159
  const o = {
161
160
  ...{
162
161
  apiURL: "https://api.notificationapi.com",
@@ -170,7 +169,7 @@ const Z = async (e, r, o, a, f, b, h) => {
170
169
  },
171
170
  ...e,
172
171
  user: "userId" in e ? { id: e.userId } : e.user
173
- }, [a, f] = I(), [b, h] = I(), [l, g] = I(), [w, P] = I(!1), [k, C] = I((/* @__PURE__ */ new Date()).toISOString()), [A, U] = I(!0), [v, N] = I(o.webPushOptInMessage), [x, J] = I(!1), W = m(() => {
172
+ }, [a, f] = I(), [N, h] = I(), [l, g] = I(), [w, S] = I(!1), [k, C] = I((/* @__PURE__ */ new Date()).toISOString()), [A, U] = I(!0), [v, b] = I(o.webPushOptInMessage), [W, J] = I(!1), x = m(() => {
174
173
  o.playSoundOnNewNotification && new Audio(o.newNotificationSoundPath).play().catch((s) => {
175
174
  console.log("Failed to play new notification sound:", s);
176
175
  });
@@ -179,17 +178,17 @@ const Z = async (e, r, o, a, f, b, h) => {
179
178
  f((n) => (t = Array.isArray(t) ? t : [], t = t.filter((d) => {
180
179
  const p = d.expDate && new Date(d.expDate * 1e3).toISOString() < s, D = new Date(d.date).getTime() > new Date(s).getTime() + 1e3;
181
180
  return !p && !D;
182
- }), Array.isArray(n) ? [
181
+ }), n = Array.isArray(n) ? n : [], [
183
182
  ...t.filter((d) => !n.find((D) => D.id === d.id)),
184
183
  ...n
185
- ] : t));
184
+ ]));
186
185
  }, []), u = X(() => {
187
186
  const t = e.client ? e.client : i.init({
188
187
  clientId: o.clientId,
189
188
  userId: o.user.id,
190
189
  hashedUserId: o.hashedUserId,
191
190
  onNewInAppNotifications: (s) => {
192
- W(), y(s);
191
+ x(), y(s);
193
192
  }
194
193
  });
195
194
  return t.identify({
@@ -203,44 +202,44 @@ const Z = async (e, r, o, a, f, b, h) => {
203
202
  o.user.number,
204
203
  o.hashedUserId,
205
204
  y,
206
- W,
205
+ x,
207
206
  e.client
208
- ]), L = m(
207
+ ]), E = m(
209
208
  async (t, s) => {
210
209
  const n = await u.rest.getNotifications(t, s);
211
210
  C(n.oldestReceived), U(n.couldLoadMore), y(n.notifications);
212
211
  },
213
212
  [y, u.rest]
214
- ), E = T(A), R = T(w), $ = T(k);
215
- S(() => {
216
- E.current = A, R.current = w, $.current = k;
213
+ ), L = T(A), R = T(w), $ = T(k);
214
+ P(() => {
215
+ L.current = A, R.current = w, $.current = k;
217
216
  }, [A, w, k]);
218
217
  const O = m(
219
218
  async (t) => {
220
- if (!(!t && (!E.current || R.current))) {
221
- P(!0);
219
+ if (!(!t && (!L.current || R.current))) {
220
+ S(!0);
222
221
  try {
223
- await L(
222
+ await E(
224
223
  t ? (/* @__PURE__ */ new Date()).toISOString() : $.current,
225
224
  t ? o.initialLoadMaxCount : 1e3
226
225
  );
227
226
  } finally {
228
- P(!1);
227
+ S(!1);
229
228
  }
230
229
  }
231
230
  },
232
- [o.initialLoadMaxCount, L]
233
- ), q = async (t) => {
231
+ [o.initialLoadMaxCount, E]
232
+ ), B = async (t) => {
234
233
  if (!a) return;
235
- const s = (/* @__PURE__ */ new Date()).toISOString(), n = a.filter((c) => t.includes(c.id) && !c.clicked).map((c) => c.id);
236
- u.updateInAppNotifications({ ids: n, clicked: !0 }), f((c) => {
237
- if (!c) return [];
238
- const d = [...c];
234
+ const s = (/* @__PURE__ */ new Date()).toISOString(), n = a.filter((r) => t.includes(r.id) && !r.clicked).map((r) => r.id);
235
+ u.updateInAppNotifications({ ids: n, clicked: !0 }), f((r) => {
236
+ if (!r) return [];
237
+ const d = [...r];
239
238
  return d.filter((p) => n.includes(p.id)).forEach((p) => {
240
239
  p.clicked = s;
241
240
  }), d;
242
241
  });
243
- }, B = async () => {
242
+ }, G = async () => {
244
243
  if (!a) return;
245
244
  const t = (/* @__PURE__ */ new Date()).toISOString(), s = a.filter((n) => !n.opened || !n.seen).map((n) => n.id);
246
245
  s.length !== 0 && (u.updateInAppNotifications({
@@ -248,12 +247,12 @@ const Z = async (e, r, o, a, f, b, h) => {
248
247
  opened: !0
249
248
  }), f((n) => {
250
249
  if (!n) return [];
251
- const c = [...n];
252
- return c.filter((d) => s.includes(d.id)).forEach((d) => {
250
+ const r = [...n];
251
+ return r.filter((d) => s.includes(d.id)).forEach((d) => {
253
252
  d.opened = t, d.seen = !0;
254
- }), c;
253
+ }), r;
255
254
  }));
256
- }, G = async (t) => {
255
+ }, K = async (t) => {
257
256
  if (!a) return;
258
257
  const s = a.filter((n) => n.archived && (t === "ALL" || t.includes(n.id))).map((n) => n.id);
259
258
  s.length !== 0 && (u.updateInAppNotifications({
@@ -261,27 +260,27 @@ const Z = async (e, r, o, a, f, b, h) => {
261
260
  archived: !1
262
261
  }), f((n) => {
263
262
  if (!n) return [];
264
- const c = [...n];
265
- return c.filter((d) => s.includes(d.id)).forEach((d) => {
263
+ const r = [...n];
264
+ return r.filter((d) => s.includes(d.id)).forEach((d) => {
266
265
  d.archived = void 0;
267
- }), c;
266
+ }), r;
268
267
  }));
269
- }, K = async (t) => {
268
+ }, V = async (t) => {
270
269
  if (!a) return;
271
- const s = (/* @__PURE__ */ new Date()).toISOString(), n = a.filter((c) => !c.archived && (t === "ALL" || t.includes(c.id))).map((c) => c.id);
272
- n.length !== 0 && (u.updateInAppNotifications({ ids: n, archived: !0 }), f((c) => {
273
- if (!c) return [];
274
- const d = [...c];
270
+ const s = (/* @__PURE__ */ new Date()).toISOString(), n = a.filter((r) => !r.archived && (t === "ALL" || t.includes(r.id))).map((r) => r.id);
271
+ n.length !== 0 && (u.updateInAppNotifications({ ids: n, archived: !0 }), f((r) => {
272
+ if (!r) return [];
273
+ const d = [...r];
275
274
  return d.filter((p) => n.includes(p.id)).forEach((p) => {
276
275
  p.archived = s;
277
276
  }), d;
278
277
  }));
279
- }, V = (t, s, n, c) => j([
278
+ }, _ = (t, s, n, r) => j([
280
279
  {
281
280
  notificationId: t,
282
281
  channel: s,
283
282
  delivery: n,
284
- subNotificationId: c
283
+ subNotificationId: r
285
284
  }
286
285
  ]), j = (t) => {
287
286
  u.rest.postPreferences(t).then(() => {
@@ -291,12 +290,12 @@ const Z = async (e, r, o, a, f, b, h) => {
291
290
  });
292
291
  }, M = m(() => {
293
292
  "serviceWorker" in navigator && navigator.serviceWorker.register(o.customServiceWorkerPath).then(async (t) => {
294
- N(!1), Notification.requestPermission().then(async (s) => {
293
+ b(!1), ie().then(async (s) => {
295
294
  s === "granted" ? await t.pushManager.subscribe({
296
295
  userVisibleOnly: !0,
297
296
  applicationServerKey: l == null ? void 0 : l.userAccountMetadata.environmentVapidPublicKey
298
297
  }).then(async (n) => {
299
- const c = {
298
+ const r = {
300
299
  webPushTokens: [
301
300
  {
302
301
  sub: {
@@ -306,7 +305,7 @@ const Z = async (e, r, o, a, f, b, h) => {
306
305
  }
307
306
  ]
308
307
  };
309
- await u.identify(c), console.log("index"), localStorage.setItem("hideWebPushOptInMessage", "true");
308
+ await u.identify(r), console.log("index"), localStorage.setItem("hideWebPushOptInMessage", "true");
310
309
  }) : s === "denied" && console.log("Permission for notifications was denied");
311
310
  });
312
311
  }).catch((t) => {
@@ -327,44 +326,53 @@ const Z = async (e, r, o, a, f, b, h) => {
327
326
  o.customServiceWorkerPath,
328
327
  l == null ? void 0 : l.userAccountMetadata.environmentVapidPublicKey
329
328
  ]);
330
- S(() => {
331
- f([]), P(!1), h(void 0), C((/* @__PURE__ */ new Date()).toISOString()), U(!0), O(!0), u.openWebSocket(), u.getPreferences().then((t) => {
329
+ P(() => {
330
+ f([]), S(!1), h(void 0), C((/* @__PURE__ */ new Date()).toISOString()), U(!0), O(!0), u.openWebSocket(), u.getPreferences().then((t) => {
332
331
  h(t);
333
332
  });
334
- }, [u, O, M]), S(() => {
335
- Notification.permission !== "default" && N(!1), v === "AUTOMATIC" && (N(
333
+ }, [u, O, M]), P(() => {
334
+ F && "Notification" in window && typeof Notification.requestPermission == "function" && Notification.permission !== "default" && b(!1), v === "AUTOMATIC" && (b(
336
335
  localStorage.getItem("hideWebPushOptInMessage") !== "true"
337
336
  ), u.getUserAccountMetadata().then((t) => {
338
- g(t), N(t.userAccountMetadata.hasWebPushEnabled);
337
+ g(t), b(t.userAccountMetadata.hasWebPushEnabled);
339
338
  }));
340
- }, [u, v]), S(() => {
341
- x && M();
342
- }, [x, M]);
343
- const _ = {
339
+ }, [u, v]), P(() => {
340
+ W && M();
341
+ }, [W, M]);
342
+ const z = {
344
343
  notifications: a,
345
- preferences: b,
344
+ preferences: N,
346
345
  userAccountMetaData: l,
347
346
  webPushOptInMessage: v,
348
347
  loadNotifications: O,
349
- markAsOpened: B,
350
- markAsArchived: K,
351
- markAsUnarchived: G,
352
- markAsClicked: q,
353
- updateDelivery: V,
348
+ markAsOpened: G,
349
+ markAsArchived: V,
350
+ markAsUnarchived: K,
351
+ markAsClicked: B,
352
+ updateDelivery: _,
354
353
  updateDeliveries: j,
355
354
  getClient: () => u,
356
- setWebPushOptInMessage: N,
355
+ setWebPushOptInMessage: b,
357
356
  setWebPushOptIn: J
358
357
  };
359
- return /* @__PURE__ */ z(F.Provider, { value: _, children: e.children });
358
+ return /* @__PURE__ */ Q(H.Provider, { value: z, children: e.children });
360
359
  }, ne = () => {
361
- const e = Y(F);
360
+ const e = Y(H);
362
361
  if (!e)
363
362
  throw new Error("useMyContext must be used within a MyProvider");
364
363
  return e;
365
364
  };
366
365
  te.useNotificationAPIContext = ne;
366
+ const ie = async () => {
367
+ if (F && "Notification" in window && typeof Notification.requestPermission == "function")
368
+ try {
369
+ return await Notification.requestPermission();
370
+ } catch (e) {
371
+ return console.error("Error requesting notification permission:", e), "default";
372
+ }
373
+ else
374
+ return console.warn("Web Push Notifications are not supported in this browser."), "default";
375
+ };
367
376
  export {
368
- F as NotificationAPIContext,
369
377
  te as NotificationAPIProvider
370
378
  };
@@ -1,8 +1,7 @@
1
1
  import "react/jsx-runtime";
2
2
  import "react";
3
- import "../Provider/index.js";
4
- import { W as a } from "../../assets/WebPushOptInMessage.js";
5
- import "../../assets/button.js";
3
+ import "../Provider/context.js";
4
+ import { W as i } from "../../assets/WebPushOptInMessage.js";
6
5
  export {
7
- a as default
6
+ i as default
8
7
  };
package/dist/main.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+
1
2
  export { NotificationFeed, NotificationPopup, NotificationLauncher, NotificationCounter } from './components/Notifications';
2
3
  export { NotificationPreferencesInline, NotificationPreferencesPopup } from './components/Preferences';
3
4
  export { NotificationAPIProvider } from './components/Provider';
package/dist/main.js CHANGED
@@ -2,15 +2,15 @@ import { NotificationFeed as r } from "./components/Notifications/NotificationFe
2
2
  import { NotificationPopup as e } from "./components/Notifications/NotificationPopup.js";
3
3
  import { NotificationLauncher as n } from "./components/Notifications/NotificationLauncher.js";
4
4
  import { NotificationCounter as c } from "./components/Notifications/NotificationCounter.js";
5
- import { NotificationPreferencesPopup as m } from "./components/Preferences/NotificationPreferencesPopup.js";
6
- import { NotificationPreferencesInline as N } from "./components/Preferences/NotificationPreferencesInline.js";
5
+ import { N } from "./assets/NotificationPreferencesPopup.js";
6
+ import { NotificationPreferencesInline as x } from "./components/Preferences/NotificationPreferencesInline.js";
7
7
  import { NotificationAPIProvider as u } from "./components/Provider/index.js";
8
- export {
8
+ import './assets/main.css';export {
9
9
  u as NotificationAPIProvider,
10
10
  c as NotificationCounter,
11
11
  r as NotificationFeed,
12
12
  n as NotificationLauncher,
13
13
  e as NotificationPopup,
14
- N as NotificationPreferencesInline,
15
- m as NotificationPreferencesPopup
14
+ x as NotificationPreferencesInline,
15
+ N as NotificationPreferencesPopup
16
16
  };
package/package.json CHANGED
@@ -1,8 +1,19 @@
1
1
  {
2
2
  "name": "@notificationapi/react",
3
3
  "private": false,
4
- "version": "0.0.36",
4
+ "version": "1.0.0",
5
5
  "type": "module",
6
+ "browserslist": [
7
+ "last 2 versions",
8
+ "last 2 ChromeAndroid versions",
9
+ "last 2 FirefoxAndroid versions",
10
+ "last 2 Safari versions",
11
+ "last 2 iOS versions",
12
+ "not IE >= 1",
13
+ "not bb >=1",
14
+ "not IE_Mob >=1",
15
+ "not op_mini all"
16
+ ],
6
17
  "scripts": {
7
18
  "dev": "vite",
8
19
  "build": "tsc --p ./tsconfig.build.json && vite build",
@@ -13,20 +24,22 @@
13
24
  "prepublishOnly": "npm run build"
14
25
  },
15
26
  "peerDependencies": {
16
- "react": "^17.0.2",
17
- "react-dom": "^17.0.2"
27
+ "react": "^17.0.2 || ^18.0.0 || ^19.0.0",
28
+ "react-dom": "^17.0.2 || ^18.0.0 || ^19.0.0"
18
29
  },
19
30
  "devDependencies": {
20
- "@ant-design/icons": "^5.3.6",
31
+ "@faker-js/faker": "^9.2.0",
21
32
  "@types/node": "^20.12.7",
22
- "@types/react": "^17.0.38",
23
- "@types/react-dom": "^17.0.11",
33
+ "@types/react": "^19.0.0",
34
+ "@types/react-dom": "^19.0.0",
24
35
  "@typescript-eslint/eslint-plugin": "^7.2.0",
25
36
  "@typescript-eslint/parser": "^7.2.0",
26
37
  "@vitejs/plugin-react": "^4.2.1",
27
38
  "eslint": "^8.57.0",
39
+ "eslint-plugin-compat": "^6.0.1",
28
40
  "eslint-plugin-react-hooks": "^4.6.0",
29
41
  "eslint-plugin-react-refresh": "^0.4.6",
42
+ "faker-js": "^1.0.0",
30
43
  "glob": "^10.4.1",
31
44
  "prettier": "^3.3.3",
32
45
  "typescript": "^5.2.2",
@@ -43,12 +56,15 @@
43
56
  "**/*.css"
44
57
  ],
45
58
  "dependencies": {
59
+ "@emotion/react": "^11.14.0",
60
+ "@emotion/styled": "^11.14.0",
61
+ "@fontsource/roboto": "^5.1.1",
62
+ "@mui/icons-material": "^6.3.1",
63
+ "@mui/material": "^6.3.1",
46
64
  "@notificationapi/core": "^0.0.12",
47
- "antd": "^5.17.4",
48
65
  "javascript-time-ago": "^2.5.10",
49
66
  "liquidjs": "^10.14.0",
50
67
  "rc-virtual-list": "^3.11.5",
51
- "react-time-ago": "^7.3.3",
52
- "styled-components": "^6.1.9"
68
+ "react-time-ago": "^7.3.3"
53
69
  }
54
70
  }