embeddedaichatux 1.0.6 → 1.0.8

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/AIChat.npm.csproj CHANGED
@@ -14,5 +14,16 @@
14
14
  <Copy SourceFiles="@(_CommonWebJsFiles)" DestinationFolder="$(MSBuildProjectDirectory)" SkipUnchangedFiles="true" />
15
15
  </Target>
16
16
 
17
+ <ItemGroup>
18
+ <None Remove="EmbeddedChat.js" />
19
+ </ItemGroup>
20
+
21
+ <ItemGroup>
22
+ <Content Include="EmbeddedChat.js">
23
+ <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
24
+ <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
25
+ </Content>
26
+ </ItemGroup>
27
+
17
28
 
18
29
  </Project>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
+ <PropertyGroup>
4
+ <ActiveDebugProfile>https</ActiveDebugProfile>
5
+ </PropertyGroup>
6
+ </Project>
package/AIChat.npm.sln ADDED
@@ -0,0 +1,25 @@
1
+ 
2
+ Microsoft Visual Studio Solution File, Format Version 12.00
3
+ # Visual Studio Version 17
4
+ VisualStudioVersion = 17.7.34024.191
5
+ MinimumVisualStudioVersion = 10.0.40219.1
6
+ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AIChat.npm", "AIChat.npm.csproj", "{37DB7D9F-39C4-428D-A205-7E78FAB8BB25}"
7
+ EndProject
8
+ Global
9
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
10
+ Debug|Any CPU = Debug|Any CPU
11
+ Release|Any CPU = Release|Any CPU
12
+ EndGlobalSection
13
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
14
+ {37DB7D9F-39C4-428D-A205-7E78FAB8BB25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15
+ {37DB7D9F-39C4-428D-A205-7E78FAB8BB25}.Debug|Any CPU.Build.0 = Debug|Any CPU
16
+ {37DB7D9F-39C4-428D-A205-7E78FAB8BB25}.Release|Any CPU.ActiveCfg = Release|Any CPU
17
+ {37DB7D9F-39C4-428D-A205-7E78FAB8BB25}.Release|Any CPU.Build.0 = Release|Any CPU
18
+ EndGlobalSection
19
+ GlobalSection(SolutionProperties) = preSolution
20
+ HideSolutionNode = FALSE
21
+ EndGlobalSection
22
+ GlobalSection(ExtensibilityGlobals) = postSolution
23
+ SolutionGuid = {33D9F6CE-532F-4C22-AAAD-2D8B3BB56596}
24
+ EndGlobalSection
25
+ EndGlobal
package/EmbeddedChat.js CHANGED
@@ -10,22 +10,25 @@ class EmbeddedChat {
10
10
  this.isPreview = this.options.isPreview || false;
11
11
  this.previewParam = this.isPreview ? "?isPreview=true" : "";
12
12
  this.serverUrl = this.options.serverUrl || 'https://embedgpt.chat/';
13
- this.positionStyle = this.containerDiv.dataset.position === 'in-place' ? 'width:100%; height:600px' : 'position: fixed; right: 0; bottom: 0; width: 300px; height: 600px';
13
+ this.positionStyle = this.containerDiv.dataset.position === 'in-place' ? 'width:100%; height:600px' : 'position: fixed; right: 0; bottom: 0; width: 300px; height: 600px; z-index: 100000';
14
+ this.mode = options.mode || 'Chat'; // default to 'chat' if mode isn't provided
15
+ if (this.mode === 'ContactForm') {
16
+ // Adjust position style for contact form if mode is 'ContactForm'
17
+ this.positionStyle = 'width:100%; height:600px';
18
+ this.containerDiv.style.height = '600px';
19
+ }
14
20
  this.init();
15
21
  }
16
22
 
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;';
23
+ init() {
24
+ const cleanedServerUrl = this.serverUrl.endsWith('/') ? this.serverUrl.slice(0, -1) : this.serverUrl;
25
+ const baseIframeUrl = `${cleanedServerUrl}/ChatUX/${this.chatId}`;
26
+ const minimizedPositionStyle = 'position: fixed; right: 0; bottom: 0; width: 300px; height: 70px; z-index: 100000';
24
27
 
25
- const iframeHtml = `
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>
28
- `;
28
+ const iframeHtml = `
29
+ <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.buildIframeUrl(baseIframeUrl, { isPreview: this.isPreview, mode: this.mode })}"></iframe>
30
+ <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="${this.buildIframeUrl(baseIframeUrl, { isPreview: this.isPreview, isMinimized: true })}"></iframe>
31
+ `;
29
32
 
30
33
  this.containerDiv.innerHTML = iframeHtml;
31
34
  this.iframe = this.containerDiv.querySelector("#embedded-chat");
@@ -35,16 +38,23 @@ class EmbeddedChat {
35
38
  // Check if the data is an object and has a message property
36
39
  if (typeof e.data === "object" && e.data.message && (!e.data.chatId || e.data.chatId === this.chatId)) {
37
40
  if (e.data.message === "minimize") {
38
- this.iframe.style.display = "none";
39
- this.minimizedIframe.style.display = "block";
41
+ if (this.mode !== 'ContactForm') {
42
+ // No minimize support for ContactForm
43
+ this.iframe.style.display = "none";
44
+ this.minimizedIframe.style.display = "block";
45
+ }
40
46
  } else if (e.data.message === "show" || e.data.message === "maximize") {
41
47
  this.iframe.style.display = "block";
42
48
  this.minimizedIframe.style.display = "none";
43
49
  // Check if the data has a scale property
44
50
  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";
51
+ if (this.mode !== 'ContactForm') {
52
+ // No scaling support for ContactForm
53
+
54
+ // Resize the iframe according to the scale factor
55
+ this.iframe.style.transform = `scale(${e.data.scale})`;
56
+ this.iframe.style.transformOrigin = "bottom right";
57
+ }
48
58
  }
49
59
  }
50
60
  }
@@ -70,8 +80,35 @@ class EmbeddedChat {
70
80
  document.body.appendChild(chatContainer);
71
81
  return chatContainer;
72
82
  }
83
+
84
+ buildIframeUrl(baseIframeUrl, params = {}) {
85
+ const urlParams = new URLSearchParams(params);
86
+
87
+ // Add parameters as needed, based on values in the params object
88
+ if (params.isPreview) {
89
+ urlParams.set('isPreview', 'true');
90
+ }
91
+
92
+ if (params.mode === 'ContactForm') {
93
+ urlParams.set('mode', 'ContactForm');
94
+ }
95
+
96
+ // Handle other parameters directly from the params object
97
+ for (const [key, value] of Object.entries(params)) {
98
+ if (key !== 'mode' && key !== 'isPreview') { // Avoid duplicates
99
+ urlParams.set(key, value);
100
+ }
101
+ }
102
+
103
+ return `${baseIframeUrl}?${urlParams.toString()}`;
104
+ }
73
105
  }
74
106
 
75
107
  export function initEmbeddedChat(containerDiv, chatId, options) {
76
108
  return new EmbeddedChat(containerDiv, chatId, options);
77
109
  }
110
+
111
+ export function initContactForm(containerDiv, chatId, options) {
112
+ const clonedOptions = { ...options, mode: 'ContactForm' }; // Clone with spread syntax
113
+ return new EmbeddedChat(containerDiv, chatId, clonedOptions);
114
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "embeddedaichatux",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
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": {