@buni.ai/chatbot-angular 1.0.25 → 1.0.26
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 +85 -10
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +85 -10
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -305,7 +305,7 @@ class BuniChatWidget {
|
|
|
305
305
|
};
|
|
306
306
|
// Listen for trigger and connection events
|
|
307
307
|
window.addEventListener("message", (event) => {
|
|
308
|
-
var _a, _b, _c, _d, _e, _f;
|
|
308
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
309
309
|
const payload = event.data;
|
|
310
310
|
if (!payload || typeof payload !== "object")
|
|
311
311
|
return;
|
|
@@ -317,26 +317,35 @@ class BuniChatWidget {
|
|
|
317
317
|
if (event.source === ((_a = this.chatIframe) === null || _a === void 0 ? void 0 : _a.contentWindow) &&
|
|
318
318
|
event.origin === this.getBaseUrl()) {
|
|
319
319
|
this.syncServerBehaviorFromData(payload.data);
|
|
320
|
-
|
|
321
|
-
|
|
320
|
+
const effectiveDefaultMode = (_d = (_c = (_b = this.options.config) === null || _b === void 0 ? void 0 : _b.defaultMode) !== null && _c !== void 0 ? _c : this.serverBehavior.defaultMode) !== null && _d !== void 0 ? _d : "full";
|
|
321
|
+
const effectiveMinimalEnabled = this.isMinimalModeEnabled();
|
|
322
|
+
if (effectiveMinimalEnabled && effectiveDefaultMode === "minimal") {
|
|
323
|
+
// Auto-open in minimal card mode
|
|
324
|
+
void this.openChatInMinimalMode();
|
|
325
|
+
}
|
|
326
|
+
else if ((_e = this.options.config) === null || _e === void 0 ? void 0 : _e.autoOpen) {
|
|
327
|
+
void this.openChat();
|
|
328
|
+
}
|
|
329
|
+
else if (container && !config.hideDefaultTrigger) {
|
|
330
|
+
// Show the trigger button
|
|
322
331
|
container.style.display = "block";
|
|
323
332
|
}
|
|
324
333
|
// Emit connection_ready event for consumers
|
|
325
334
|
this.emit("connection_ready", {
|
|
326
335
|
timestamp: Date.now(),
|
|
327
|
-
behavior: (
|
|
336
|
+
behavior: (_f = payload.data) === null || _f === void 0 ? void 0 : _f.behavior,
|
|
328
337
|
});
|
|
329
338
|
if (this.options.onConnectionReady &&
|
|
330
339
|
typeof this.options.onConnectionReady === "function") {
|
|
331
340
|
this.options.onConnectionReady({
|
|
332
341
|
timestamp: Date.now(),
|
|
333
|
-
behavior: (
|
|
342
|
+
behavior: (_g = payload.data) === null || _g === void 0 ? void 0 : _g.behavior,
|
|
334
343
|
});
|
|
335
344
|
}
|
|
336
345
|
}
|
|
337
346
|
break;
|
|
338
347
|
case "chatbot:close":
|
|
339
|
-
if (event.source === ((
|
|
348
|
+
if (event.source === ((_h = this.chatIframe) === null || _h === void 0 ? void 0 : _h.contentWindow) &&
|
|
340
349
|
event.origin === this.getBaseUrl()) {
|
|
341
350
|
this.closeChat();
|
|
342
351
|
this.displayMode = "hidden";
|
|
@@ -344,7 +353,7 @@ class BuniChatWidget {
|
|
|
344
353
|
}
|
|
345
354
|
break;
|
|
346
355
|
case "chatbot:minimize":
|
|
347
|
-
if (event.source === ((
|
|
356
|
+
if (event.source === ((_j = this.chatIframe) === null || _j === void 0 ? void 0 : _j.contentWindow) &&
|
|
348
357
|
event.origin === this.getBaseUrl()) {
|
|
349
358
|
if (this.isMinimalModeEnabled()) {
|
|
350
359
|
if (!this.state.isOpen) {
|
|
@@ -362,7 +371,7 @@ class BuniChatWidget {
|
|
|
362
371
|
}
|
|
363
372
|
break;
|
|
364
373
|
case "trigger_clicked":
|
|
365
|
-
if (event.source === ((
|
|
374
|
+
if (event.source === ((_k = this.triggerIframe) === null || _k === void 0 ? void 0 : _k.contentWindow) &&
|
|
366
375
|
event.origin === window.location.origin) {
|
|
367
376
|
this.openChat();
|
|
368
377
|
}
|
|
@@ -502,11 +511,65 @@ class BuniChatWidget {
|
|
|
502
511
|
</body>
|
|
503
512
|
</html>`;
|
|
504
513
|
}
|
|
514
|
+
async openChatInMinimalMode() {
|
|
515
|
+
if (!this.chatIframe || !this.widgetElement || !this.triggerIframe)
|
|
516
|
+
return;
|
|
517
|
+
const config = this.options.config || {};
|
|
518
|
+
const isMobile = window.innerWidth <= 768;
|
|
519
|
+
const isTablet = window.innerWidth > 768 && window.innerWidth <= 1024;
|
|
520
|
+
const ensureUnits = (value, defaultValue) => {
|
|
521
|
+
if (!value)
|
|
522
|
+
return defaultValue;
|
|
523
|
+
const str = String(value);
|
|
524
|
+
if (str.match(/^[\d.]+\s*(px|em|rem|%|vh|vw)$/))
|
|
525
|
+
return str;
|
|
526
|
+
if (str.match(/^[\d.]+$/))
|
|
527
|
+
return `${str}px`;
|
|
528
|
+
return str;
|
|
529
|
+
};
|
|
530
|
+
const widthValue = ensureUnits(config.width, "350px");
|
|
531
|
+
const heightValue = ensureUnits(config.height, "650px");
|
|
532
|
+
const chatWidth = isMobile
|
|
533
|
+
? "100vw"
|
|
534
|
+
: isTablet
|
|
535
|
+
? "min(calc(100vw - 3rem), 370px)"
|
|
536
|
+
: widthValue;
|
|
537
|
+
const chatHeight = isMobile
|
|
538
|
+
? "100vh"
|
|
539
|
+
: isTablet
|
|
540
|
+
? "min(calc(100vh - 3rem), 620px)"
|
|
541
|
+
: heightValue;
|
|
542
|
+
// Size container to full chat dimensions initially (iframe needs space to render)
|
|
543
|
+
this.widgetElement.style.cssText = `
|
|
544
|
+
position: fixed;
|
|
545
|
+
pointer-events: none;
|
|
546
|
+
z-index: 999999;
|
|
547
|
+
width: ${chatWidth};
|
|
548
|
+
height: ${chatHeight};
|
|
549
|
+
${isMobile ? "max-width: 100vw; max-height: 100vh;" : ""}
|
|
550
|
+
transition: width 0.3s ease, height 0.3s ease, border-radius 0.3s ease;
|
|
551
|
+
${this.getPositionStyles(config.position || "bottom-right", false)}
|
|
552
|
+
display: block;
|
|
553
|
+
overflow: visible;
|
|
554
|
+
box-sizing: border-box;
|
|
555
|
+
`;
|
|
556
|
+
// Hide trigger, show chat iframe
|
|
557
|
+
this.triggerIframe.style.display = "none";
|
|
558
|
+
this.chatIframe.style.display = "block";
|
|
559
|
+
this.chatIframe.style.visibility = "visible";
|
|
560
|
+
this.state.isMinimized = false;
|
|
561
|
+
this.state.isOpen = true;
|
|
562
|
+
this.displayMode = "minimal";
|
|
563
|
+
this.state.displayMode = "minimal";
|
|
564
|
+
// Ask the iframe to enter minimal mode; it will reply with "minimized" when ready
|
|
565
|
+
this.postMessageToWidget("minimize");
|
|
566
|
+
this.emit("minimized", { timestamp: Date.now() });
|
|
567
|
+
}
|
|
505
568
|
async openChat() {
|
|
506
569
|
if (!this.chatIframe || !this.widgetElement || !this.triggerIframe)
|
|
507
570
|
return;
|
|
508
|
-
if (this.state.isOpen)
|
|
509
|
-
return; // Already open
|
|
571
|
+
if (this.state.isOpen && this.displayMode !== "minimal")
|
|
572
|
+
return; // Already open in full mode
|
|
510
573
|
const config = this.options.config || {};
|
|
511
574
|
const isMobile = window.innerWidth <= 768;
|
|
512
575
|
const isTablet = window.innerWidth > 768 && window.innerWidth <= 1024;
|
|
@@ -687,6 +750,18 @@ class BuniChatWidget {
|
|
|
687
750
|
}
|
|
688
751
|
this.displayMode = "minimal";
|
|
689
752
|
this.state.displayMode = "minimal";
|
|
753
|
+
// Shrink container to actual minimal card size
|
|
754
|
+
if (this.widgetElement && this.chatIframe) {
|
|
755
|
+
const isMobile = window.innerWidth <= 768;
|
|
756
|
+
if (!isMobile) {
|
|
757
|
+
this.widgetElement.style.width =
|
|
758
|
+
"min(calc(100vw - 1.5rem), 390px)";
|
|
759
|
+
this.widgetElement.style.height = "auto";
|
|
760
|
+
this.widgetElement.style.overflow = "visible";
|
|
761
|
+
this.chatIframe.style.height = "520px";
|
|
762
|
+
this.chatIframe.style.width = "100%";
|
|
763
|
+
}
|
|
764
|
+
}
|
|
690
765
|
}
|
|
691
766
|
else {
|
|
692
767
|
// Backward-compatible behavior.
|