@notificationapi/react 0.0.31 → 0.0.33

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 (29) hide show
  1. package/dist/assets/AntdIcon.js +4 -4
  2. package/dist/assets/Notification.js +3094 -2713
  3. package/dist/assets/PurePanel.js +2 -2
  4. package/dist/assets/RightOutlined.js +1 -1
  5. package/dist/assets/button.js +1394 -577
  6. package/dist/assets/channelUtils.js +1 -1
  7. package/dist/assets/colors.js +14798 -14301
  8. package/dist/assets/index.js +156 -158
  9. package/dist/assets/index2.js +212 -221
  10. package/dist/assets/index3.js +8307 -724
  11. package/dist/assets/pickAttrs.js +1 -1
  12. package/dist/assets/presets.js +810 -0
  13. package/dist/components/Notifications/Inbox.js +3520 -3323
  14. package/dist/components/Notifications/InboxHeader.d.ts +1 -2
  15. package/dist/components/Notifications/InboxHeader.js +2 -2
  16. package/dist/components/Notifications/Notification.js +1 -1
  17. package/dist/components/Notifications/NotificationFeed.js +1 -2
  18. package/dist/components/Preferences/NotificationPreferencesInline.d.ts +1 -2
  19. package/dist/components/Preferences/NotificationPreferencesPopup.d.ts +1 -2
  20. package/dist/components/Preferences/NotificationPreferencesPopup.js +1423 -857
  21. package/dist/components/Preferences/PreferenceInput.d.ts +1 -1
  22. package/dist/components/Preferences/PreferenceInput.js +843 -812
  23. package/dist/components/Preferences/Preferences.d.ts +1 -2
  24. package/dist/components/Preferences/Preferences.js +331 -328
  25. package/dist/components/Preferences/channelUtils.js +1 -1
  26. package/dist/components/Provider/index.d.ts +1 -0
  27. package/dist/components/Provider/index.js +27 -34
  28. package/package.json +5 -5
  29. package/dist/assets/index4.js +0 -8408
@@ -1,5 +1,5 @@
1
1
  import "react/jsx-runtime";
2
- import "../../assets/index3.js";
2
+ import "../../assets/presets.js";
3
3
  import "../Notifications/interface.js";
4
4
  import { a as r, g as m } from "../../assets/channelUtils.js";
