@buni.ai/chatbot-angular 1.0.27 → 1.0.29
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.esm.js +71 -67
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +71 -67
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.esm.js
CHANGED
|
@@ -354,12 +354,12 @@ class BuniChatWidget {
|
|
|
354
354
|
if (event.source === ((_j = this.chatIframe) === null || _j === void 0 ? void 0 : _j.contentWindow) &&
|
|
355
355
|
event.origin === this.getBaseUrl()) {
|
|
356
356
|
if (this.isMinimalModeEnabled()) {
|
|
357
|
-
if (!this.state.isOpen) {
|
|
358
|
-
void this.openChat();
|
|
359
|
-
}
|
|
360
357
|
this.postMessageToWidget("minimize");
|
|
358
|
+
this.applyMinimalContainerFrame();
|
|
361
359
|
this.displayMode = "minimal";
|
|
362
360
|
this.state.displayMode = "minimal";
|
|
361
|
+
this.state.isOpen = true;
|
|
362
|
+
this.state.isMinimized = false;
|
|
363
363
|
}
|
|
364
364
|
else {
|
|
365
365
|
this.closeChat();
|
|
@@ -512,56 +512,47 @@ class BuniChatWidget {
|
|
|
512
512
|
async openChatInMinimalMode() {
|
|
513
513
|
if (!this.chatIframe || !this.widgetElement || !this.triggerIframe)
|
|
514
514
|
return;
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
const
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
: isTablet
|
|
533
|
-
? "min(calc(100vw - 3rem), 370px)"
|
|
534
|
-
: widthValue;
|
|
535
|
-
const chatHeight = isMobile
|
|
536
|
-
? "100vh"
|
|
537
|
-
: isTablet
|
|
538
|
-
? "min(calc(100vh - 3rem), 620px)"
|
|
539
|
-
: heightValue;
|
|
540
|
-
// Size container to full chat dimensions initially (iframe needs space to render)
|
|
515
|
+
this.applyMinimalContainerFrame();
|
|
516
|
+
this.state.isMinimized = false;
|
|
517
|
+
this.state.isOpen = true;
|
|
518
|
+
this.displayMode = "minimal";
|
|
519
|
+
this.state.displayMode = "minimal";
|
|
520
|
+
// Ask the iframe to enter minimal mode; it will reply with "minimized" when ready
|
|
521
|
+
this.postMessageToWidget("minimize");
|
|
522
|
+
this.emit("minimized", { timestamp: Date.now() });
|
|
523
|
+
}
|
|
524
|
+
applyMinimalContainerFrame() {
|
|
525
|
+
var _a;
|
|
526
|
+
if (!this.widgetElement || !this.chatIframe || !this.triggerIframe)
|
|
527
|
+
return;
|
|
528
|
+
const position = ((_a = this.options.config) === null || _a === void 0 ? void 0 : _a.position) || "bottom-right";
|
|
529
|
+
// Use a conservative initial height; the iframe will report the exact
|
|
530
|
+
// rendered card height via "minimal_card_size" and we'll resize then.
|
|
531
|
+
const initialMinimalHeight = "420px";
|
|
541
532
|
this.widgetElement.style.cssText = `
|
|
542
533
|
position: fixed;
|
|
543
534
|
pointer-events: none;
|
|
544
535
|
z-index: 999999;
|
|
545
|
-
width:
|
|
546
|
-
|
|
547
|
-
|
|
536
|
+
width: min(calc(100vw - 1.5rem), 390px);
|
|
537
|
+
max-width: min(calc(100vw - 1.5rem), 390px);
|
|
538
|
+
height: ${initialMinimalHeight};
|
|
539
|
+
max-height: ${initialMinimalHeight};
|
|
548
540
|
transition: width 0.3s ease, height 0.3s ease, border-radius 0.3s ease;
|
|
549
|
-
${this.getPositionStyles(
|
|
541
|
+
${this.getPositionStyles(position, true)}
|
|
550
542
|
display: block;
|
|
551
|
-
overflow:
|
|
543
|
+
overflow: hidden;
|
|
544
|
+
border-radius: 16px;
|
|
545
|
+
box-shadow: 0 18px 40px -24px rgba(15, 23, 42, 0.45);
|
|
552
546
|
box-sizing: border-box;
|
|
553
547
|
`;
|
|
554
|
-
// Hide trigger, show chat iframe
|
|
555
548
|
this.triggerIframe.style.display = "none";
|
|
556
549
|
this.chatIframe.style.display = "block";
|
|
557
550
|
this.chatIframe.style.visibility = "visible";
|
|
558
|
-
this.
|
|
559
|
-
this.
|
|
560
|
-
this.
|
|
561
|
-
this.
|
|
562
|
-
|
|
563
|
-
this.postMessageToWidget("minimize");
|
|
564
|
-
this.emit("minimized", { timestamp: Date.now() });
|
|
551
|
+
this.chatIframe.style.width = "100%";
|
|
552
|
+
this.chatIframe.style.height = initialMinimalHeight;
|
|
553
|
+
this.chatIframe.style.maxHeight = initialMinimalHeight;
|
|
554
|
+
this.chatIframe.style.borderRadius = "0";
|
|
555
|
+
this.chatIframe.style.boxShadow = "none";
|
|
565
556
|
}
|
|
566
557
|
async openChat() {
|
|
567
558
|
if (!this.chatIframe || !this.widgetElement || !this.triggerIframe)
|
|
@@ -612,6 +603,11 @@ class BuniChatWidget {
|
|
|
612
603
|
this.triggerIframe.style.display = "none";
|
|
613
604
|
this.chatIframe.style.display = "block";
|
|
614
605
|
this.chatIframe.style.visibility = "visible";
|
|
606
|
+
// Restore full-mode iframe styles that may have been overridden in minimal mode
|
|
607
|
+
this.chatIframe.style.height = "100%";
|
|
608
|
+
this.chatIframe.style.maxHeight = "100%";
|
|
609
|
+
this.chatIframe.style.borderRadius = isMobile ? "0" : "16px";
|
|
610
|
+
this.chatIframe.style.boxShadow = isMobile ? "none" : "0 8px 32px rgba(0,0,0,0.15)";
|
|
615
611
|
this.state.isMinimized = false;
|
|
616
612
|
this.state.isOpen = true;
|
|
617
613
|
this.displayMode = "full";
|
|
@@ -698,7 +694,7 @@ class BuniChatWidget {
|
|
|
698
694
|
setupPostMessageAPI(iframe) {
|
|
699
695
|
// Listen for messages from the iframe
|
|
700
696
|
window.addEventListener("message", (event) => {
|
|
701
|
-
var _a
|
|
697
|
+
var _a;
|
|
702
698
|
if (event.source !== iframe.contentWindow) {
|
|
703
699
|
return;
|
|
704
700
|
}
|
|
@@ -740,45 +736,34 @@ class BuniChatWidget {
|
|
|
740
736
|
this.options.onNewMessage(data);
|
|
741
737
|
}
|
|
742
738
|
break;
|
|
743
|
-
case "minimized":
|
|
739
|
+
case "minimized": {
|
|
744
740
|
this.syncServerBehaviorFromData(data);
|
|
741
|
+
const reportedDisplayMode = (data === null || data === void 0 ? void 0 : data.displayMode) === "minimal" || (data === null || data === void 0 ? void 0 : data.displayMode) === "hidden"
|
|
742
|
+
? data.displayMode
|
|
743
|
+
: null;
|
|
744
|
+
if (reportedDisplayMode === "hidden") {
|
|
745
|
+
this.closeChat();
|
|
746
|
+
this.displayMode = "hidden";
|
|
747
|
+
this.state.displayMode = "hidden";
|
|
748
|
+
break;
|
|
749
|
+
}
|
|
745
750
|
if (this.isMinimalModeEnabled()) {
|
|
746
751
|
this.displayMode = "minimal";
|
|
747
752
|
this.state.displayMode = "minimal";
|
|
748
753
|
this.state.isOpen = true;
|
|
749
754
|
this.state.isMinimized = false;
|
|
750
|
-
|
|
751
|
-
if (this.widgetElement && this.chatIframe && this.triggerIframe) {
|
|
752
|
-
const position = ((_a = this.options.config) === null || _a === void 0 ? void 0 : _a.position) || "bottom-right";
|
|
753
|
-
this.widgetElement.style.cssText = `
|
|
754
|
-
position: fixed;
|
|
755
|
-
pointer-events: none;
|
|
756
|
-
z-index: 999999;
|
|
757
|
-
width: min(calc(100vw - 1.5rem), 390px);
|
|
758
|
-
max-width: min(calc(100vw - 1.5rem), 390px);
|
|
759
|
-
height: auto;
|
|
760
|
-
transition: width 0.3s ease, height 0.3s ease, border-radius 0.3s ease;
|
|
761
|
-
${this.getPositionStyles(position, true)}
|
|
762
|
-
display: block;
|
|
763
|
-
overflow: visible;
|
|
764
|
-
box-sizing: border-box;
|
|
765
|
-
`;
|
|
766
|
-
this.triggerIframe.style.display = "none";
|
|
767
|
-
this.chatIframe.style.display = "block";
|
|
768
|
-
this.chatIframe.style.visibility = "visible";
|
|
769
|
-
this.chatIframe.style.width = "100%";
|
|
770
|
-
this.chatIframe.style.height = "min(calc(100vh - 1.5rem), 520px)";
|
|
771
|
-
}
|
|
755
|
+
this.applyMinimalContainerFrame();
|
|
772
756
|
}
|
|
773
757
|
else {
|
|
774
758
|
// Backward-compatible behavior.
|
|
775
759
|
this.closeChat();
|
|
776
760
|
}
|
|
777
761
|
break;
|
|
762
|
+
}
|
|
778
763
|
case "new_unread_message":
|
|
779
764
|
// Update unread count in trigger
|
|
780
765
|
this.state.unreadCount++;
|
|
781
|
-
if ((
|
|
766
|
+
if ((_a = this.triggerIframe) === null || _a === void 0 ? void 0 : _a.contentWindow) {
|
|
782
767
|
this.triggerIframe.contentWindow.postMessage({ type: "updateUnreadCount", count: this.state.unreadCount }, window.location.origin);
|
|
783
768
|
}
|
|
784
769
|
break;
|
|
@@ -796,6 +781,25 @@ class BuniChatWidget {
|
|
|
796
781
|
this.options.onError(data.error);
|
|
797
782
|
}
|
|
798
783
|
break;
|
|
784
|
+
case "maximized":
|
|
785
|
+
// The iframe has switched to full mode (e.g. user clicked expand from
|
|
786
|
+
// minimal card). Resize the host container to the configured full size.
|
|
787
|
+
void this.openChat();
|
|
788
|
+
break;
|
|
789
|
+
case "minimal_card_size":
|
|
790
|
+
// The iframe reports its rendered card height so we can shrink the
|
|
791
|
+
// container to wrap the card tightly. Without this the host-page
|
|
792
|
+
// box-shadow renders around the full container, appearing as padding.
|
|
793
|
+
// Only apply when still in minimal mode to avoid overriding a pending
|
|
794
|
+
// full-mode transition.
|
|
795
|
+
if (this.widgetElement && this.chatIframe && (data === null || data === void 0 ? void 0 : data.height) > 0 && this.displayMode === "minimal") {
|
|
796
|
+
const h = `${data.height}px`;
|
|
797
|
+
this.widgetElement.style.height = h;
|
|
798
|
+
this.widgetElement.style.maxHeight = h;
|
|
799
|
+
this.chatIframe.style.height = h;
|
|
800
|
+
this.chatIframe.style.maxHeight = h;
|
|
801
|
+
}
|
|
802
|
+
break;
|
|
799
803
|
}
|
|
800
804
|
});
|
|
801
805
|
}
|