@banbox/chat 1.0.9 → 1.0.10

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.d.cts CHANGED
@@ -471,7 +471,13 @@ type ChatMessageItemProps = {
471
471
  status?: string;
472
472
  className?: string;
473
473
  onReply?: () => void;
474
- onTranslate?: () => void;
474
+ /**
475
+ * Optional async translator. Receives the original text and returns the
476
+ * translated string. When omitted the translate button is still shown but
477
+ * does nothing (good for demo mode).
478
+ * Example: `onTranslate={(t) => googleTranslate(t, "bn")}`
479
+ */
480
+ onTranslate?: (text: string) => string | undefined;
475
481
  initialSrc?: string;
476
482
  };
477
483
  declare const ChatMessageItem: React__default.FC<ChatMessageItemProps>;
package/dist/index.d.ts CHANGED
@@ -471,7 +471,13 @@ type ChatMessageItemProps = {
471
471
  status?: string;
472
472
  className?: string;
473
473
  onReply?: () => void;
474
- onTranslate?: () => void;
474
+ /**
475
+ * Optional async translator. Receives the original text and returns the
476
+ * translated string. When omitted the translate button is still shown but
477
+ * does nothing (good for demo mode).
478
+ * Example: `onTranslate={(t) => googleTranslate(t, "bn")}`
479
+ */
480
+ onTranslate?: (text: string) => string | undefined;
475
481
  initialSrc?: string;
476
482
  };
477
483
  declare const ChatMessageItem: React__default.FC<ChatMessageItemProps>;
package/dist/index.js CHANGED
@@ -3243,21 +3243,6 @@ var MessageHoverActions = ({
3243
3243
  ] });
3244
3244
  };
3245
3245
  var MessageHoverActions_default = MessageHoverActions;
