embeddedaichatux 1.7.2 → 1.8.0

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 +91 -11
  2. package/package.json +1 -1
package/EmbeddedChat.js CHANGED
@@ -12,6 +12,7 @@
12
12
  this.serverUrl = this.options.serverUrl || 'https://embedgpt.chat/';
13
13
  this.height = options.height || 600; // Default height
14
14
  this.width = options.width || 320; // Default width
15
+ this.marginBottom = options.marginBottom || 0;
15
16
  this.enableAnimation = options.enableAnimation !== false; // Default to true if not provided
16
17
  this.minimizedHeight = `${this.height * 0.3}px`; // 30% of the full height
17
18
  this.mouseInsideChat = false;
@@ -23,7 +24,7 @@
23
24
 
24
25
  this.positionStyle = this.containerDiv.dataset.position === 'in-place' ?
25
26
  `width:100%; height:${this.height}px; ${transitionStyle}` :
26
- `position: fixed; right: 1em; bottom: 0; width: ${this.width}px; height: ${this.height}px; z-index: 100000; max-width:80%; ${transitionStyle}`;
27
+ `position: fixed; right: 1em; bottom: 0; width: ${this.width}px; z-index: 100000; max-width:90vw; max-height: 90vh; ${transitionStyle}`;
27
28
  this.mode = options.mode || 'Chat'; // default to 'chat'
28
29
  this.minimizeOnScroll = false; // Default to false
29
30
  if (this.mode === 'ContactForm') {
@@ -89,6 +90,11 @@
89
90
  this.minimizedIframe = this.containerDiv.querySelector("#embedded-chat-minimized");
90
91
 
91
92
  await this.waitForIframeLoad(this.iframe);
93
+
94
+ if (this.mode === 'ContactForm') {
95
+ this.iframe.style.maxWidth = "100%";
96
+ this.iframe.style.display = "block";
97
+ }
92
98
  }
93
99
 
94
100
  addEventListeners() {
@@ -106,6 +112,24 @@
106
112
  this.minimizeOnScrollAction();
107
113
  }
108
114
  });
115
+
116
+ window.addEventListener("load", () => {
117
+ this.postResizeMessage();
118
+ });
119
+
120
+ window.addEventListener("resize", () => {
121
+ this.postResizeMessage();
122
+ });
123
+ }
124
+
125
+ postResizeMessage() {
126
+ if (this.iframe?.contentWindow) {
127
+ this.iframe.contentWindow.postMessage({
128
+ message: "resize",
129
+ width: window.innerWidth, // Ensure correct size
130
+ height: window.innerHeight
131
+ }, "*");
132
+ }
109
133
  }
110
134
 
111
135
  handleMessage(e) {
@@ -117,18 +141,23 @@
117
141
  this.minimizeOnScroll = minimizeValue === true || minimizeValue === "true";
118
142
  }
119
143
 
120
- // Collect updates for locale, width, and scale
121
144
  if (e.data.locale) {
122
145
  updates.locale = e.data.locale;
123
146
  }
124
147
  if (e.data.width) {
125
148
  updates.width = e.data.width;
126
149
  }
150
+ if (e.data.height) {
151
+ updates.height = e.data.height;
152
+ }
153
+ if (e.data.marginBottom) {
154
+ updates.marginBottom = e.data.marginBottom;
155
+ }
127
156
  if (e.data.scale) {
128
157
  updates.scale = e.data.scale;
129
158
  }
130
159
 
131
- // Apply iframe updates (locale, width, scale) in one go
160
+ // Apply iframe updates in one go
132
161
  if (Object.keys(updates).length > 0) {
133
162
  this.applyIframeUpdates(updates);
134
163
  }
@@ -201,7 +230,7 @@
201
230
  }
202
231
  }
203
232
 
