@alan-ai/alan-sdk-web 1.8.84 → 1.8.86

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.
@@ -21,6 +21,7 @@ export interface AlanButton {
21
21
  isAudioOutputEnabled: () => boolean,
22
22
  setFullScreenMode: (value: boolean) => void,
23
23
  close: () => void,
24
+ minimize: () => void,
24
25
  open: () => void,
25
26
  clear: () => void,
26
27
  };
@@ -1,6 +1,7 @@
1
1
  export interface AlanButtonOptions {
2
2
  key: string;
3
3
  rootEl?: HTMLElement | undefined;
4
+ chatEl?: HTMLElement | undefined;
4
5
  right?: number | string;
5
6
  bottom?: number | string;
6
7
  left?: number | string;
@@ -17,7 +18,11 @@ export interface AlanButtonOptions {
17
18
  onButtonState?: (state: string) => void;
18
19
  onConnectionStatus?: (status: string) => void;
19
20
  textChat?: {
21
+ closeDelay?: number;
22
+ showBtnIfChatOpen?: boolean;
23
+ openByDefault?: boolean;
20
24
  onClose?: () => void;
21
25
  onMinimize?: () => void;
26
+ onOpen?: () => void;
22
27
  }
23
28
  }
package/dist/alan_lib.js CHANGED
@@ -91753,6 +91753,10 @@
91753
91753
  opacity: 0;
91754
91754
  animation: text-chat-appear-anim ${textChatAppearAnimationMs}ms ease-in-out forwards;
91755
91755
  }`;
91756
+ keyFrames += getStyleSheetMarker() + `.alan-text-chat__openning-immidiately {
91757
+ opacity: 1;
91758
+ transform: scale(1);
91759
+ }`;
91756
91760
  keyFrames += getStyleSheetMarker() + generateKeyFrame(
91757
91761
  "text-chat-appear-anim",
91758
91762
  `
@@ -93942,6 +93946,7 @@
93942
93946
  style.setAttribute("id", "alan-stylesheet-" + projectId);
93943
93947
  style.type = "text/css";
93944
93948
  keyFrames += `.alanBtn-root * { box-sizing: border-box; font-family: ${webOptions?.chatOptions?.textChat?.popup?.fontFamily || "Poppins"}; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;}`;
93949
+ keyFrames += `.alanBtn-chat-root-inlined {height: 100%;}`;
93945
93950
  var hoverSelector = !isMobile() ? ":hover" : ":active";
