@college-africa/chat-ui 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { C as e, S as t, T as n, _ as r, a as i, b as a, c as o, d as s, f as c, g as l, h as u, i as d, l as f, m as p, n as m, o as h, p as g, s as _, t as v, u as y, v as b, w as x, x as S, y as C } from "./summaries-CJ-n36dY.js";
1
+ import { C as e, S as t, T as n, _ as r, a as i, b as a, c as o, d as s, f as c, g as l, h as u, i as d, l as f, m as p, n as m, o as h, p as g, s as _, t as v, u as y, v as b, w as x, x as S, y as C } from "./summaries-mMFesyHg.js";
2
2
  import * as w from "react";
3
3
  import T, { Children as E, Component as D, createContext as O, createElement as k, forwardRef as A, useCallback as j, useContext as M, useEffect as N, useLayoutEffect as ee, useMemo as te, useRef as P, useState as F } from "react";
4
4
  import { Alert as I, AlertTitle as ne, AppBar as re, Autocomplete as ie, Avatar as ae, Badge as oe, Box as L, Button as R, Chip as se, CircularProgress as ce, Dialog as le, DialogActions as ue, DialogContent as de, DialogTitle as fe, Divider as pe, Drawer as me, FormControlLabel as he, IconButton as z, InputAdornment as ge, LinearProgress as _e, List as ve, ListItem as ye, ListItemAvatar as be, ListItemButton as xe, ListItemText as Se, Menu as Ce, MenuItem as we, Paper as Te, Select as Ee, Skeleton as De, Snackbar as Oe, Switch as ke, TextField as Ae, Toolbar as je, Tooltip as Me, Typography as B } from "@mui/material";
@@ -5016,13 +5016,13 @@ Kd.defaultProps = { validateOnChange: !0 };
5016
5016
  //#endregion
5017
5017
  //#region ../../node_modules/lodash/isSymbol.js