204
- applyIframeUpdates({ locale, width, scale } = {}) {
233
+ applyIframeUpdates({ locale, width, height, marginBottom, scale } = {}) {
205
234
  // Update locale if provided and different (but do not update the iframe URL)
206
235
  if (locale && typeof locale === 'string' && locale !== this.locale) {
207
236
  this.locale = locale;
@@ -240,8 +269,65 @@
240
269
  }
241
270
  console.log(`Scale applied: ${scale}`);
242
271
  }
243
- }
244
272
 
273
+ // Handle height and marginBottom
274
+ let parsedHeight = parseInt(height, 10);
275
+ let parsedMarginBottom = parseInt(marginBottom, 10);
276
+
277
+ // Default to existing values if not provided or invalid
278
+ if (isNaN(parsedHeight) || parsedHeight <= 0) {
279
+ parsedHeight = this.height;
280
+ }
281
+ if (isNaN(parsedMarginBottom) || parsedMarginBottom < 0) {
282
+ parsedMarginBottom = (typeof this.marginBottom === 'number') ? this.marginBottom : 0;
283
+ }
284
+
285
+ // Clamp so that height + marginBottom doesn't exceed 90% of viewport
286
+ const viewportHeight = window.innerHeight;
287
+ if (parsedHeight + parsedMarginBottom > 0.9 * viewportHeight) {
288
+ parsedHeight = Math.max(0, 0.9 * viewportHeight - parsedMarginBottom);
289
+ }
290
+
291
+ // Only apply if there's an actual change
292
+ if (parsedHeight !== this.height || parsedMarginBottom !== this.marginBottom) {
293
+ this.height = parsedHeight;
294
+ this.marginBottom = parsedMarginBottom;
295
+ this.minimizedHeight = `${this.height * 0.3}px`;
296
+
297
+ console.log(`Height updated to: ${this.height}px, marginBottom: ${this.marginBottom}px`);
298
+
299
+ // Apply the updated height/marginBottom if not ContactForm
300
+ if (this.mode !== 'ContactForm') {
301
+ if (this.containerDiv.dataset.position === 'in-place') {
302
+ // "in-place" uses full width, sets containerDiv height
303
+ this.containerDiv.style.height = `${this.height}px`;
304
+ if (this.iframe) {
305
+ this.iframe.style.height = `${this.height}px`;
306
+ }
307
+ if (this.minimizedIframe) {
308
+ this.minimizedIframe.style.height = this.minimizedHeight;
309
+ }
310
+ } else {
311
+ // position: fixed (typical floating chat)
312
+ // Update bottom offset, main height
313
+ if (this.iframe) {
314
+ this.iframe.style.height = `${this.height}px`;
315
+ this.iframe.style.bottom = `${this.marginBottom}px`;
316
+ }
317
+ if (this.minimizedIframe) {
318
+ this.minimizedIframe.style.height = this.minimizedHeight;
319
+ this.minimizedIframe.style.bottom = `${this.marginBottom}px`;
320
+ }
321
+ }
322
+ } else {
323
+ // ContactForm mode
324
+ this.containerDiv.style.height = `${this.height}px`;
325
+ if (this.iframe) {
326
+ this.iframe.style.height = `${this.height}px`;
327
+ }
328
+ }
329
+ }
330
+ }
245
331
 
246
332
  showMaximized(animate = false) {
247
333
  const schedulePostMessage = () => {
@@ -269,12 +355,6 @@
269
355
 
270
356
  this.iframe.style.display = "block";
271
357
 
272
- if (this.isSafari() && !this.hasRefreshed) {
273
- const currentSrc = this.iframe.src;
274
- this.iframe.src = ''; // Temporarily clear the src
275
- this.iframe.src = currentSrc; // Reset to the original src to trigger a reload
276
- this.hasRefreshed = true; // Prevent endless loop
277
- }
278
358
 
279
359
  this.iframe.style.height = `${this.height}px`;
280
360
  this.iframe.style.opacity = '1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "embeddedaichatux",
3
- "version": "1.7.2",
3
+ "version": "1.8.0",
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": {