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

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; }";
@@ -95038,7 +95043,7 @@ code.hljs {
95038
95043
  // alan_btn/alan_btn.ts
95039
95044
  var import_sjcl = __toESM(require_sjcl());
95040
95045
  (function(ns) {
95041
- uiState.lib.version = "alan-version.1.8.84".replace("alan-version.", "");
95046
+ uiState.lib.version = "alan-version.1.8.85".replace("alan-version.", "");
95042
95047
  if (window.alanBtn) {
95043
95048
  console.warn("Alan: the Alan Button source code has already added (v." + uiState.lib.version + ")");
95044
95049
  }
@@ -95063,7 +95068,8 @@ code.hljs {
95063
95068
  var keepButtonPositionAfterDnD = false;
95064
95069
  var dragAndDropEnabled = true;
95065
95070
  var curDialogId = null;
95066
- var textChatIsHidden = true;
95071
+ var closeChatTimeoutId;
95072
+ var textChatIsHidden = !options.textChat?.openByDefault;
95067
95073
  var textChatWasClosedManually = false;
95068
95074
  var voiceEnabledInTextChat = true;
95069
95075
  var textChatMessages = [];
@@ -95225,6 +95231,9 @@ code.hljs {
95225
95231
  showTextChat();
95226
95232
  broadcastReloadIframeToIframes();
95227
95233
  },
95234
+ minimize: () => {
95235
+ minimizeTextChat();
95236
+ },
95228
95237
  close: () => {
95229
95238
  closeTextChat();
95230
95239
  },
@@ -95550,6 +95559,9 @@ code.hljs {
95550
95559
  function isInlinedMode() {
95551
95560
  return uiState.textChat.inlined;
95552
95561
  }
95562
+ function isChatOpenedByDefault() {
95563
+ return options?.textChat?.openByDefault;
95564
+ }
95553
95565
  btnSize = btnModes[mode].btnSize;
95554
95566
  function setDefautlPositionProps(value) {
95555
95567
  if (/^\d+$/.test(value)) {
@@ -95565,6 +95577,7 @@ code.hljs {
95565
95577
  if (uiState.btn.zIndex) {
95566
95578
  rootEl.style.zIndex = uiState.btn.zIndex;
95567
95579
  }
95580
+ chatHolderDiv.style.zIndex = uiState.btn.zIndex + 2;
95568
95581
  setButtonPosition();
95569
95582
  recognisedTextContent.classList.add("alanBtn-recognised-text-content");
95570
95583
  recognisedTextHolder.classList.add("alanBtn-recognised-text-holder");
@@ -95596,7 +95609,7 @@ code.hljs {
95596
95609
  sideBtnPos = setDefautlPositionProps(options.right !== void 0 ? options.right : btnModes[mode].rightPos);
95597
95610
  initRightPos = parseInt(sideBtnPos, 10);
95598
95611
  }
95599
- if (isInlinedMode()) {
95612
+ if (isInlinedMode() && !options.chatEl) {
95600
95613
  rootEl.style.position = "static";
95601
95614
  } else {
95602
95615
  rootEl.style.position = options.position ? options.position : "fixed";
@@ -95767,7 +95780,7 @@ code.hljs {
95767
95780
  btn.style.height = size + "px";
95768
95781
  btn.style.maxHeight = size + "px";
95769
95782
  rootEl.style.width = size + "px";
95770
- if (isInlinedMode()) {
95783
+ if (isInlinedMode() && !options.chatEl) {
95771
95784
  rootEl.style.width = "100%";
95772
95785
  rootEl.style.minWidth = "100%";
95773
95786
  rootEl.style.maxWidth = "100%";
@@ -96181,8 +96194,12 @@ code.hljs {
96181
96194
  return;
96182
96195
  if (!dndBackAnimFinished)
96183
96196
  return;
96184
- if (uiState.textChat.available && textChatIsHidden) {
96185
- activateAlanButton();
96197
+ if (uiState.textChat.available) {
96198
+ if (textChatIsHidden) {
96199
+ activateAlanButton();
96200
+ } else {
96201
+ closeTextChat();
96202
+ }
96186
96203
  } else {
96187
96204
  activateVoiceBtn();
96188
96205
  this.blur();
@@ -96638,7 +96655,12 @@ code.hljs {
96638
96655
  }
96639
96656
  updateMsgLoaderIcons(options2?.chatOptions?.textChat);
96640
96657
  initTextChat();
96641
- if (isInlinedMode() || options2?.chatOptions?.textChat?.popup?.openByDefualt === true || isTextChatSavedStateOpened()) {
96658
+ if (options2?.chatOptions?.textChat?.popup?.openByDefualt === true || !isInlinedMode() && isTextChatSavedStateOpened()) {
96659
+ if (!textChatWasClosedManually) {
96660
+ showTextChat(true);
96661
+ }
96662
+ }
96663
+ if (isChatOpenedByDefault()) {
96642
96664
  if (!textChatWasClosedManually) {
96643
96665
  showTextChat(true);
96644
96666
  }
@@ -96701,7 +96723,7 @@ code.hljs {
96701
96723
  }
96702
96724
  function savePrevUserId(userId) {
96703
96725
  if (isLocalStorageAvailable) {
96704
- localStorage.setItem(LOCAL_STORAGE_KEYS.getPrevUserIdKey(), encryptMessage(userId, "userId"));
96726
+ localStorage.setItem(LOCAL_STORAGE_KEYS.getPrevUserIdKey(), encryptMessage(userId || "default", "userId"));
96705
96727
  }
96706
96728
  }
96707
96729
  function getPrevUserId() {
@@ -98316,38 +98338,56 @@ ${LEARN_MORE_LABEL}
98316
98338
  }
98317
98339
  }
98318
98340
  function showTextChat(noAnimation) {
98341
+ if (chatHolderDiv.classList.contains("is-alan-chat-opened"))
98342
+ return;
98343
+ clearTimeout(closeChatTimeoutId);
98319
98344
  textChatWasClosedManually = false;
98320
- if (options.onEvent) {
98321
- options.onEvent({ name: "textChatOpened" });
98322
- }
98323
98345
  fixPopupScrollOnMobileForTextChat(true);
98324
98346
  hideChatNotifications();
98325
98347
  hidePopup();
98326
98348
  chatHolderDiv.style.display = "flex";
98327
98349
  textChatIsHidden = false;
98328
- if (noAnimation === true) {
98329
- rootEl.classList.add("hide-alan-btn-when-text-chat-is-opened-immediately");
98350
+ if (options.textChat?.showBtnIfChatOpen !== true) {
98351
+ if (noAnimation === true) {
98352
+ rootEl.classList.add("hide-alan-btn-when-text-chat-is-opened-immediately");
98353
+ } else {
98354
+ rootEl.classList.add("hide-alan-btn-when-text-chat-is-opened");
98355
+ }
98356
+ }
98357
+ chatHolderDiv.classList.add("is-alan-chat-opened");
98358
+ if (isInlinedMode()) {
98359
+ chatHolderDiv.classList.add("alan-text-chat__openning-immidiately");
98330
98360
  } else {
98331
- rootEl.classList.add("hide-alan-btn-when-text-chat-is-opened");
98361
+ chatHolderDiv.classList.add("alan-text-chat__openning");
98332
98362
  }
98333
- chatHolderDiv.classList.add("alan-text-chat__openning");
98334
98363
  if (isLocalStorageAvailable) {
98335
98364
  if (!isMobile()) {
98336
98365
  localStorage.setItem(LOCAL_STORAGE_KEYS.getOpenedClosedTextChatStateKey(), "1");
98337
98366
  }
98338
98367
  }
98368
+ if (options?.textChat?.onOpen) {
98369
+ options?.textChat?.onOpen();
98370
+ }
98371
+ if (options.onEvent) {
98372
+ options.onEvent({ name: "textChatOpened" });
98373
+ }
98339
98374
  }
98340
98375
  function hideTextChat() {
98341
98376
  if (textChatIsHidden)
98342
98377
  return;
98343
98378
  deactivateAlanButton();
98379
+ chatHolderDiv.classList.remove("is-alan-chat-opened");
98344
98380
  chatHolderDiv.classList.add("alan-text-chat__closing");
98345
- rootEl.classList.add("text-chat-is-closing");
98381
+ if (options.textChat?.showBtnIfChatOpen !== true) {
98382
+ rootEl.classList.add("text-chat-is-closing");
98383
+ }
98346
98384
  setTimeout(() => {
98347
98385
  chatHolderDiv.style.display = "none";
98348
98386
  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");
98387
+ if (options.textChat?.showBtnIfChatOpen !== true) {
98388
+ rootEl.classList.remove("hide-alan-btn-when-text-chat-is-opened");
98389
+ rootEl.classList.remove("hide-alan-btn-when-text-chat-is-opened-immediately");
98390
+ }
98351
98391
  rootEl.classList.remove("text-chat-is-closing");
98352
98392
  fixPopupScrollOnMobileForTextChat(false);
98353
98393
  }, uiState.textChat.defaults.appearAnimationMs);
@@ -98366,26 +98406,47 @@ ${LEARN_MORE_LABEL}
98366
98406
  }
98367
98407
  function closeTextChat() {
98368
98408
  textChatWasClosedManually = true;
98369
- if (options.onEvent) {
98370
- options.onEvent({ name: "textChatClosed" });
98371
- }
98372
98409
  if (options?.textChat?.onClose) {
98373
98410
  options?.textChat?.onClose();
98411
+ }
98412
+ const closeDelay = options?.textChat?.closeDelay;
98413
+ if (closeDelay) {
98414
+ clearTimeout(closeChatTimeoutId);
98415
+ closeChatTimeoutId = setTimeout(() => {
98416
+ _closeChat();
98417
+ }, closeDelay);
98374
98418
  } else {
98375
- hideTextChat();
98419
+ _closeChat();
98420
+ }
98421
+ }
98422
+ function _closeChat() {
98423
+ if (options.onEvent) {
98424
+ options.onEvent({ name: "textChatClosed" });
98376
98425
  }
98426
+ hideTextChat();
98377
98427
  if (uiState.textChat.options?.popup?.clearChatOnClose === true) {
98378
98428
  onClearTextChatBtnClick();
98379
98429
  }
98380
98430
  }
98381
- function minimizeTextChat() {
98431
+ function _minimizeChat() {
98382
98432
  if (options.onEvent) {
98383
98433
  options.onEvent({ name: "textChatMinimized" });
98384
98434
  }
98435
+ hideTextChat();
98436
+ }
98437
+ function minimizeTextChat() {
98438
+ textChatWasClosedManually = true;
98385
98439
  if (options?.textChat?.onMinimize) {
98386
98440
  options?.textChat?.onMinimize();
98441
+ }
98442
+ const closeDelay = options?.textChat?.closeDelay;
98443
+ if (closeDelay) {
98444
+ clearTimeout(closeChatTimeoutId);
98445
+ closeChatTimeoutId = setTimeout(() => {
98446
+ _minimizeChat();
98447
+ }, closeDelay);
98387
98448
  } else {
98388
- hideTextChat();
98449
+ _minimizeChat();
98389
98450
  }
98390
98451
  }
98391
98452
  function expandCollapseChatSidePanel() {
@@ -98509,7 +98570,7 @@ ${LEARN_MORE_LABEL}
98509
98570
  changeBgColors(DEFAULT);
98510
98571
  micIconDiv.style.opacity = "1";
98511
98572
  roundedTriangleIconDiv.style.opacity = "0";
98512
- disconnectedMicLoaderIconImg.style.opacity = "0";
98573
+ disconnectedMicLoaderIconImg.style.opacity = "1";
98513
98574
  changeCustomLogoVisibility(
98514
98575
  defaultStateBtnIconImg,
98515
98576
  [
@@ -98880,13 +98941,20 @@ ${LEARN_MORE_LABEL}
98880
98941
  }
98881
98942
  function showBtn() {
98882
98943
  rootEl.innerHTML = "";
98883
- if (!isInlinedMode()) {
98884
- recognisedTextHolder.appendChild(recognisedTextContent);
98885
- rootEl.appendChild(recognisedTextHolder);
98886
- rootEl.appendChild(btn);
98887
- btn.appendChild(chatNotificationsBubble);
98944
+ recognisedTextHolder.appendChild(recognisedTextContent);
98945
+ rootEl.appendChild(recognisedTextHolder);
98946
+ rootEl.appendChild(btn);
98947
+ btn.appendChild(chatNotificationsBubble);
98948
+ if (isInlinedMode()) {
98949
+ if (options.chatEl) {
98950
+ options.chatEl.append(chatHolderDiv);
98951
+ } else {
98952
+ console.error("Text Chat element is not defined. Set chatEl in Alan Button options");
98953
+ return;
98954
+ }
98955
+ } else {
98956
+ rootEl.appendChild(chatHolderDiv);
98888
98957
  }
98889
- rootEl.appendChild(chatHolderDiv);
98890
98958
  resizeTextArea();
98891
98959
  btnDisabled = false;
98892
98960
  }
@@ -98957,6 +99025,13 @@ ${LEARN_MORE_LABEL}
98957
99025
  }
98958
99026
  rootEl.classList.add("alanBtn-root");
98959
99027
  rootEl.classList.add("alan-" + getProjectId());
99028
+ if (options.chatEl) {
99029
+ options.chatEl.classList.add("alanBtn-root");
99030
+ if (isInlinedMode()) {
99031
+ options.chatEl.classList.add("alanBtn-chat-root-inlined");
99032
+ }
99033
+ options.chatEl.classList.add("alan-" + getProjectId());
99034
+ }
98960
99035
  var alanBtnSavedOptions = null;
98961
99036
  if (isTutorMode()) {
98962
99037
  showBtn();
@@ -99032,10 +99107,10 @@ ${LEARN_MORE_LABEL}
99032
99107
  rootEl.style.setProperty("top", dndBtnTopPos + "px", "important");
99033
99108
  rootEl.style.setProperty("bottom", "auto", "important");
99034
99109
  }
99035
- if (Math.abs(tempDeltaX) > 15 || Math.abs(tempDeltaY) > 15) {
99110
+ if ((Math.abs(tempDeltaX) > 15 || Math.abs(tempDeltaY) > 15) && !isInlinedMode()) {
99036
99111
  hideTextChat();
99037
- afterMouseMove = true;
99038
99112
  }
99113
+ afterMouseMove = true;
99039
99114
  newLeftPos = dndBtnLeftPos + posInfo.clientX - dndInitMousePos2[0];
99040
99115
  newTopPos = dndBtnTopPos + posInfo.clientY - dndInitMousePos2[1];
99041
99116
  tempDeltaX = posInfo.clientX - dndInitMousePos2[0];