5018
5018
  var qd = /* @__PURE__ */ x(((e, t) => {
5019
- var n = C(), r = l(), i = "[object Symbol]";
5019
+ var n = b(), r = u(), i = "[object Symbol]";
5020
5020
  function a(e) {
5021
5021
  return typeof e == "symbol" || r(e) && n(e) == i;
5022
5022
  }
5023
5023
  t.exports = a;
5024
5024
  })), Jd = /* @__PURE__ */ x(((e, t) => {
5025
- var n = u(), r = qd(), i = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/, a = /^\w*$/;
5025
+ var n = p(), r = qd(), i = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/, a = /^\w*$/;
5026
5026
  function o(e, t) {
5027
5027
  if (n(e)) return !1;
5028
5028
  var o = typeof e;
@@ -5030,18 +5030,18 @@ var qd = /* @__PURE__ */ x(((e, t) => {
5030
5030
  }
5031
5031
  t.exports = o;
5032
5032
  })), Yd = /* @__PURE__ */ x(((e, t) => {
5033
- var n = r(), i = "Expected a function";
5034
- function a(e, t) {
5035
- if (typeof e != "function" || t != null && typeof t != "function") throw TypeError(i);
5036
- var r = function() {
5037
- var n = arguments, i = t ? t.apply(this, n) : n[0], a = r.cache;
5038
- if (a.has(i)) return a.get(i);
5033
+ var n = l(), r = "Expected a function";
5034
+ function i(e, t) {
5035
+ if (typeof e != "function" || t != null && typeof t != "function") throw TypeError(r);
5036
+ var a = function() {
5037
+ var n = arguments, r = t ? t.apply(this, n) : n[0], i = a.cache;
5038
+ if (i.has(r)) return i.get(r);
5039
5039
  var o = e.apply(this, n);
5040
- return r.cache = a.set(i, o) || a, o;
5040
+ return a.cache = i.set(r, o) || i, o;
5041
5041
  };
5042
- return r.cache = new (a.Cache || n)(), r;
5042
+ return a.cache = new (i.Cache || n)(), a;
5043
5043
  }
5044
- a.Cache = n, t.exports = a;
5044
+ i.Cache = n, t.exports = i;
5045
5045
  })), Xd = /* @__PURE__ */ x(((e, t) => {
5046
5046
  var n = Yd(), r = 500;
5047
5047
  function i(e) {
@@ -5066,15 +5066,15 @@ var qd = /* @__PURE__ */ x(((e, t) => {
5066
5066
  }
5067
5067
  t.exports = n;
5068
5068
  })), $d = /* @__PURE__ */ x(((e, t) => {
5069
- var n = a(), r = Qd(), i = u(), o = qd(), s = Infinity, c = n ? n.prototype : void 0, l = c ? c.toString : void 0;
5070
- function d(e) {
5069
+ var n = C(), r = Qd(), i = p(), a = qd(), o = Infinity, s = n ? n.prototype : void 0, c = s ? s.toString : void 0;
5070
+ function l(e) {
5071
5071
  if (typeof e == "string") return e;
5072
- if (i(e)) return r(e, d) + "";
5073
- if (o(e)) return l ? l.call(e) : "";
5072
+ if (i(e)) return r(e, l) + "";
5073
+ if (a(e)) return c ? c.call(e) : "";
5074
5074
  var t = e + "";
5075
- return t == "0" && 1 / e == -s ? "-0" : t;
5075
+ return t == "0" && 1 / e == -o ? "-0" : t;
5076
5076
  }
5077
- t.exports = d;
5077
+ t.exports = l;
5078
5078
  })), ef = /* @__PURE__ */ x(((e, t) => {
5079
5079
  var n = $d();
5080
5080
  function r(e) {
@@ -5082,7 +5082,7 @@ var qd = /* @__PURE__ */ x(((e, t) => {
5082
5082
  }
5083
5083
  t.exports = r;
5084
5084
  })), tf = /* @__PURE__ */ x(((e, t) => {
5085
- var n = u(), r = Jd(), i = Zd(), a = ef();
5085
+ var n = p(), r = Jd(), i = Zd(), a = ef();
5086
5086
  function o(e, t) {
5087
5087
  return n(e) ? e : r(e, t) ? [e] : i(a(e));
5088
5088
  }
@@ -5216,24 +5216,24 @@ var qd = /* @__PURE__ */ x(((e, t) => {
5216
5216
  let t = new Date(e);
5217
5217
  return `${t.getFullYear()}-${String(t.getMonth() + 1).padStart(2, "0")}-${String(t.getDate()).padStart(2, "0")}`;
5218
5218
  }, df = ({ multiple: e = !1, formik: t, name: n, label: r = "Search users", disabled: a = !1, error: o, helperText: s, value: c, onChange: l }) => {
5219
- let [u, d] = F(!1), [f, m] = F([]), [h, g] = F(!1), [_, v] = F(""), y = j(async (e) => {
5219
+ let [u, d] = F(!1), [f, p] = F([]), [m, h] = F(!1), [g, _] = F(""), v = j(async (e) => {
5220
5220
  if (e.length < 2) {
5221
- m([]);
5221
+ p([]);
5222
5222
  return;
5223
5223
  }
5224
- g(!0);
5224
+ h(!0);
5225
5225
  try {
5226
5226
  let t = i();
5227
5227
  if (!t) return;
5228
- m(await t.searchUsers({ name: e }));
5228
+ p(await t.searchUsers({ name: e }));
5229
5229
  } catch (e) {
5230
- p.error("Failed to search users:", e), m([]);
5230
+ S.error("Failed to search users:", e), p([]);
5231
5231
  } finally {
5232
- g(!1);
5232
+ h(!1);
5233
5233
  }
5234
- }, []), b = j((e, t) => {
5235
- v(t), y(t);
5236
- }, [y]), x = () => c === void 0 ? t && n ? t.values[n] : e ? [] : null : c, S = (e, r) => {
5234
+ }, []), y = j((e, t) => {
5235
+ _(t), v(t);
5236
+ }, [v]), b = () => c === void 0 ? t && n ? t.values[n] : e ? [] : null : c, x = (e, r) => {
5237
5237
  l ? l(r) : t && n && t.setFieldValue(n, r);
5238
5238
  }, C = () => {
5239
5239
  t && n && t.setFieldTouched(n);
@@ -5247,14 +5247,14 @@ var qd = /* @__PURE__ */ x(((e, t) => {
5247
5247
  onClose: () => d(!1),
5248
5248
  multiple: e,
5249
5249
  options: f,
5250
- value: x(),
5251
- onChange: S,
5250
+ value: b(),
5251
+ onChange: x,
5252
5252
  onBlur: C,
5253
- onInputChange: b,
5253
+ onInputChange: y,
5254
5254
  getOptionLabel: (e) => e.name,
5255
5255
  isOptionEqualToValue: (e, t) => e.id === t.id,
5256
- loading: h,
5257
- noOptionsText: _.length < 3 ? "Type at least 3 characters to search" : "No users found",
5256
+ loading: m,
5257
+ noOptionsText: g.length < 3 ? "Type at least 3 characters to search" : "No users found",
5258
5258
  renderOption: (e, t) => /* @__PURE__ */ k(L, {
5259
5259
  component: "li",
5260
5260
  ...e,
@@ -5276,7 +5276,7 @@ var qd = /* @__PURE__ */ x(((e, t) => {
5276
5276
  helperText: w() || s,
5277
5277
  InputProps: {
5278
5278
  ...e.InputProps,
5279
- endAdornment: /* @__PURE__ */ H(Ne, { children: [h ? /* @__PURE__ */ V(ce, { size: 20 }) : null, e.InputProps.endAdornment] })
5279
+ endAdornment: /* @__PURE__ */ H(Ne, { children: [m ? /* @__PURE__ */ V(ce, { size: 20 }) : null, e.InputProps.endAdornment] })
5280
5280
  }
5281
5281
  })
5282
5282
  });
@@ -5491,17 +5491,17 @@ typeof FinalizationRegistry < "u" && new FinalizationRegistry((e) => {
5491
5491
  t && t.release(e);
5492
5492
  }), Reflect.get(w, "use");
5493
5493
  var yf = ({ selectedConversation: e, currentUser: t, onConversationSelect: n }) => {
5494
- let [r, a] = F(!0), [o, c] = F(), [l, u] = F(!1), d = vf(() => s.summaries.toArray(), [e]) || [], f = vf(() => s.groups.toArray(), []) || [], m = t?.role === "admin" || t?.role === "system", h = j(async () => {
5494
+ let [r, a] = F(!0), [o, c] = F(), [l, u] = F(!1), d = vf(() => s.summaries.toArray(), [e]) || [], f = vf(() => s.groups.toArray(), []) || [], p = t?.role === "admin" || t?.role === "system", m = j(async () => {
5495
5495
  a(!0), t?.org && (await Promise.all([v({}), mf(t?.org)]).catch((e) => {
5496
5496
  c(e instanceof Error ? e : Error(String(e)));
5497
5497
  }), a(!1));
5498
5498
  }, [t?.org]);
5499
5499
  N(() => {
5500
- h();
5501
- let e = setInterval(h, 3 * 6e4);
5500
+ m();
5501
+ let e = setInterval(m, 3 * 6e4);
5502
5502
  return () => clearInterval(e);
5503
- }, [h]);
5504
- let [g, _] = F({});
5503
+ }, [m]);
5504
+ let [h, g] = F({});
5505
5505
  N(() => {
5506
5506
  d.length > 0 && t?.org && (async () => {
5507
5507
  if (!t?.org) return;
@@ -5509,28 +5509,28 @@ var yf = ({ selectedConversation: e, currentUser: t, onConversationSelect: n })
5509
5509
  if (!e) return;
5510
5510
  let n = {};
5511
5511
  for (let t of d) try {
5512
- if (t.user !== void 0 && !g[t.user]) {
5512
+ if (t.user !== void 0 && !h[t.user]) {
5513
5513
  let r = await e.getUser(t.user);
5514
5514
  n[t.user] = r.name;
5515
5515
  }
5516
5516
  } catch (e) {
5517
- p.error("Failed to load conversation name:", e);
5517
+ S.error("Failed to load conversation name:", e);
5518
5518
  }
5519
- Object.keys(n).length > 0 && _((e) => ({
5519
+ Object.keys(n).length > 0 && g((e) => ({
5520
5520
  ...e,
5521
5521
  ...n
5522
5522
  }));
5523
5523
  })();
5524
5524
  }, [d, t?.org]);
5525
- let y = (e) => e.user === void 0 ? e.group === void 0 ? "Unknown" : f.find((t) => t.id === e.group)?.name || `Group ${e.group}` : g[e.user] || `User ${e.user}`, b = (t) => e ? t.group === void 0 ? t.user === void 0 ? !1 : e.type === "dm" && e.id === t.user : e.type === "group" && e.id === t.group : !1, x = (e) => {
5525
+ let _ = (e) => e.user === void 0 ? e.group === void 0 ? "Unknown" : f.find((t) => t.id === e.group)?.name || `Group ${e.group}` : h[e.user] || `User ${e.user}`, y = (t) => e ? t.group === void 0 ? t.user === void 0 ? !1 : e.type === "dm" && e.id === t.user : e.type === "group" && e.id === t.group : !1, b = (e) => {
5526
5526
  e.group === void 0 ? e.user !== void 0 && n({
5527
5527
  type: "dm",
5528
5528
  id: e.user,
5529
- name: y(e)
5529
+ name: _(e)
5530
5530
  }) : n({
5531
5531
  type: "group",
5532
5532
  id: e.group,
5533
- name: y(e)
5533
+ name: _(e)
5534
5534
  });
5535
5535
  };
5536
5536
  return /* @__PURE__ */ H(L, {
@@ -5550,7 +5550,7 @@ var yf = ({ selectedConversation: e, currentUser: t, onConversationSelect: n })
5550
5550
  component: "div",
5551
5551
  sx: { flexGrow: 1 },
5552
5552
  children: "Messages"
5553
- }), m && /* @__PURE__ */ V(Me, {
5553
+ }), p && /* @__PURE__ */ V(Me, {
5554
5554
  title: "Create Group",
5555
5555
  children: /* @__PURE__ */ V(z, {
5556
5556
  color: "primary",
@@ -5561,11 +5561,11 @@ var yf = ({ selectedConversation: e, currentUser: t, onConversationSelect: n })
5561
5561
  })
5562
5562
  })] })
5563
5563
  }),
5564
- m && t?.org && /* @__PURE__ */ V(pf, {
5564
+ p && t?.org && /* @__PURE__ */ V(pf, {
5565
5565
  open: l,
5566
5566
  onClose: () => u(!1),
5567
5567
  onSuccess: async () => {
5568
- await h();
5568
+ await m();
5569
5569
  },
5570
5570
  orgId: t.org
5571
5571
  }),
@@ -5609,9 +5609,9 @@ var yf = ({ selectedConversation: e, currentUser: t, onConversationSelect: n })
5609
5609
  }));
5610
5610
  return [...[...d].sort((e, t) => new Date(t.last_message_at).getTime() - new Date(e.last_message_at).getTime()), ...n].map((e) => /* @__PURE__ */ V(Aa, {
5611
5611
  conversation: e,
5612
- displayName: y(e),
5613
- selected: b(e),
5614
- onClick: () => x(e),
5612
+ displayName: _(e),
5613
+ selected: y(e),
5614
+ onClick: () => b(e),
5615
5615
  currentUser: t
5616
5616
  }, e.group === void 0 ? `user-${e.user}` : `group-${e.group}`));
5617
5617
  })()
@@ -6142,6 +6142,7 @@ var Ef = ({ isOwnMessage: e, isLastInGroup: t, status: n, isOptimistic: r }) =>
6142
6142
  display: "block",
6143
6143
  width: "100%",
6144
6144
  maxWidth: 280,
6145
+ maxHeight: 300,
6145
6146
  cursor: "pointer",
6146
6147
  borderRadius: "4px"
6147
6148
  }
@@ -6370,7 +6371,7 @@ function Pf(e) {
6370
6371
  if (!e.length) return t;
6371
6372
  try {
6372
6373
  let n = Nf(e), r = Array.from(n);
6373
- if (p.debug("[names] size:", n.size), !n.size) return t;
6374
+ if (S.debug("[names] size:", n.size), !n.size) return t;
6374
6375
  let a = (await s.users.bulkGet(r)).filter((e) => !!e), o = /* @__PURE__ */ new Map();
6375
6376
  if (a.forEach((e) => {
6376
6377
  o.set(e.id, e.name);
@@ -6382,7 +6383,7 @@ function Pf(e) {
6382
6383
  let d = o;
6383
6384
  return u.forEach((e) => d.set(e.id, e.name)), d;
6384
6385
  } catch (e) {
6385
- p.error("[useSenderNames] Failed to fetch users:", e);
6386
+ S.error("[useSenderNames] Failed to fetch users:", e);
6386
6387
  }
6387
6388
  return t;
6388
6389
  }, [e, t]);
@@ -9179,7 +9180,7 @@ function bp({ conversation: e, limit: t = 50 }) {
9179
9180
  return Mf(async () => {
9180
9181
  let r = { limit: t };
9181
9182
  d.length && (r.cursorType = "after", r.cursorDatetime = d[d.length - 1]?.created_at), i(!0), await o(e, r).catch(u), i(!1), await s.summaries.update(n, { unread_count: 0 });
9182
- }, [e, t]), p.debug("mw", d.length), {
9183
+ }, [e, t]), S.debug("mw", d.length), {
9183
9184
  messages: d,
9184
9185
  cursor: f,
9185
9186
  loading: r,
@@ -9192,7 +9193,7 @@ function bp({ conversation: e, limit: t = 50 }) {
9192
9193
  if (!f?.datetime) return;
9193
9194
  n.cursorType = "before", n.cursorDatetime = f.datetime, await o(e, n);
9194
9195
  } catch (e) {
9195
- p.error("[useMessages] Failed to load more:", e);
9196
+ S.error("[useMessages] Failed to load more:", e);
9196
9197
  }
9197
9198
  c(!1);
9198
9199
  }
@@ -9396,7 +9397,7 @@ var xp = ({ conversation: e, user: t, isConnected: n, onBack: r }) => {
9396
9397
  };
9397
9398
  }
9398
9399
  componentDidCatch(e, t) {
9399
- p.error("ErrorBoundary caught an error:", e, t), this.props.onError?.(e, t);
9400
+ S.error("ErrorBoundary caught an error:", e, t), this.props.onError?.(e, t);
9400
9401
  }
9401
9402
  handleReset = () => {
9402
9403
  this.setState({
@@ -9455,7 +9456,7 @@ function Cp({ onMessage: e, onConnect: t, onDisconnect: n, onError: r } = {}) {
9455
9456
  e.off("message", s), e.off("open", c), e.off("close", l), e.off("error", u);
9456
9457
  }) : void 0;
9457
9458
  } catch (e) {
9458
- p.error("Failed to setup WebSocket listeners:", e);
9459
+ S.error("Failed to setup WebSocket listeners:", e);
9459
9460
  }
9460
9461
  }, [
9461
9462
  s,
@@ -9557,7 +9558,7 @@ var wp = ({ initialConversation: e }) => {
9557
9558
  } },
9558
9559
  children: t
9559
9560
  }), Ep = /* @__PURE__ */ x(((e, t) => {
9560
- var n = S();
9561
+ var n = a();
9561
9562
  t.exports = function() {
9562
9563
  return n.Date.now();
9563
9564
  };
@@ -9575,26 +9576,26 @@ var wp = ({ initialConversation: e }) => {
9575
9576
  }
9576
9577
  t.exports = i;
9577
9578
  })), kp = /* @__PURE__ */ x(((e, t) => {
9578
- var n = Op(), r = b(), i = qd(), a = NaN, o = /^[-+]0x[0-9a-f]+$/i, s = /^0b[01]+$/i, c = /^0o[0-7]+$/i, l = parseInt;
9579
- function u(e) {
9579
+ var n = Op(), i = r(), a = qd(), o = NaN, s = /^[-+]0x[0-9a-f]+$/i, c = /^0b[01]+$/i, l = /^0o[0-7]+$/i, u = parseInt;
9580
+ function d(e) {
9580
9581
  if (typeof e == "number") return e;
9581
- if (i(e)) return a;
9582
- if (r(e)) {
9582
+ if (a(e)) return o;
9583
+ if (i(e)) {
9583
9584
  var t = typeof e.valueOf == "function" ? e.valueOf() : e;
9584
- e = r(t) ? t + "" : t;
9585
+ e = i(t) ? t + "" : t;
9585
9586
  }
9586
9587
  if (typeof e != "string") return e === 0 ? e : +e;
9587
9588
  e = n(e);
9588
- var u = s.test(e);
9589
- return u || c.test(e) ? l(e.slice(2), u ? 2 : 8) : o.test(e) ? a : +e;
9589
+ var r = c.test(e);
9590
+ return r || l.test(e) ? u(e.slice(2), r ? 2 : 8) : s.test(e) ? o : +e;
9590
9591
  }
9591
- t.exports = u;
9592
+ t.exports = d;
9592
9593
  })), Ap = /* @__PURE__ */ n((/* @__PURE__ */ x(((e, t) => {
9593
- var n = b(), r = Ep(), i = kp(), a = "Expected a function", o = Math.max, s = Math.min;
9594
- function c(e, t, c) {
9594
+ var n = r(), i = Ep(), a = kp(), o = "Expected a function", s = Math.max, c = Math.min;
9595
+ function l(e, t, r) {
9595
9596
  var l, u, d, f, p, m, h = 0, g = !1, _ = !1, v = !0;
9596
- if (typeof e != "function") throw TypeError(a);
9597
- t = i(t) || 0, n(c) && (g = !!c.leading, _ = "maxWait" in c, d = _ ? o(i(c.maxWait) || 0, t) : d, v = "trailing" in c ? !!c.trailing : v);
9597
+ if (typeof e != "function") throw TypeError(o);
9598
+ t = a(t) || 0, n(r) && (g = !!r.leading, _ = "maxWait" in r, d = _ ? s(a(r.maxWait) || 0, t) : d, v = "trailing" in r ? !!r.trailing : v);
9598
9599
  function y(t) {
9599
9600
  var n = l, r = u;
9600
9601
  return l = u = void 0, h = t, f = e.apply(r, n), f;
@@ -9604,14 +9605,14 @@ var wp = ({ initialConversation: e }) => {
9604
9605
  }
9605
9606
  function x(e) {
9606
9607
  var n = e - m, r = e - h, i = t - n;
9607
- return _ ? s(i, d - r) : i;
9608
+ return _ ? c(i, d - r) : i;
9608
9609
  }
9609
9610
  function S(e) {
9610
9611
  var n = e - m, r = e - h;
9611
9612
  return m === void 0 || n >= t || n < 0 || _ && r >= d;
9612
9613
  }
9613
9614
  function C() {
9614
- var e = r();
9615
+ var e = i();
9615
9616
  if (S(e)) return w(e);
9616
9617
  p = setTimeout(C, x(e));
9617
9618
  }
@@ -9622,10 +9623,10 @@ var wp = ({ initialConversation: e }) => {
9622
9623
  p !== void 0 && clearTimeout(p), h = 0, l = m = u = p = void 0;
9623
9624
  }
9624
9625
  function E() {
9625
- return p === void 0 ? f : w(r());
9626
+ return p === void 0 ? f : w(i());
9626
9627
  }
9627
9628
  function D() {
9628
- var e = r(), n = S(e);
9629
+ var e = i(), n = S(e);
9629
9630
  if (l = arguments, u = this, m = e, n) {
9630
9631
  if (p === void 0) return b(m);
9631
9632
  if (_) return clearTimeout(p), p = setTimeout(C, t), y(m);
@@ -9634,9 +9635,9 @@ var wp = ({ initialConversation: e }) => {
9634
9635
  }
9635
9636
  return D.cancel = T, D.flush = E, D;
9636
9637
  }
9637
- t.exports = c;
9638
+ t.exports = l;
9638
9639
  })))(), 1), jp = 0, Mp = (0, Ap.default)(() => {
9639
- i() && v().catch((e) => p.warn(String(e)));
9640
+ i() && v().catch((e) => S.warn(String(e)));
9640
9641
  }, 600);
9641
9642
  function Np() {
9642
9643
  return N(() => (jp++, jp === 1 && (document.addEventListener("visibilitychange", () => {