embeddedaichatux 1.0.3 → 1.0.5

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/EmbeddedChat.js CHANGED
@@ -7,44 +7,62 @@ class EmbeddedChat {
7
7
  this.containerDiv = containerDiv;
8
8
  this.chatId = chatId;
9
9
  this.options = options || {};
10
- this.avatarImage = this.options.avatarImage || '/img/avatar.jpg';
11
10
  this.isPreview = this.options.isPreview || false;
12
11
  this.previewParam = this.isPreview ? "?isPreview=true" : "";
13
- this.serverUrl = this.options.serverUrl || 'https://embedgpt.chat';
12
+ this.serverUrl = this.options.serverUrl || 'https://embedgpt.chat/';
14
13
  this.positionStyle = this.containerDiv.dataset.position === 'in-place' ? 'width:100%; height:600px' : 'position: fixed; right: 0; bottom: 0; width: 300px; height: 600px';
15
14
  this.init();
16
15
  }
17
16
 
18
17
  init() {
18
+ const cleanedServerUrl = this.serverUrl.endsWith('/') ? this.serverUrl.slice(0, -1) : this.serverUrl;
19
+ const baseIframeUrl = `${cleanedServerUrl}/ChatUX/${this.chatId}`;
20
+ const previewQueryString = this.isPreview ? "?isPreview=true" : "";
21
+ const minimizedQueryString = this.isPreview ? "&isMinimized=true" : "?isMinimized=true";
22
+
23
+ const minimizedPositionStyle = 'position: fixed; right: 0; bottom: 0; width: 300px; height: 70px;';
24
+
19
25
  const iframeHtml = `
20
- <iframe id="embedded-chat" style="${this.positionStyle}; display: none; border:none; overflow:hidden;" frameborder="0" sandbox="allow-same-origin allow-scripts allow-popups allow-forms" src="${this.serverUrl}/ChatUX/${this.chatId}${this.previewParam}"></iframe>
21
- <div id="embedded-chat-minimized" class="container" style="display: none;; color:#43636e;width:100%; position: fixed; right: 0; bottom: 0; width: 300px; height: 50px; padding-top: 10px;padding-left: 100px;">
22
- <img title="Chat" src="${this.avatarImage}" style="height:40px; border-radius: 50%;" />
23
- <button id="embedded-chat-now" class="btn btn-primary">Chat Now</button>
24
- </div>
26
+ <iframe id="embedded-chat" style="${this.positionStyle}; display: none; border:none; overflow:hidden;" frameborder="0" sandbox="allow-same-origin allow-scripts allow-popups allow-forms" src="${baseIframeUrl}${previewQueryString}"></iframe>
27
+ <iframe id="embedded-chat-minimized" style="${minimizedPositionStyle}; display: none; border:none; overflow:hidden;" frameborder="0" sandbox="allow-same-origin allow-scripts allow-popups allow-forms" src="${baseIframeUrl}${previewQueryString}${minimizedQueryString}"></iframe>
25
28
  `;
26
29
 
27
30
  this.containerDiv.innerHTML = iframeHtml;
28
31
  this.iframe = this.containerDiv.querySelector("#embedded-chat");
29
- this.minimizedDiv = this.containerDiv.querySelector("#embedded-chat-minimized");
30
- this.chatNowButton = this.containerDiv.querySelector("#embedded-chat-now");
31
-
32
- this.chatNowButton.addEventListener("click", () => {
33
- this.iframe.style.display = "block";
34
- this.minimizedDiv.style.display = "none";
35
- });
32
+ this.minimizedIframe = this.containerDiv.querySelector("#embedded-chat-minimized");
36
33
 
37
34
  window.addEventListener("message", (e) => {
38
- if (e.data === "minimize") {
39
- this.iframe.style.display = "none";
40
- this.minimizedDiv.style.display = "block";
41
- } else if (e.data === "show") {
42
- this.iframe.style.display = "block";
43
- this.minimizedDiv.style.display = "none";
35
+ // Check if the data is an object and has a message property
36
+ if (typeof e.data === "object" && e.data.message) {
37
+ if (e.data.message === "minimize") {
38
+ this.iframe.style.display = "none";
39
+ this.minimizedIframe.style.display = "block";
40
+ } else if (e.data.message === "show" || e.data.message === "maximize") {
41
+ this.iframe.style.display = "block";
42
+ this.minimizedIframe.style.display = "none";
43
+ // Check if the data has a scale property
44
+ if (e.data.scale) {
45
+ // Resize the iframe according to the scale factor
46
+ this.iframe.style.transform = `scale(${e.data.scale})`;
47
+ this.iframe.style.transformOrigin = "bottom right";
48
+ }
49
+ }
50
+ }
51
+ // For backward compatibility, handle the case when the data is a string
52
+ else if (typeof e.data === "string") {
53
+ if (e.data === "minimize") {
54
+ this.iframe.style.display = "none";
55
+ this.minimizedIframe.style.display = "block";
56
+ } else if (e.data === "show" || e.data === "maximize") {
57
+ this.iframe.style.display = "block";
58
+ this.minimizedIframe.style.display = "none";
59
+ }
44
60
  }
45
61
  });
46
62
  }
47
63
 
64
+
65
+
48
66
  createChatContainer() {
49
67
  const chatContainer = document.createElement('div');
50
68
  chatContainer.className = 'embedded-chat-container';
package/README.md CHANGED
@@ -4,4 +4,11 @@ A lightweight and customizable embedded chat UI component that seamlessly integr
4
4
 
5
5
  ## Installation
6
6
 
7
- npm install aichatembedded
7
+ To update
8
+ 1. Modify the version in package.json
9
+ 1. NPM login
10
+ 1. npm publish
11
+
12
+ NPM: https://www.npmjs.com/settings/aichatepicenter/packages
13
+
14
+
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "embeddedaichatux",
3
- "version": "1.0.2",
3
+ "version": "1.0.5",
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": {
@@ -1,7 +1,6 @@
1
1
  C:\Git\AIChat\AIChat.npm\bin\Debug\net7.0\appsettings.Development.json
2
2
  C:\Git\AIChat\AIChat.npm\bin\Debug\net7.0\appsettings.json
3
3
  C:\Git\AIChat\AIChat.npm\bin\Debug\net7.0\package.json
4
- C:\Git\AIChat\AIChat.npm\bin\Debug\net7.0\AIChat.npm.staticwebassets.runtime.json
5
4
  C:\Git\AIChat\AIChat.npm\bin\Debug\net7.0\AIChat.npm.exe
6
5
  C:\Git\AIChat\AIChat.npm\bin\Debug\net7.0\AIChat.npm.deps.json
7
6
  C:\Git\AIChat\AIChat.npm\bin\Debug\net7.0\AIChat.npm.runtimeconfig.json
@@ -1,19 +1,11 @@
1
1
  {
2
2
  "Version": 1,
3
- "Hash": "tgwDmMv0sNqFpS/YhU/JuTb1QFLHbsjUk/iZBXYCB2Y=",
3
+ "Hash": "XERhvELNAMUvgNoh15s4mBH/fub4TdCl8jFj3CODgig=",
4
4
  "Source": "AIChat.npm",
5
5
  "BasePath": "_content/AIChat.npm",
6
6
  "Mode": "Default",
7
7
  "ManifestType": "Build",
8
8
  "ReferencedProjectsConfiguration": [],
9
- "DiscoveryPatterns": [
10
- {
11
- "Name": "AIChat.npm\\wwwroot",
12
- "Source": "AIChat.npm",
13
- "ContentRoot": "C:\\Git\\AIChat\\AIChat.npm\\wwwroot\\",
14
- "BasePath": "_content/AIChat.npm",
15
- "Pattern": "**"
16
- }
17
- ],
9
+ "DiscoveryPatterns": [],
18
10
  "Assets": []
19
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "embeddedaichatux",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
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": {
@@ -1 +0,0 @@
1
- {"ContentRoots":["C:\\Git\\AIChat\\AIChat.npm\\wwwroot\\"],"Root":{"Children":null,"Asset":null,"Patterns":[{"ContentRootIndex":0,"Pattern":"**","Depth":0}]}}
@@ -1 +0,0 @@
1
- {"ContentRoots":["C:\\Git\\AIChat\\AIChat.npm\\wwwroot\\"],"Root":{"Children":null,"Asset":null,"Patterns":[{"ContentRootIndex":0,"Pattern":"**","Depth":0}]}}