3246
- var toBanglaDemo = (s) => {
3247
- const map = {
3248
- Hi: "\u09B9\u09BE\u0987",
3249
- "Do you have a freight forwarder in China?": "\u0986\u09AA\u09A8\u09BE\u09B0 \u0995\u09BF \u099A\u09C0\u09A8\u09C7 \u0995\u09CB\u09A8\u09CB \u09AB\u09CD\u09B0\u09C7\u0987\u099F \u09AB\u09B0\u0993\u09AF\u09BC\u09BE\u09B0\u09CD\u09A1\u09BE\u09B0 \u0986\u099B\u09C7?",
3250
- "This conversation is empty. Say hi \u{1F44B}": "\u098F\u0987 \u0995\u09A5\u09CB\u09AA\u0995\u09A5\u09A8\u099F\u09BF \u0996\u09BE\u09B2\u09BF \u0964 \u09B9\u09BE\u0987 \u09B9\u09BE\u0987 \u09B9\u09BE\u0987 \u09AC\u09B2\u09C1\u09A8 \u{1F44B}",
3251
- "Can we schedule a call for tomorrow?": "\u0986\u09AE\u09B0\u09BE \u0995\u09BF \u0986\u0997\u09BE\u09AE\u09C0\u0995\u09BE\u09B2 \u098F\u0995\u099F\u09BF \u0995\u09B2 \u09A8\u09BF\u09B0\u09CD\u09A7\u09BE\u09B0\u09A3 \u0995\u09B0\u09A4\u09C7 \u09AA\u09BE\u09B0\u09BF?",
3252
- "Sure, what time suits you?": "\u0985\u09AC\u09B6\u09CD\u09AF\u0987, \u0986\u09AA\u09A8\u09BE\u09B0 \u099C\u09A8\u09CD\u09AF \u0995\u09CB\u09A8 \u09B8\u09AE\u09AF\u09BC\u099F\u09BF \u09B8\u09C1\u09AC\u09BF\u09A7\u09BE\u099C\u09A8\u0995?",
3253
- "Welcome to Global Marketplace": "\u0997\u09CD\u09B2\u09CB\u09AC\u09BE\u09B2 \u09AE\u09BE\u09B0\u09CD\u0995\u09C7\u099F\u09AA\u09CD\u09B2\u09C7\u09B8\u09C7 \u0986\u09AA\u09A8\u09BE\u0995\u09C7 \u09B8\u09CD\u09AC\u09BE\u0997\u09A4\u09AE \u{1F389}",
3254
- "Happy to be here!": "\u098F\u0996\u09BE\u09A8\u09C7 \u09A5\u09BE\u0995\u09A4\u09C7 \u09AA\u09C7\u09B0\u09C7 \u0986\u09A8\u09A8\u09CD\u09A6\u09BF\u09A4!"
3255
- };
3256
- if (map[s]) {
3257
- return map[s];
3258
- }
3259
- return `\u09AC\u09BE\u0982\u09B2\u09BE ${s}`;
3260
- };
3261
3246
  var ChatMessageItem = ({
3262
3247
  id,
3263
3248
  mine = false,
@@ -3280,31 +3265,24 @@ var ChatMessageItem = ({
3280
3265
  }) => {
3281
3266
  const originalTextRef = React16.useRef(text ?? "");
3282
3267
  const [translated, setTranslated] = React16.useState(false);
3283
- const displayText = translated ? toBanglaDemo(originalTextRef.current) : originalTextRef.current;
3268
+ const displayText = translated ? onTranslate?.(originalTextRef.current) ?? originalTextRef.current : originalTextRef.current;
3284
3269
  const handleTranslateClick = () => {
3285
3270
  setTranslated((v) => !v);
3286
- onTranslate?.();
3287
3271
  };
3288
3272
  return /* @__PURE__ */ jsx("div", { className: clsx3("mb-4", className), "data-msg-id": id, children: /* @__PURE__ */ jsxs("div", { className: clsx3("flex items-end gap-3", mine && "justify-end"), children: [
3289
- !mine && /* @__PURE__ */ jsx("div", { className: `${showStatus ? "mb-5" : "mb-0"}`, children: initialSrc ? /* @__PURE__ */ jsxs("div", { className: "relative h-10 w-10 shrink-0 rounded-full border border-[#F1F1F1]", children: [
3290
- /* @__PURE__ */ jsx(
3291
- "img",
3292
- {
3293
- src: initialSrc,
3294
- alt: "avatar image",
3295
- className: "h-full w-full rounded-full object-cover"
3296
- }
3297
- ),
3298
- /* @__PURE__ */ jsx("span", { className: "absolute bottom-0 right-0 h-[11.25px] w-[11.25px] rounded-full bg-[#328545] ring-1 ring-white" })
3299
- ] }) : /* @__PURE__ */ jsxs(
3273
+ !mine && /* @__PURE__ */ jsx("div", { className: `${showStatus ? "mb-5" : "mb-0"}`, children: initialSrc ? /* @__PURE__ */ jsx("div", { className: "relative h-10 w-10 shrink-0 rounded-full border border-[#F1F1F1]", children: /* @__PURE__ */ jsx(
3274
+ "img",
3275
+ {
3276
+ src: initialSrc,
3277
+ alt: "avatar image",
3278
+ className: "h-full w-full rounded-full object-cover"
3279
+ }
3280
+ ) }) : /* @__PURE__ */ jsx(
3300
3281
  "div",
3301
3282
  {
3302
3283
  className: "relative grid h-10 w-10 shrink-0 place-items-center rounded-full border border-[#f1f1f1] font-semibold text-[#2c2c2c]",
3303
3284
  style: { backgroundColor: avatarBg },
3304
- children: [
3305
- authorInitial,
3306
- /* @__PURE__ */ jsx("span", { className: "absolute bottom-0 right-0 h-[11.25px] w-[11.25px] rounded-full bg-[#328545] ring-1 ring-white" })
3307
- ]
3285
+ children: authorInitial
3308
3286
  }
3309
3287
  ) }),
3310
3288
  /* @__PURE__ */ jsxs("div", { className: clsx3("flex flex-col gap-1 w-full"), children: [
@@ -3707,6 +3685,22 @@ var ChatImagePreviewModal = ({
3707
3685
  ) }) });
3708
3686
  };
3709
3687
  var ChatImagePreviewModal_default = ChatImagePreviewModal;
3688
+
3689
+ // src/utils/theme.ts
3690
+ var GRADIENT_BORDER = "linear-gradient(236.83deg, rgba(51,201,212,0.3) 0.4%, rgba(39,83,251,0.3) 30.28%, rgba(39,83,251,0.3) 50.2%, rgba(39,83,251,0.3) 65.14%, rgba(235,67,255,0.3) 100%)";
3691
+ function getThemeAttr(theme) {
3692
+ if (!theme || theme === "marketplace") return "marketplace";
3693
+ if (theme === "admin") return "admin";
3694
+ return "custom";
3695
+ }
3696
+ function getThemeVars(theme) {
3697
+ if (!theme || theme === "marketplace" || theme === "admin") return {};
3698
+ const vars = {};
3699
+ if (theme.primary) vars["--color-banbox-primary"] = theme.primary;
3700
+ if (theme.primaryActive) vars["--color-banbox-primary-active"] = theme.primaryActive;
3701
+ if (theme.surfaceLow) vars["--color-banbox-surface-container-low"] = theme.surfaceLow;
3702
+ return vars;
3703
+ }
3710
3704
  var baseItem = "flex w-full items-center gap-3 px-3 py-2 text-sm hover:bg-black/5 cursor-pointer";
3711
3705
  var ChatKebabMenu = ({
3712
3706
  pinned,
@@ -3802,20 +3796,6 @@ var avatarBgByInitial = {
3802
3796
  B: "#F0EDEB",
3803
3797
  b: "#F0EDEB"
3804
3798
  };
3805
- var GRADIENT_BORDER = "linear-gradient(236.83deg, rgba(51,201,212,0.3) 0.4%, rgba(39,83,251,0.3) 30.28%, rgba(39,83,251,0.3) 50.2%, rgba(39,83,251,0.3) 65.14%, rgba(235,67,255,0.3) 100%)";
3806
- function getThemeAttr(theme) {
3807
- if (!theme || theme === "marketplace") return "marketplace";
3808
- if (theme === "admin") return "admin";
3809
- return "custom";
3810
- }
3811
- function getThemeVars(theme) {
3812
- if (!theme || theme === "marketplace" || theme === "admin") return {};
3813
- const vars = {};
3814
- if (theme.primary) vars["--color-banbox-primary"] = theme.primary;
3815
- if (theme.primaryActive) vars["--color-banbox-primary-active"] = theme.primaryActive;
3816
- if (theme.surfaceLow) vars["--color-banbox-surface-container-low"] = theme.surfaceLow;
3817
- return vars;
3818
- }
3819
3799
  var InboxPopup = ({ adapter, uiCallbacks, theme }) => {
3820
3800
  const { close, selectThread, selectedThreadId, reference } = useChatUI();
3821
3801
  const { isOpen: isGalleryOpen, closeGallery } = useGallery();
@@ -3870,6 +3850,9 @@ var InboxPopup = ({ adapter, uiCallbacks, theme }) => {
3870
3850
  if (activeId) adapter.threads.markRead?.(activeId);
3871
3851
  }
3872
3852
  }, [activeId, adapter]);
3853
+ useEffect(() => {
3854
+ if (activeId) adapter.threads.markRead?.(activeId);
3855
+ }, []);
3873
3856
  const toRef2 = (m) => ({
3874
3857
  id: m.id,
3875
3858
  author: typeof m.author === "string" ? m.author : "U",
@@ -4092,13 +4075,10 @@ var InboxPopup = ({ adapter, uiCallbacks, theme }) => {
4092
4075
  ] });
4093
4076
  };
4094
4077
  var InboxPopup_default = InboxPopup;
4095
- var GRADIENT_BORDER2 = "linear-gradient(236.83deg, rgba(51,201,212,0.3) 0.4%, rgba(39,83,251,0.3) 30.28%, rgba(39,83,251,0.3) 50.2%, rgba(39,83,251,0.3) 65.14%, rgba(235,67,255,0.3) 100%)";
4096
4078
  function coalesceThreadId(reference, threads) {
4097
- const referenceId = reference?.id;
4098
- if (reference?.kind === "quotation") {
4099
- return threads.find((t) => t.id === "t4")?.id ?? (threads[0]?.id ?? "");
4100
- }
4101
- return referenceId && (threads.find((t) => t.id === referenceId)?.id || threads.find((t) => t.inquiryId === referenceId)?.id) || (threads.length ? threads[0].id : "");
4079
+ if (!reference?.id) return threads[0]?.id ?? "";
4080
+ const refId = reference.id;
4081
+ return threads.find((t) => t.id === refId)?.id ?? threads.find((t) => t.orderId === refId)?.id ?? threads.find((t) => t.inquiryId === refId)?.id ?? threads[0]?.id ?? "";
4102
4082
  }
4103
4083
  function toRef(m) {
4104
4084
  return {
@@ -4111,25 +4091,19 @@ function toRef(m) {
4111
4091
  audio: m.audio
4112
4092
  };
4113
4093
  }
4114
- function getThemeAttr2(theme) {
4115
- if (!theme || theme === "marketplace") return "marketplace";
4116
- if (theme === "admin") return "admin";
4117
- return "custom";
4118
- }
4119
- function getThemeVars2(theme) {
4120
- if (!theme || theme === "marketplace" || theme === "admin") return {};
4121
- const vars = {};
4122
- if (theme.primary) vars["--color-banbox-primary"] = theme.primary;
4123
- if (theme.primaryActive) vars["--color-banbox-primary-active"] = theme.primaryActive;
4124
- if (theme.surfaceLow) vars["--color-banbox-surface-container-low"] = theme.surfaceLow;
4125
- return vars;
4126
- }
4127
4094
  var SinglePopup = ({ adapter, uiCallbacks, theme }) => {
4128
4095
  const { close, reference } = useChatUI();
4129
4096
  const { isOpen: isGalleryOpen, closeGallery } = useGallery();
4130
- const threads = adapter.threads.list(reference);
4097
+ const [threads, setThreads] = React16.useState(() => adapter.threads.list(reference));
4098
+ React16.useEffect(() => {
4099
+ setThreads(adapter.threads.list(reference));
4100
+ const unsub = adapter.threads.subscribe(() => {
4101
+ setThreads(adapter.threads.list(reference));
4102
+ });
4103
+ return unsub;
4104
+ }, [adapter, reference]);
4131
4105
  const initialThreadId = React16.useMemo(
4132
- () => coalesceThreadId(reference, threads),
4106
+ () => coalesceThreadId(reference, adapter.threads.list(reference)),
4133
4107
  // eslint-disable-next-line react-hooks/exhaustive-deps
4134
4108
  [reference]
4135
4109
  );
@@ -4193,12 +4167,12 @@ var SinglePopup = ({ adapter, uiCallbacks, theme }) => {
4193
4167
  {
4194
4168
  role: "dialog",
4195
4169
  "aria-modal": "true",
4196
- "data-theme": getThemeAttr2(theme),
4170
+ "data-theme": getThemeAttr(theme),
4197
4171
  className: "banbox-chat-root relative h-[650px] w-[450px] rounded-[20px] p-[2px]",
4198
4172
  style: {
4199
4173
  boxShadow: "0px 2px 12px 0px #3B33331A",
4200
- background: GRADIENT_BORDER2,
4201
- ...getThemeVars2(theme)
4174
+ background: GRADIENT_BORDER,
4175
+ ...getThemeVars(theme)
4202
4176
  },
4203
4177
  initial: { x: "110%" },
4204
4178
  animate: { x: 0 },