embeddedaichatux 1.7.0 → 1.7.1

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 (2) hide show
  1. package/EmbeddedChat.js +74 -22
  2. package/package.json +1 -1
package/EmbeddedChat.js CHANGED
@@ -74,7 +74,7 @@
74
74
  this.addEventListeners();
75
75
  }
76
76
 
77
- updateIframes() {
77
+ async updateIframes() {
78
78
  const cleanedServerUrl = this.serverUrl.endsWith('/') ? this.serverUrl.slice(0, -1) : this.serverUrl;
79
79
  const baseIframeUrl = `${cleanedServerUrl}/ChatUX/${this.chatId}`;
80
80
  const minimizedPositionStyle = `position: fixed; right: 0; bottom: 0; width: ${this.width}px; height: ${this.minimizedHeight}; z-index: 100000; ${this.enableAnimation ? 'transition: height 0.3s ease, opacity 0.3s ease;' : ''}`;
@@ -87,6 +87,8 @@
87
87
  this.containerDiv.innerHTML = iframeHtml;
88
88
  this.iframe = this.containerDiv.querySelector("#embedded-chat");
89
89
  this.minimizedIframe = this.containerDiv.querySelector("#embedded-chat-minimized");
90
+
91
+ await this.waitForIframeLoad(this.iframe);
90
92
  }
91
93
 
92
94
  addEventListeners() {
@@ -110,9 +112,9 @@
110
112
  if (typeof e.data === "object" && (!e.data.chatId || e.data.chatId === this.chatId)) {
111
113
  const updates = {};
112
114
 
113
- // Preserve minimize on scroll functionality
114
- if (e.data.type === "setMinimizeOnScroll") {
115
- this.minimizeOnScroll = e.data.value === "true";
115
+ if (e.data.type === "setMinimizeOnScroll" || e.data.minimizeOnScroll !== undefined) {
116
+ const minimizeValue = e.data.type === "setMinimizeOnScroll" ? e.data.value : e.data.minimizeOnScroll;
117
+ this.minimizeOnScroll = minimizeValue === true || minimizeValue === "true";
116
118
  }
117
119
 
118
120
  // Collect updates for locale, width, and scale
@@ -138,7 +140,8 @@
138
140
  this.animateMinimize();
139
141
  }
140
142
  } else if (e.data.message === "show" || e.data.message === "maximize") {
141
- this.showMaximized();
143
+ const animate = e.data.animate === true;
144
+ this.showMaximized(animate);
142
145
  }
143
146
  }
144
147
 
@@ -170,6 +173,31 @@
170
173
  }
171
174
  }
172
175
 
176
+ animateMaximize() {
177
+ if (this.mode !== 'ContactForm') {
178
+ // Start the animation for minimizing iframe
179
+ this.minimizedIframe.style.height = `${this.height}px`;
180
+ this.minimizedIframe.style.opacity = '0';
181
+
182
+ setTimeout(() => {
183
+ // Hide the minimized iframe
184
+ this.minimizedIframe.style.display = "none";
185
+ this.minimizedIframe.style.opacity = '1'; // Reset opacity
186
+
187
+ // Show and animate the main iframe
188
+ this.iframe.style.display = "block";
189
+ this.iframe.style.height = this.minimizedHeight; // Start with minimized height
190
+ this.iframe.style.opacity = '0'; // Start with zero opacity
191
+
192
+ // Trigger the maximize animation
193
+ setTimeout(() => {
194
+ this.iframe.style.height = `${this.height}px`; // Animate to full height
195
+ this.iframe.style.opacity = '1'; // Animate opacity to full
196
+ }, 10); // Small delay to allow display changes to take effect
197
+ }, this.enableAnimation ? 300 : 0); // Match the minimize animation duration
198
+ }
199
+ }
200
+
173
201
  applyIframeUpdates({ locale, width, scale } = {}) {
174
202
  // Update locale if provided and different (but do not update the iframe URL)
175
203
  if (locale && typeof locale === 'string' && locale !== this.locale) {
@@ -212,26 +240,29 @@
212
240
  }
213
241
 
214
242
 
215
- showMaximized() {
216
- this.minimizedIframe.style.display = "none";
217
-
218
- this.minimizedIframe.style.height = `${this.height}px`;
219
- this.minimizedIframe.style.opacity = ''; // Reset opacity to unset
220
-
221
- this.iframe.style.display = "block";
222
-
223
- if (this.isSafari() && !this.hasRefreshed) {
224
- // Force refresh by resetting the iframe's src
225
- const currentSrc = this.iframe.src;
226
- this.iframe.src = ''; // Temporarily clear the src
227
- this.iframe.src = currentSrc; // Reset to the original src to trigger a reload
228
- this.hasRefreshed = true; // Prevent endless loop
243
+ showMaximized(animate = false) {
244
+ if (animate) {
245
+ this.animateMaximize();
229
246
  }
247
+ else {
248
+ this.minimizedIframe.style.display = "none";
249
+ this.minimizedIframe.style.height = `${this.height}px`;
250
+ this.minimizedIframe.style.opacity = ''; // Reset opacity to unset
251
+
252
+ this.iframe.style.display = "block";
253
+
254
+ if (this.isSafari() && !this.hasRefreshed) {
255
+ const currentSrc = this.iframe.src;
256
+ this.iframe.src = ''; // Temporarily clear the src
257
+ this.iframe.src = currentSrc; // Reset to the original src to trigger a reload
258
+ this.hasRefreshed = true; // Prevent endless loop
259
+ }
230
260
 
231
- this.iframe.style.height = `${this.height}px`;
232
- this.iframe.style.opacity = '1';
261
+ this.iframe.style.height = `${this.height}px`;
262
+ this.iframe.style.opacity = '1';
233
263
 
234
- this.iframe.contentWindow.postMessage({ message: "show" }, "*");
264
+ this.iframe.contentWindow.postMessage({ message: "show" }, "*");
265
+ }
235
266
  }
236
267
 
237
268
  applyScale(scale) {
@@ -300,6 +331,27 @@
300
331
 
301
332
  return `${baseIframeUrl}?${urlParams.toString()}`;
302
333
  }
334
+
335
+ waitForIframeLoad(iframe, timeout = 5000) {
336
+ return new Promise((resolve, reject) => {
337
+ // Check if the iframe is already loaded
338
+ if (iframe.contentDocument || iframe.contentWindow) {
339
+ resolve();
340
+ return;
341
+ }
342
+
343
+ // Set up a timeout to avoid waiting indefinitely
344
+ const timeoutId = setTimeout(() => {
345
+ reject(new Error('Iframe did not load within the timeout period.'));
346
+ }, timeout);
347
+
348
+ // Add the load event listener
349
+ iframe.addEventListener('load', () => {
350
+ clearTimeout(timeoutId); // Clear the timeout
351
+ resolve();
352
+ }, { once: true }); // Ensure the listener is triggered only once
353
+ });
354
+ }
303
355
  }
304
356
 
305
357
  export function initEmbeddedChat(containerDiv, chatId, options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "embeddedaichatux",
3
- "version": "1.7.0",
3
+ "version": "1.7.1",
4
4
  "description": "A lightweight and customizable embedded AI chat UI component that seamlessly integrates into web applications, offering minimized and expanded views, with iframe-based content rendering.",
5
5
  "main": "EmbeddedChat.js",
6
6
  "scripts": {