93946
93951
  if (!isMobile()) {
93947
93952
  keyFrames += getStyleSheetMarker() + ".alanBtn{transform: scale(1); transition: " + transitionCss + ";} .alanBtn" + hoverSelector + "{transform: scale(1.11111);transition:" + transitionCss + ";}.alanBtn:focus {transform: scale(1);" + transitionCss + "; border: solid 3px #50e3c2; outline: none; }";
@@ -94589,10 +94594,13 @@ code.hljs {
94589
94594
  return copyBtn;
94590
94595
  return msg.type === "response" && isFinalMessage(msg) ? copyBtn : "";
94591
94596
  }
94592
- function changeMsgLikeStatus(msg) {
94597
+ function changeMsgLikeStatus(msg, options) {
94593
94598
  const reqId = msg.ctx?.reqId || msg.reqId;
94594
94599
  if (reqId) {
94595
94600
  window.tutorProject.call("sendFeedback", { reqId, status: msg.liked });
94601
+ if (options.onEvent) {
94602
+ options.onEvent({ name: "feedbackSent", status: msg.liked, reqId });
94603
+ }
94596
94604
  }
94597
94605
  }
94598
94606
  function resetStylesForLikeAndDislikeBtns(curMsgBubble, msg) {
@@ -95038,7 +95046,7 @@ code.hljs {
95038
95046
  // alan_btn/alan_btn.ts
95039
95047
  var import_sjcl = __toESM(require_sjcl());
95040
95048
  (function(ns) {
95041
- uiState.lib.version = "alan-version.1.8.84".replace("alan-version.", "");
95049
+ uiState.lib.version = "alan-version.1.8.86".replace("alan-version.", "");
95042
95050
  if (window.alanBtn) {
95043
95051
  console.warn("Alan: the Alan Button source code has already added (v." + uiState.lib.version + ")");
95044
95052
  }
@@ -95063,7 +95071,8 @@ code.hljs {
95063
95071
  var keepButtonPositionAfterDnD = false;
95064
95072
  var dragAndDropEnabled = true;
95065
95073
  var curDialogId = null;
95066
- var textChatIsHidden = true;
95074
+ var closeChatTimeoutId;
95075
+ var textChatIsHidden = !options.textChat?.openByDefault;
95067
95076
  var textChatWasClosedManually = false;
95068
95077
  var voiceEnabledInTextChat = true;
95069
95078
  var textChatMessages = [];
@@ -95225,6 +95234,9 @@ code.hljs {
95225
95234
  showTextChat();
95226
95235
  broadcastReloadIframeToIframes();
95227
95236
  },
95237
+ minimize: () => {
95238
+ minimizeTextChat();
95239
+ },
95228
95240
  close: () => {
95229
95241
  closeTextChat();
95230
95242
  },
@@ -95550,6 +95562,9 @@ code.hljs {
95550
95562
  function isInlinedMode() {
95551
95563
  return uiState.textChat.inlined;
95552
95564
  }
95565
+ function isChatOpenedByDefault() {
95566
+ return options?.textChat?.openByDefault;
95567
+ }
95553
95568
  btnSize = btnModes[mode].btnSize;
95554
95569
  function setDefautlPositionProps(value) {
95555
95570
  if (/^\d+$/.test(value)) {
@@ -95565,6 +95580,7 @@ code.hljs {
95565
95580
  if (uiState.btn.zIndex) {
95566
95581
  rootEl.style.zIndex = uiState.btn.zIndex;
95567
95582
  }
95583
+ chatHolderDiv.style.zIndex = uiState.btn.zIndex + 2;
95568
95584
  setButtonPosition();
95569
95585
  recognisedTextContent.classList.add("alanBtn-recognised-text-content");
95570
95586
  recognisedTextHolder.classList.add("alanBtn-recognised-text-holder");
@@ -95596,7 +95612,7 @@ code.hljs {
95596
95612
  sideBtnPos = setDefautlPositionProps(options.right !== void 0 ? options.right : btnModes[mode].rightPos);
95597
95613
  initRightPos = parseInt(sideBtnPos, 10);
95598
95614
  }
95599
- if (isInlinedMode()) {
95615
+ if (isInlinedMode() && !options.chatEl) {
95600
95616
  rootEl.style.position = "static";
95601
95617
  } else {
95602
95618
  rootEl.style.position = options.position ? options.position : "fixed";
@@ -95767,7 +95783,7 @@ code.hljs {
95767
95783
  btn.style.height = size + "px";
95768
95784
  btn.style.maxHeight = size + "px";
95769
95785
  rootEl.style.width = size + "px";
95770
- if (isInlinedMode()) {
95786
+ if (isInlinedMode() && !options.chatEl) {
95771
95787
  rootEl.style.width = "100%";
95772
95788
  rootEl.style.minWidth = "100%";
95773
95789
  rootEl.style.maxWidth = "100%";
@@ -96181,8 +96197,12 @@ code.hljs {
96181
96197
  return;
96182
96198
  if (!dndBackAnimFinished)
96183
96199
  return;
96184
- if (uiState.textChat.available && textChatIsHidden) {
96185
- activateAlanButton();
96200
+ if (uiState.textChat.available) {
96201
+ if (textChatIsHidden) {
96202
+ activateAlanButton();
96203
+ } else {
96204
+ closeTextChat();
96205
+ }
96186
96206
  } else {
96187
96207
  activateVoiceBtn();
96188
96208
  this.blur();
@@ -96638,7 +96658,12 @@ code.hljs {
96638
96658
  }
96639
96659
  updateMsgLoaderIcons(options2?.chatOptions?.textChat);
96640
96660
  initTextChat();
96641
- if (isInlinedMode() || options2?.chatOptions?.textChat?.popup?.openByDefualt === true || isTextChatSavedStateOpened()) {
96661
+ if (options2?.chatOptions?.textChat?.popup?.openByDefualt === true || !isInlinedMode() && isTextChatSavedStateOpened()) {
96662
+ if (!textChatWasClosedManually) {
96663
+ showTextChat(true);
96664
+ }
96665
+ }
96666
+ if (isChatOpenedByDefault()) {
96642
96667
  if (!textChatWasClosedManually) {
96643
96668
  showTextChat(true);
96644
96669
  }
@@ -96701,7 +96726,7 @@ code.hljs {
96701
96726
  }
96702
96727
  function savePrevUserId(userId) {
96703
96728
  if (isLocalStorageAvailable) {
96704
- localStorage.setItem(LOCAL_STORAGE_KEYS.getPrevUserIdKey(), encryptMessage(userId, "userId"));
96729
+ localStorage.setItem(LOCAL_STORAGE_KEYS.getPrevUserIdKey(), encryptMessage(userId || "default", "userId"));
96705
96730
  }
96706
96731
  }
96707
96732
  function getPrevUserId() {
@@ -96739,28 +96764,30 @@ code.hljs {
96739
96764
  } else {
96740
96765
  switchState(getDefaultBtnState());
96741
96766
  }
96742
- const { dialogId } = window.tutorProject.getSettings();
96743
- console.info(`Alan: connected to ${dialogId !== getSavedDialogId() ? "new" : ""} dialog:
96767
+ if (!isTutorMode()) {
96768
+ const { dialogId } = window.tutorProject.getSettings();
96769
+ console.info(`Alan: connected to ${dialogId !== getSavedDialogId() ? "new" : ""} dialog:
96744
96770
  ${dialogId}
96745
96771
  ${getSavedDialogId() || "-"} (prev. dialog)`);
96746
- curDialogId = dialogId;
96747
- sentMessages = restoreSentMessages();
96748
- const prevUserId = getPrevUserId();
96749
- if (getSavedDialogId() !== dialogId) {
96750
- saveDialogId(dialogId);
96751
- restoreMessagesInChat(true);
96752
- onNewDialogAutoReconnect();
96753
- } else {
96754
- if (!(0, import_lodash2.isEmpty)(prevUserId) && (0, import_lodash2.isEmpty)(uiState.userInfo.userId)) {
96755
- savePrevUserId(uiState.userInfo.userId);
96756
- connectToNewDialog();
96757
- return;
96772
+ curDialogId = dialogId;
96773
+ sentMessages = restoreSentMessages();
96774
+ const prevUserId = getPrevUserId();
96775
+ if (getSavedDialogId() !== dialogId) {
96776
+ saveDialogId(dialogId);
96777
+ restoreMessagesInChat(true);
96778
+ onNewDialogAutoReconnect();
96779
+ } else {
96780
+ if (!(0, import_lodash2.isEmpty)(prevUserId) && (0, import_lodash2.isEmpty)(uiState.userInfo.userId)) {
96781
+ savePrevUserId(uiState.userInfo.userId);
96782
+ connectToNewDialog();
96783
+ return;
96784
+ }
96785
+ saveDialogId(dialogId);
96786
+ restoreMessagesInChat(true);
96758
96787
  }
96759
- saveDialogId(dialogId);
96760
- restoreMessagesInChat(true);
96761
- }
96762
- console.info(`Alan: curDialogId:
96788
+ console.info(`Alan: curDialogId:
96763
96789
  ${curDialogId}`);
96790
+ }
96764
96791
  if (!isTutorMode()) {
96765
96792
  sendSyncPageState();
96766
96793
  }
@@ -97307,7 +97334,7 @@ ${curDialogId}`);
97307
97334
  if (dislikeBtnEl) {
97308
97335
  msg.liked = msg.liked !== -1 ? -1 : 0;
97309
97336
  }
97310
- changeMsgLikeStatus(msg);
97337
+ changeMsgLikeStatus(msg, options);
97311
97338
  resetStylesForLikeAndDislikeBtns(curMsgBubble, msg);
97312
97339
  saveMessageHistory();
97313
97340
  }
@@ -98316,38 +98343,56 @@ ${LEARN_MORE_LABEL}
98316
98343
  }
98317
98344
  }
98318
98345
  function showTextChat(noAnimation) {
98346
+ if (chatHolderDiv.classList.contains("is-alan-chat-opened"))
98347
+ return;
98348
+ clearTimeout(closeChatTimeoutId);
98319
98349
  textChatWasClosedManually = false;
98320
- if (options.onEvent) {
98321
- options.onEvent({ name: "textChatOpened" });
98322
- }
98323
98350
  fixPopupScrollOnMobileForTextChat(true);
98324
98351
  hideChatNotifications();
98325
98352
  hidePopup();
98326
98353
  chatHolderDiv.style.display = "flex";
98327
98354
  textChatIsHidden = false;
98328
- if (noAnimation === true) {
98329
- rootEl.classList.add("hide-alan-btn-when-text-chat-is-opened-immediately");
98355
+ if (options.textChat?.showBtnIfChatOpen !== true) {
98356
+ if (noAnimation === true) {
98357
+ rootEl.classList.add("hide-alan-btn-when-text-chat-is-opened-immediately");
98358
+ } else {
98359
+ rootEl.classList.add("hide-alan-btn-when-text-chat-is-opened");
98360
+ }
98361
+ }
98362
+ chatHolderDiv.classList.add("is-alan-chat-opened");
98363
+ if (isInlinedMode()) {
98364
+ chatHolderDiv.classList.add("alan-text-chat__openning-immidiately");
98330
98365
  } else {
98331
- rootEl.classList.add("hide-alan-btn-when-text-chat-is-opened");
98366
+ chatHolderDiv.classList.add("alan-text-chat__openning");
98332
98367
  }
98333
- chatHolderDiv.classList.add("alan-text-chat__openning");
98334
98368
  if (isLocalStorageAvailable) {
98335
98369
  if (!isMobile()) {
98336
98370
  localStorage.setItem(LOCAL_STORAGE_KEYS.getOpenedClosedTextChatStateKey(), "1");
98337
98371
  }
98338
98372
  }
98373
+ if (options?.textChat?.onOpen) {
98374
+ options?.textChat?.onOpen();
98375
+ }
98376
+ if (options.onEvent) {
98377
+ options.onEvent({ name: "textChatOpened" });
98378
+ }
98339
98379
  }
98340
98380
  function hideTextChat() {
98341
98381
  if (textChatIsHidden)
98342
98382
  return;
98343
98383
  deactivateAlanButton();
98384
+ chatHolderDiv.classList.remove("is-alan-chat-opened");
98344
98385
  chatHolderDiv.classList.add("alan-text-chat__closing");
98345
- rootEl.classList.add("text-chat-is-closing");
98386
+ if (options.textChat?.showBtnIfChatOpen !== true) {
98387
+ rootEl.classList.add("text-chat-is-closing");
98388
+ }
98346
98389
  setTimeout(() => {
98347
98390
  chatHolderDiv.style.display = "none";
98348
98391
  chatHolderDiv.classList.remove("alan-text-chat__closing");
98349
- rootEl.classList.remove("hide-alan-btn-when-text-chat-is-opened");
98350
- rootEl.classList.remove("hide-alan-btn-when-text-chat-is-opened-immediately");
98392
+ if (options.textChat?.showBtnIfChatOpen !== true) {
98393
+ rootEl.classList.remove("hide-alan-btn-when-text-chat-is-opened");
98394
+ rootEl.classList.remove("hide-alan-btn-when-text-chat-is-opened-immediately");
98395
+ }
98351
98396
  rootEl.classList.remove("text-chat-is-closing");
98352
98397
  fixPopupScrollOnMobileForTextChat(false);
98353
98398
  }, uiState.textChat.defaults.appearAnimationMs);
@@ -98366,26 +98411,47 @@ ${LEARN_MORE_LABEL}
98366
98411
  }
98367
98412
  function closeTextChat() {
98368
98413
  textChatWasClosedManually = true;
98369
- if (options.onEvent) {
98370
- options.onEvent({ name: "textChatClosed" });
98371
- }
98372
98414
  if (options?.textChat?.onClose) {
98373
98415
  options?.textChat?.onClose();
98416
+ }
98417
+ const closeDelay = options?.textChat?.closeDelay;
98418
+ if (closeDelay) {
98419
+ clearTimeout(closeChatTimeoutId);
98420
+ closeChatTimeoutId = setTimeout(() => {
98421
+ _closeChat();
98422
+ }, closeDelay);
98374
98423
  } else {
98375
- hideTextChat();
98424
+ _closeChat();
98376
98425
  }
98426
+ }
98427
+ function _closeChat() {
98428
+ if (options.onEvent) {
98429
+ options.onEvent({ name: "textChatClosed" });
98430
+ }
98431
+ hideTextChat();
98377
98432
  if (uiState.textChat.options?.popup?.clearChatOnClose === true) {
98378
98433
  onClearTextChatBtnClick();
98379
98434
  }
98380
98435
  }
98381
- function minimizeTextChat() {
98436
+ function _minimizeChat() {
98382
98437
  if (options.onEvent) {
98383
98438
  options.onEvent({ name: "textChatMinimized" });
98384
98439
  }
98440
+ hideTextChat();
98441
+ }
98442
+ function minimizeTextChat() {
98443
+ textChatWasClosedManually = true;
98385
98444
  if (options?.textChat?.onMinimize) {
98386
98445
  options?.textChat?.onMinimize();
98446
+ }
98447
+ const closeDelay = options?.textChat?.closeDelay;
98448
+ if (closeDelay) {
98449
+ clearTimeout(closeChatTimeoutId);
98450
+ closeChatTimeoutId = setTimeout(() => {
98451
+ _minimizeChat();
98452
+ }, closeDelay);
98387
98453
  } else {
98388
- hideTextChat();
98454
+ _minimizeChat();
98389
98455
  }
98390
98456
  }
98391
98457
  function expandCollapseChatSidePanel() {
@@ -98509,7 +98575,7 @@ ${LEARN_MORE_LABEL}
98509
98575
  changeBgColors(DEFAULT);
98510
98576
  micIconDiv.style.opacity = "1";
98511
98577
  roundedTriangleIconDiv.style.opacity = "0";
98512
- disconnectedMicLoaderIconImg.style.opacity = "0";
98578
+ disconnectedMicLoaderIconImg.style.opacity = "1";
98513
98579
  changeCustomLogoVisibility(
98514
98580
  defaultStateBtnIconImg,
98515
98581
  [
@@ -98880,13 +98946,20 @@ ${LEARN_MORE_LABEL}
98880
98946
  }
98881
98947
  function showBtn() {
98882
98948
  rootEl.innerHTML = "";
98883
- if (!isInlinedMode()) {
98884
- recognisedTextHolder.appendChild(recognisedTextContent);
98885
- rootEl.appendChild(recognisedTextHolder);
98886
- rootEl.appendChild(btn);
98887
- btn.appendChild(chatNotificationsBubble);
98949
+ recognisedTextHolder.appendChild(recognisedTextContent);
98950
+ rootEl.appendChild(recognisedTextHolder);
98951
+ rootEl.appendChild(btn);
98952
+ btn.appendChild(chatNotificationsBubble);
98953
+ if (isInlinedMode()) {
98954
+ if (options.chatEl) {
98955
+ options.chatEl.append(chatHolderDiv);
98956
+ } else {
98957
+ console.error("Text Chat element is not defined. Set chatEl in Alan Button options");
98958
+ return;
98959
+ }
98960
+ } else {
98961
+ rootEl.appendChild(chatHolderDiv);
98888
98962
  }
98889
- rootEl.appendChild(chatHolderDiv);
98890
98963
  resizeTextArea();
98891
98964
  btnDisabled = false;
98892
98965
  }
@@ -98957,6 +99030,13 @@ ${LEARN_MORE_LABEL}
98957
99030
  }
98958
99031
  rootEl.classList.add("alanBtn-root");
98959
99032
  rootEl.classList.add("alan-" + getProjectId());
99033
+ if (options.chatEl) {
99034
+ options.chatEl.classList.add("alanBtn-root");
99035
+ if (isInlinedMode()) {
99036
+ options.chatEl.classList.add("alanBtn-chat-root-inlined");
99037
+ }
99038
+ options.chatEl.classList.add("alan-" + getProjectId());
99039
+ }
98960
99040
  var alanBtnSavedOptions = null;
98961
99041
  if (isTutorMode()) {
98962
99042
  showBtn();
@@ -99032,10 +99112,10 @@ ${LEARN_MORE_LABEL}
99032
99112
  rootEl.style.setProperty("top", dndBtnTopPos + "px", "important");
99033
99113
  rootEl.style.setProperty("bottom", "auto", "important");
99034
99114
  }
99035
- if (Math.abs(tempDeltaX) > 15 || Math.abs(tempDeltaY) > 15) {
99115
+ if ((Math.abs(tempDeltaX) > 15 || Math.abs(tempDeltaY) > 15) && !isInlinedMode()) {
99036
99116
  hideTextChat();
99037
- afterMouseMove = true;
99038
99117
  }
99118
+ afterMouseMove = true;
99039
99119
  newLeftPos = dndBtnLeftPos + posInfo.clientX - dndInitMousePos2[0];
99040
99120
  newTopPos = dndBtnTopPos + posInfo.clientY - dndInitMousePos2[1];
99041
99121
  tempDeltaX = posInfo.clientX - dndInitMousePos2[0];