5
5
  export {
@@ -33,6 +33,7 @@ type Props = ({
33
33
  initialLoadMaxAge?: Date;
34
34
  playSoundOnNewNotification?: boolean;
35
35
  newNotificationSoundPath?: string;
36
+ client?: typeof NotificationAPIClientSDK;
36
37
  };
37
38
  export declare const NotificationAPIProvider: React.FunctionComponent<PropsWithChildren<Props>> & {
38
39
  useNotificationAPIContext: typeof useNotificationAPIContext;
@@ -1,15 +1,15 @@
1
1
  import { jsx as B } from "react/jsx-runtime";
2
2
  import { createContext as z, useState as N, useCallback as m, useMemo as F, useRef as k, useEffect as U, useContext as G } from "react";
3
- const J = async (e, s, i, a, f, w, p) => {
4
- const h = _(a, f, w), l = await fetch(
3
+ const J = async (e, s, i, a, f, w, h) => {
4
+ const p = _(a, f, w), l = await fetch(
5
5
  `https://${s}/${a}/users/${encodeURIComponent(
6
6
  f
7
7
  )}/${i}`,
8
8
  {
9
9
  method: e,
10
- body: JSON.stringify(p),
10
+ body: JSON.stringify(h),
11
11
  headers: {
12
- Authorization: `Basic ${h}`
12
+ Authorization: `Basic ${p}`
13
13
  }
14
14
  }
15
15
  );
@@ -116,18 +116,18 @@ const J = async (e, s, i, a, f, w, p) => {
116
116
  // e.g. identify simply maps to postUsers
117
117
  getInAppNotifications: async (e) => {
118
118
  const s = e.maxCountNeeded || n.config.getInAppDefaultCount, i = e.oldestNeeded || n.config.getInAppDefaultOldest;
119
- let a = [], f = e.before, w = !0, p = !0;
120
- for (; p; ) {
121
- const h = (await n.rest.getNotifications(
119
+ let a = [], f = e.before, w = !0, h = !0;
120
+ for (; h; ) {
121
+ const p = (await n.rest.getNotifications(
122
122
  f,
123
123
  s
124
124
  )).notifications.filter(
125
125
  (l) => !a.find((g) => g.id === l.id)
126
126
  );
127
- f = h.reduce(
127
+ f = p.reduce(
128
128
  (l, g) => l < g.date ? l : g.date,
129
129
  e.before
130
- ), a = [...a, ...h], w = h.length > 0, p = !0, (!w || a.length >= s || f < i) && (p = !1);
130
+ ), a = [...a, ...p], w = p.length > 0, h = !0, (!w || a.length >= s || f < i) && (h = !1);
131
131
  }
132
132
  return {
133
133
  items: a,
@@ -164,7 +164,7 @@ const J = async (e, s, i, a, f, w, p) => {
164
164
  },
165
165
  ...e,
166
166
  user: "userId" in e ? { id: e.userId } : e.user
167
- }, [a, f] = N(), [w, p] = N(), [h, l] = N(!1), [g, y] = N((/* @__PURE__ */ new Date()).toISOString()), [b, P] = N(!0), D = m(() => {
167
+ }, [a, f] = N(), [w, h] = N(), [p, l] = N(!1), [g, y] = N((/* @__PURE__ */ new Date()).toISOString()), [b, P] = N(!0), D = m(() => {
168
168
  i.playSoundOnNewNotification && new Audio(i.newNotificationSoundPath).play().catch((r) => {
169
169
  console.log("Failed to play new notification sound:", r);
170
170
  });
@@ -175,7 +175,7 @@ const J = async (e, s, i, a, f, w, p) => {
175
175
  ...t
176
176
  ] : o));
177
177
  }, []), u = F(() => {
178
- const o = n.init({
178
+ const o = e.client ? e.client : n.init({
179
179
  clientId: i.clientId,
180
180
  userId: i.user.id,
181
181
  hashedUserId: i.hashedUserId,
@@ -194,17 +194,18 @@ const J = async (e, s, i, a, f, w, p) => {
194
194
  i.user.number,
195
195
  i.hashedUserId,
196
196
  S,
197
- D
197
+ D,
198
+ e.client
198
199
  ]), O = m(
199
200
  async (o, r) => {
200
201
  const t = await u.rest.getNotifications(o, r);
201
202
  y(t.oldestReceived), P(t.couldLoadMore), S(t.notifications);
202
203
  },
203
204
  [S, u.rest]
204
- ), v = k(b), C = k(h), x = k(g);
205
+ ), v = k(b), C = k(p), x = k(g);
205
206
  U(() => {
206
- v.current = b, C.current = h, x.current = g;
207
- }, [b, h, g]);
207
+ v.current = b, C.current = p, x.current = g;
208
+ }, [b, p, g]);
208
209
  const A = m(
209
210
  async (o) => {
210
211
  if (!(!o && (!v.current || C.current))) {
@@ -221,54 +222,46 @@ const J = async (e, s, i, a, f, w, p) => {
221
222
  },
222
223
  [i.initialLoadMaxCount, O]
223
224
  ), R = async (o) => {
224
- if (!a)
225
- return;
225
+ if (!a) return;
226
226
  const r = (/* @__PURE__ */ new Date()).toISOString(), t = a.filter((c) => o.includes(c.id) && !c.clicked).map((c) => c.id);
227
227
  u.updateInAppNotifications({ ids: t, clicked: !0 }), f((c) => {
228
- if (!c)
229
- return [];
228
+ if (!c) return [];
230
229
  const d = [...c];
231
230
  return d.filter((I) => t.includes(I.id)).forEach((I) => {
232
231
  I.clicked = r;
233
232
  }), d;
234
233
  });
235
234
  }, $ = async () => {
236
- if (!a)
237
- return;
235
+ if (!a) return;
238
236
  const o = (/* @__PURE__ */ new Date()).toISOString(), r = a.filter((t) => !t.opened || !t.seen).map((t) => t.id);
239
237
  r.length !== 0 && (u.updateInAppNotifications({
240
238
  ids: r,
241
239
  opened: !0
242
240
  }), f((t) => {
243
- if (!t)
244
- return [];
241
+ if (!t) return [];
245
242
  const c = [...t];
246
243
  return c.filter((d) => r.includes(d.id)).forEach((d) => {
247
244
  d.opened = o, d.seen = !0;
248
245
  }), c;
249
246
  }));
250
247
  }, j = async (o) => {
251
- if (!a)
252
- return;
248
+ if (!a) return;
253
249
  const r = a.filter((t) => t.archived && (o === "ALL" || o.includes(t.id))).map((t) => t.id);
254
250
  r.length !== 0 && (u.updateInAppNotifications({
255
251
  ids: r,
256
252
  archived: !1
257
253
  }), f((t) => {
258
- if (!t)
259
- return [];
254
+ if (!t) return [];
260
255
  const c = [...t];
261
256
  return c.filter((d) => r.includes(d.id)).forEach((d) => {
262
257
  d.archived = void 0;
263
258
  }), c;
264
259
  }));
265
260
  }, T = async (o) => {
266
- if (!a)
267
- return;
261
+ if (!a) return;
268
262
  const r = (/* @__PURE__ */ new Date()).toISOString(), t = a.filter((c) => !c.archived && (o === "ALL" || o.includes(c.id))).map((c) => c.id);
269
263
  t.length !== 0 && (u.updateInAppNotifications({ ids: t, archived: !0 }), f((c) => {
270
- if (!c)
271
- return [];
264
+ if (!c) return [];
272
265
  const d = [...c];
273
266
  return d.filter((I) => t.includes(I.id)).forEach((I) => {
274
267
  I.archived = r;
@@ -284,13 +277,13 @@ const J = async (e, s, i, a, f, w, p) => {
284
277
  ]), L = (o) => {
285
278
  u.rest.postPreferences(o).then(() => {
286
279
  u.getPreferences().then((r) => {
287
- p(r);
280
+ h(r);
288
281
  });
289
282
  });
290
283
  };
291
284
  U(() => {
292
- f([]), l(!1), p(void 0), y((/* @__PURE__ */ new Date()).toISOString()), P(!0), A(!0), u.openWebSocket(), u.getPreferences().then((o) => {
293
- p(o);
285
+ f([]), l(!1), h(void 0), y((/* @__PURE__ */ new Date()).toISOString()), P(!0), A(!0), u.openWebSocket(), u.getPreferences().then((o) => {
286
+ h(o);
294
287
  });
295
288
  }, [u, A]);
296
289
  const H = {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@notificationapi/react",
3
3
  "private": false,
4
- "version": "0.0.31",
4
+ "version": "0.0.33",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",
@@ -13,14 +13,14 @@
13
13
  "prepublishOnly": "npm run build"
14
14
  },
15
15
  "peerDependencies": {
16
- "react": "^16.14.0",
17
- "react-dom": "^16.14.0"
16
+ "react": "^17.0.2",
17
+ "react-dom": "^17.0.2"
18
18
  },
19
19
  "devDependencies": {
20
20
  "@ant-design/icons": "^5.3.6",
21
21
  "@types/node": "^20.12.7",
22
- "@types/react": "^16.14.0",
23
- "@types/react-dom": "^16.9.8",
22
+ "@types/react": "^17.0.38",
23
+ "@types/react-dom": "^17.0.11",
24
24
  "@typescript-eslint/eslint-plugin": "^7.2.0",
25
25
  "@typescript-eslint/parser": "^7.2.0",
26
26
  "@vitejs/plugin-react": "^4.2.1",