@ahmedramez-org/nexus-chat 1.0.0-beta.20 → 1.0.0-beta.21

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 (3) hide show
  1. package/package.json +1 -1
  2. package/react.js +2 -1
  3. package/window.js +7 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ahmedramez-org/nexus-chat",
3
- "version": "1.0.0-beta.20",
3
+ "version": "1.0.0-beta.21",
4
4
  "description": "NexusChat for any app: a connector and React component that load the prebuilt chat from IncortaCopilot (or a pinned copy), and the host contract types and checks.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
package/react.js CHANGED
@@ -284,7 +284,7 @@ function EmbeddedChat({ embedUrl, modes, defaultMode, theme = 'light', locale })
284
284
  const [src] = useState(() => embedSrc(embedUrl, theme, locale));
285
285
  useEffect(() => {
286
286
  if (!win || !opened) return undefined;
287
- const connected = connectEmbeddedChat(win, frame.current, { embedUrl, theme });
287
+ const connected = connectEmbeddedChat(win, frame.current, { embedUrl, theme, locale });
288
288
  embedded.current = connected;
289
289
  return () => {
290
290
  connected.destroy();
@@ -292,6 +292,7 @@ function EmbeddedChat({ embedUrl, modes, defaultMode, theme = 'light', locale })
292
292
  };
293
293
  }, [win, opened, embedUrl]);
294
294
  useEffect(() => embedded.current?.setTheme(theme), [theme]);
295
+ useEffect(() => embedded.current?.setLocale(locale), [locale]);
295
296
 
296
297
  return h(
297
298
  'div',
package/window.js CHANGED
@@ -274,7 +274,7 @@ export function createChatWindow({ into, panel, modes = MODES, defaultMode, them
274
274
  * buttons applied, and "active" sent while the user works in the app, so
275
275
  * Incorta's idle timeout does not end the chat's session.
276
276
  */
277
- export function connectEmbeddedChat(win, iframe, { embedUrl, theme = 'light' }) {
277
+ export function connectEmbeddedChat(win, iframe, { embedUrl, theme = 'light', locale }) {
278
278
  // From the chat page itself, not a sign-in page the frame navigated to.
279
279
  const origin = new URL(embedUrl, location.href).origin;
280
280
  const skeleton = showNexusChatSkeleton(win.panel, theme);
@@ -283,7 +283,7 @@ export function connectEmbeddedChat(win, iframe, { embedUrl, theme = 'light' })
283
283
  const post = (message) =>
284
284
  iframe.contentWindow?.postMessage({ ...message, v: PROTOCOL_VERSION }, origin);
285
285
  const sendStyle = (force) => {
286
- const message = { nexusChat: 'style', theme, window: win.state() };
286
+ const message = { nexusChat: 'style', theme, locale, window: win.state() };
287
287
  const key = JSON.stringify(message);
288
288
  if (!force && key === sent) return;
289
289
  sent = key;
@@ -327,6 +327,10 @@ export function connectEmbeddedChat(win, iframe, { embedUrl, theme = 'light' })
327
327
  skeleton.setTheme(next);
328
328
  sendStyle();
329
329
  },
330
+ setLocale(next) {
331
+ locale = next;
332
+ sendStyle();
333
+ },
330
334
  destroy() {
331
335
  clearTimeout(fallback);
332
336
  skeleton.remove();
@@ -361,7 +365,7 @@ export function createEmbeddedChat({
361
365
  iframe.src = embedSrc(embedUrl, theme, locale);
362
366
  iframe.style.cssText = 'display:block;width:100%;height:100%;border:0';
363
367
  win.panel.prepend(iframe);
364
- embedded = connectEmbeddedChat(win, iframe, { embedUrl, theme });
368
+ embedded = connectEmbeddedChat(win, iframe, { embedUrl, theme, locale });
365
369
  };
366
370
  const unsubscribe = win.subscribe(embed);
367
371
  embed();