nerdagent-chat-widget 1.0.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.
- package/README.md +257 -0
- package/dist/angular/index.d.ts +38 -0
- package/dist/angular/index.js +5 -0
- package/dist/angular/index.js.map +1 -0
- package/dist/angular/nerd-chat-widget.d.ts +11 -0
- package/dist/angular/nerd-chat-widget.js +289 -0
- package/dist/angular/nerd-chat-widget.js.map +1 -0
- package/dist/cjs/app-globals-V2Kpy_OQ.js +8 -0
- package/dist/cjs/app-globals-V2Kpy_OQ.js.map +1 -0
- package/dist/cjs/index-CURqjGGU.js +1471 -0
- package/dist/cjs/index-CURqjGGU.js.map +1 -0
- package/dist/cjs/index.cjs.js +235 -0
- package/dist/cjs/index.cjs.js.map +1 -0
- package/dist/cjs/loader.cjs.js +14 -0
- package/dist/cjs/loader.cjs.js.map +1 -0
- package/dist/cjs/nerd-chat-widget.cjs.entry.js +9 -0
- package/dist/cjs/nerd-chat-widget.entry.cjs.js.map +1 -0
- package/dist/cjs/nerdagent-chat-widget.cjs.js +26 -0
- package/dist/cjs/nerdagent-chat-widget.cjs.js.map +1 -0
- package/dist/collection/collection-manifest.json +12 -0
- package/dist/collection/components/chat-widget/chat-widget.js +808 -0
- package/dist/collection/components/chat-widget/chat-widget.js.map +1 -0
- package/dist/collection/components/chat-widget/chat-widget.scss +420 -0
- package/dist/collection/index.js +2 -0
- package/dist/collection/index.js.map +1 -0
- package/dist/collection/script.js +323 -0
- package/dist/components/index.d.ts +33 -0
- package/dist/components/index.js +1514 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/nerd-chat-widget.d.ts +11 -0
- package/dist/components/nerd-chat-widget.js +9 -0
- package/dist/components/nerd-chat-widget.js.map +1 -0
- package/dist/esm/app-globals-DQuL1Twl.js +6 -0
- package/dist/esm/app-globals-DQuL1Twl.js.map +1 -0
- package/dist/esm/index-Dlv_7oUh.js +1444 -0
- package/dist/esm/index-Dlv_7oUh.js.map +1 -0
- package/dist/esm/index.js +233 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/loader.js +12 -0
- package/dist/esm/loader.js.map +1 -0
- package/dist/esm/nerd-chat-widget.entry.js +3 -0
- package/dist/esm/nerd-chat-widget.entry.js.map +1 -0
- package/dist/esm/nerdagent-chat-widget.js +22 -0
- package/dist/esm/nerdagent-chat-widget.js.map +1 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.js +1 -0
- package/dist/nerdagent-chat-widget/index.esm.js +2 -0
- package/dist/nerdagent-chat-widget/index.esm.js.map +1 -0
- package/dist/nerdagent-chat-widget/loader.esm.js.map +1 -0
- package/dist/nerdagent-chat-widget/nerd-chat-widget.entry.esm.js.map +1 -0
- package/dist/nerdagent-chat-widget/nerdagent-chat-widget.esm.js +2 -0
- package/dist/nerdagent-chat-widget/nerdagent-chat-widget.esm.js.map +1 -0
- package/dist/nerdagent-chat-widget/p-395fe7e7.entry.js +2 -0
- package/dist/nerdagent-chat-widget/p-395fe7e7.entry.js.map +1 -0
- package/dist/nerdagent-chat-widget/p-DQuL1Twl.js +2 -0
- package/dist/nerdagent-chat-widget/p-DQuL1Twl.js.map +1 -0
- package/dist/nerdagent-chat-widget/p-Dlv_7oUh.js +3 -0
- package/dist/nerdagent-chat-widget/p-Dlv_7oUh.js.map +1 -0
- package/dist/react/index.d.ts +38 -0
- package/dist/react/index.js +5 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/nerd-chat-widget.d.ts +11 -0
- package/dist/react/nerd-chat-widget.js +289 -0
- package/dist/react/nerd-chat-widget.js.map +1 -0
- package/dist/types/components/chat-widget/chat-widget.d.ts +95 -0
- package/dist/types/components.d.ts +251 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/stencil-public-runtime.d.ts +1730 -0
- package/dist/vue/index.d.ts +38 -0
- package/dist/vue/index.js +5 -0
- package/dist/vue/index.js.map +1 -0
- package/dist/vue/nerd-chat-widget.d.ts +11 -0
- package/dist/vue/nerd-chat-widget.js +289 -0
- package/dist/vue/nerd-chat-widget.js.map +1 -0
- package/loader/cdn.js +1 -0
- package/loader/index.cjs.js +1 -0
- package/loader/index.d.ts +24 -0
- package/loader/index.es2017.js +1 -0
- package/loader/index.js +2 -0
- package/package.json +76 -0
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
let widget = null;
|
|
2
|
+
|
|
3
|
+
// Clean embed code generation
|
|
4
|
+
|
|
5
|
+
// Function to get current widget configuration
|
|
6
|
+
function getCurrentConfig() {
|
|
7
|
+
try {
|
|
8
|
+
// Check if required elements exist
|
|
9
|
+
const requiredElements = ['agentName', 'agentRole', 'primaryColor', 'accentColor', 'welcomeMessage', 'placeholderText', 'position', 'width', 'height'];
|
|
10
|
+
for (const id of requiredElements) {
|
|
11
|
+
if (!document.getElementById(id)) {
|
|
12
|
+
console.error('Required element not found:', id);
|
|
13
|
+
return getDefaultConfig();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
agentName: document.getElementById('agentName').value || 'Support Agent',
|
|
19
|
+
agentRole: document.getElementById('agentRole').value || 'Customer Support',
|
|
20
|
+
primaryColor: document.getElementById('primaryColor').value || '#2d3e50',
|
|
21
|
+
accentColor: document.getElementById('accentColor').value || '#4e8cff',
|
|
22
|
+
welcomeMessage: document.getElementById('welcomeMessage').value || 'Hi! How can I help?',
|
|
23
|
+
placeholderText: document.getElementById('placeholderText').value || 'Type your message...',
|
|
24
|
+
position: document.getElementById('position').value || 'bottom-right',
|
|
25
|
+
width: parseInt(document.getElementById('width').value) || 350,
|
|
26
|
+
height: parseInt(document.getElementById('height').value) || 500,
|
|
27
|
+
showMinimizeButton: document.getElementById('showMinimizeButton')?.checked || true,
|
|
28
|
+
showTimestamps: document.getElementById('showTimestamps')?.checked || true,
|
|
29
|
+
enableFileUpload: document.getElementById('enableFileUpload')?.checked || false,
|
|
30
|
+
enableSpeech: document.getElementById('enableSpeech')?.checked || false,
|
|
31
|
+
showPoweredBy: document.getElementById('showPoweredBy')?.checked || true
|
|
32
|
+
};
|
|
33
|
+
} catch (error) {
|
|
34
|
+
console.error('Error getting config:', error);
|
|
35
|
+
return getDefaultConfig();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Default configuration fallback
|
|
40
|
+
function getDefaultConfig() {
|
|
41
|
+
return {
|
|
42
|
+
agentName: 'Support Agent',
|
|
43
|
+
agentRole: 'Customer Support',
|
|
44
|
+
primaryColor: '#2d3e50',
|
|
45
|
+
accentColor: '#4e8cff',
|
|
46
|
+
welcomeMessage: 'Hi! How can I help?',
|
|
47
|
+
placeholderText: 'Type your message...',
|
|
48
|
+
position: 'bottom-right',
|
|
49
|
+
width: 350,
|
|
50
|
+
height: 500,
|
|
51
|
+
showMinimizeButton: true,
|
|
52
|
+
showTimestamps: true,
|
|
53
|
+
enableFileUpload: false,
|
|
54
|
+
enableSpeech: false,
|
|
55
|
+
showPoweredBy: true
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Framework-specific code templates with syntax highlighting
|
|
60
|
+
const codeTemplates = {
|
|
61
|
+
html: function(config) {
|
|
62
|
+
return '<span class="syntax-comment"><!-- Add this to your HTML --></span>\n<span class="syntax-tag"><nerd-chat-widget</span>\n <span class="syntax-attr-name">agent-name</span>=<span class="syntax-attr-value">"' + config.agentName + '"</span>\n <span class="syntax-attr-name">agent-role</span>=<span class="syntax-attr-value">"' + config.agentRole + '"</span>\n <span class="syntax-attr-name">primary-color</span>=<span class="syntax-attr-value">"' + config.primaryColor + '"</span>\n <span class="syntax-attr-name">accent-color</span>=<span class="syntax-attr-value">"' + config.accentColor + '"</span>\n <span class="syntax-attr-name">welcome-message</span>=<span class="syntax-attr-value">"' + config.welcomeMessage + '"</span>\n <span class="syntax-attr-name">placeholder-text</span>=<span class="syntax-attr-value">"' + config.placeholderText + '"</span>\n <span class="syntax-attr-name">position</span>=<span class="syntax-attr-value">"' + config.position + '"</span>\n <span class="syntax-attr-name">width</span>=<span class="syntax-attr-value">"' + config.width + '"</span>\n <span class="syntax-attr-name">height</span>=<span class="syntax-attr-value">"' + config.height + '"</span>\n <span class="syntax-attr-name">show-minimize-button</span>=<span class="syntax-attr-value">"' + config.showMinimizeButton + '"</span>\n <span class="syntax-attr-name">show-timestamps</span>=<span class="syntax-attr-value">"' + config.showTimestamps + '"</span>\n <span class="syntax-attr-name">enable-file-upload</span>=<span class="syntax-attr-value">"' + config.enableFileUpload + '"</span>\n <span class="syntax-attr-name">enable-speech</span>=<span class="syntax-attr-value">"' + config.enableSpeech + '"</span>\n <span class="syntax-attr-name">show-powered-by</span>=<span class="syntax-attr-value">"' + config.showPoweredBy + '"</span><span class="syntax-tag">></span>\n<span class="syntax-tag"></nerd-chat-widget></span>\n\n<span class="syntax-comment"><!-- Add this script --></span>\n<span class="syntax-tag"><script</span> <span class="syntax-attr-name">src</span>=<span class="syntax-attr-value">"https://cdn.nerdagent.ai/widget.js"</span><span class="syntax-tag">></script></span>';
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
react: function(config) {
|
|
66
|
+
return '<span class="syntax-comment">// Install: npm install @nerdagent/chat-widget-react</span>\n<span class="syntax-keyword">import</span> React <span class="syntax-keyword">from</span> <span class="syntax-string">\'react\'</span>;\n<span class="syntax-keyword">import</span> { NerdChatWidget } <span class="syntax-keyword">from</span> <span class="syntax-string">\'@nerdagent/chat-widget-react\'</span>;\n\n<span class="syntax-keyword">function</span> <span class="syntax-tag">App</span>() {\n <span class="syntax-keyword">return</span> (\n <span class="syntax-tag"><div</span> <span class="syntax-attr-name">className</span>=<span class="syntax-attr-value">"App"</span><span class="syntax-tag">></span>\n <span class="syntax-tag"><NerdChatWidget</span>\n <span class="syntax-attr-name">agentName</span>=<span class="syntax-attr-value">"' + config.agentName + '"</span>\n <span class="syntax-attr-name">agentRole</span>=<span class="syntax-attr-value">"' + config.agentRole + '"</span>\n <span class="syntax-attr-name">primaryColor</span>=<span class="syntax-attr-value">"' + config.primaryColor + '"</span>\n <span class="syntax-attr-name">accentColor</span>=<span class="syntax-attr-value">"' + config.accentColor + '"</span>\n <span class="syntax-attr-name">welcomeMessage</span>=<span class="syntax-attr-value">"' + config.welcomeMessage + '"</span>\n <span class="syntax-attr-name">position</span>=<span class="syntax-attr-value">"' + config.position + '"</span>\n <span class="syntax-attr-name">width</span>={' + config.width + '}\n <span class="syntax-attr-name">height</span>={' + config.height + '}\n <span class="syntax-attr-name">showMinimizeButton</span>={' + config.showMinimizeButton + '}\n <span class="syntax-attr-name">showTimestamps</span>={' + config.showTimestamps + '}\n <span class="syntax-tag">/></span>\n <span class="syntax-tag"></div></span>\n );\n}\n\n<span class="syntax-keyword">export default</span> App;';
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
angular: function(config) {
|
|
70
|
+
return '<span class="syntax-comment">// Install: npm install @nerdagent/chat-widget-angular</span>\n<span class="syntax-comment">// In your app.module.ts:</span>\n<span class="syntax-keyword">import</span> { NerdChatWidgetModule } <span class="syntax-keyword">from</span> <span class="syntax-string">\'@nerdagent/chat-widget-angular\'</span>;\n\n@<span class="syntax-tag">NgModule</span>({\n <span class="syntax-attr-name">imports</span>: [\n BrowserModule,\n NerdChatWidgetModule\n ]\n})\n\n<span class="syntax-comment"><!-- In your component template: --></span>\n<span class="syntax-tag"><nerd-chat-widget</span>\n <span class="syntax-attr-name">[agentName]</span>=<span class="syntax-attr-value">"\'' + config.agentName + '\'"</span>\n <span class="syntax-attr-name">[agentRole]</span>=<span class="syntax-attr-value">"\'' + config.agentRole + '\'"</span>\n <span class="syntax-attr-name">[primaryColor]</span>=<span class="syntax-attr-value">"\'' + config.primaryColor + '\'"</span>\n <span class="syntax-attr-name">[position]</span>=<span class="syntax-attr-value">"\'' + config.position + '\'"</span>\n <span class="syntax-attr-name">[width]</span>=<span class="syntax-attr-value">"' + config.width + '"</span>\n <span class="syntax-attr-name">[height]</span>=<span class="syntax-attr-value">"' + config.height + '"</span><span class="syntax-tag">></span>\n<span class="syntax-tag"></nerd-chat-widget></span>';
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
vue: function(config) {
|
|
74
|
+
return '<span class="syntax-comment">// Install: npm install @nerdagent/chat-widget-vue</span>\n<span class="syntax-comment">// In your main.js:</span>\n<span class="syntax-keyword">import</span> { createApp } <span class="syntax-keyword">from</span> <span class="syntax-string">\'vue\'</span>;\n<span class="syntax-keyword">import</span> { NerdChatWidget } <span class="syntax-keyword">from</span> <span class="syntax-string">\'@nerdagent/chat-widget-vue\'</span>;\n\n<span class="syntax-keyword">const</span> app = <span class="syntax-tag">createApp</span>(App);\napp.<span class="syntax-tag">component</span>(<span class="syntax-string">\'nerd-chat-widget\'</span>, NerdChatWidget);\n\n<span class="syntax-comment"><!-- In your component template: --></span>\n<span class="syntax-tag"><template></span>\n <span class="syntax-tag"><nerd-chat-widget</span>\n <span class="syntax-attr-name">:agent-name</span>=<span class="syntax-attr-value">"\'' + config.agentName + '\'"</span>\n <span class="syntax-attr-name">:agent-role</span>=<span class="syntax-attr-value">"\'' + config.agentRole + '\'"</span>\n <span class="syntax-attr-name">:primary-color</span>=<span class="syntax-attr-value">"\'' + config.primaryColor + '\'"</span>\n <span class="syntax-attr-name">:position</span>=<span class="syntax-attr-value">"\'' + config.position + '\'"</span>\n <span class="syntax-attr-name">:width</span>=<span class="syntax-attr-value">"' + config.width + '"</span>\n <span class="syntax-attr-name">:height</span>=<span class="syntax-attr-value">"' + config.height + '"</span>\n <span class="syntax-tag">/></span>\n<span class="syntax-tag"></template></span>';
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// Function to update code display with framework-specific examples
|
|
79
|
+
function updateCodeDisplay() {
|
|
80
|
+
console.log('=== updateCodeDisplay called ===');
|
|
81
|
+
|
|
82
|
+
try {
|
|
83
|
+
const activeTab = document.querySelector('.tab-btn.active');
|
|
84
|
+
console.log('Active tab:', activeTab);
|
|
85
|
+
|
|
86
|
+
const selectedFramework = activeTab ? activeTab.getAttribute('data-framework') : 'html';
|
|
87
|
+
console.log('Selected framework:', selectedFramework);
|
|
88
|
+
|
|
89
|
+
const codeContent = document.getElementById('codeContent');
|
|
90
|
+
console.log('Code content element:', codeContent);
|
|
91
|
+
|
|
92
|
+
if (!codeContent) {
|
|
93
|
+
console.error('Code content element not found');
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Get current configuration
|
|
98
|
+
const config = getCurrentConfig();
|
|
99
|
+
console.log('Current config keys:', Object.keys(config));
|
|
100
|
+
|
|
101
|
+
// Update framework label first
|
|
102
|
+
const frameworkLabel = document.getElementById('frameworkLabel');
|
|
103
|
+
if (frameworkLabel) {
|
|
104
|
+
const labels = {
|
|
105
|
+
'html': 'HTML',
|
|
106
|
+
'react': 'ReactJS',
|
|
107
|
+
'angular': 'Angular',
|
|
108
|
+
'vue': 'VueJS'
|
|
109
|
+
};
|
|
110
|
+
frameworkLabel.textContent = labels[selectedFramework] || 'HTML';
|
|
111
|
+
console.log('Updated framework label to:', labels[selectedFramework]);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Check if template exists
|
|
115
|
+
console.log('Available templates:', Object.keys(codeTemplates));
|
|
116
|
+
const codeTemplate = codeTemplates[selectedFramework];
|
|
117
|
+
console.log('Template found:', !!codeTemplate);
|
|
118
|
+
|
|
119
|
+
if (codeTemplate) {
|
|
120
|
+
const generatedCode = codeTemplate(config);
|
|
121
|
+
console.log('Generated code length:', generatedCode.length);
|
|
122
|
+
console.log('First 100 chars:', generatedCode.substring(0, 100));
|
|
123
|
+
codeContent.innerHTML = generatedCode;
|
|
124
|
+
console.log('Code updated successfully');
|
|
125
|
+
} else {
|
|
126
|
+
console.error('No template found for framework:', selectedFramework);
|
|
127
|
+
codeContent.innerHTML = '<span style="color: red;">Error: Template not found for ' + selectedFramework + '</span>';
|
|
128
|
+
}
|
|
129
|
+
} catch (error) {
|
|
130
|
+
console.error('Error in updateCodeDisplay:', error);
|
|
131
|
+
console.error('Error stack:', error.stack);
|
|
132
|
+
const codeContent = document.getElementById('codeContent');
|
|
133
|
+
if (codeContent) {
|
|
134
|
+
codeContent.innerHTML = '<span style="color: red;">Error loading code example: ' + error.message + '</span>';
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
console.log('=== updateCodeDisplay finished ===');
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Function to get clean code without HTML syntax highlighting
|
|
142
|
+
function getCleanCode(framework, config) {
|
|
143
|
+
if (framework === 'html') {
|
|
144
|
+
return '<!-- Add this to your HTML -->' + '\n' +
|
|
145
|
+
'<nerd-chat-widget' + '\n' +
|
|
146
|
+
' agent-name="' + config.agentName + '"' + '\n' +
|
|
147
|
+
' agent-role="' + config.agentRole + '"' + '\n' +
|
|
148
|
+
' primary-color="' + config.primaryColor + '"' + '\n' +
|
|
149
|
+
' position="' + config.position + '"' + '\n' +
|
|
150
|
+
' width="' + config.width + '"' + '\n' +
|
|
151
|
+
' height="' + config.height + '">' + '\n' +
|
|
152
|
+
'</nerd-chat-widget>' + '\n' + '\n' +
|
|
153
|
+
'<!-- Add this script -->' + '\n' +
|
|
154
|
+
'<script src="https://cdn.nerdagent.ai/widget.js"><\/script>';
|
|
155
|
+
} else if (framework === 'react') {
|
|
156
|
+
return '// Install: npm install @nerdagent/chat-widget-react' + '\n' +
|
|
157
|
+
'import React from \'react\';' + '\n' +
|
|
158
|
+
'import { NerdChatWidget } from \'@nerdagent/chat-widget-react\';' + '\n' + '\n' +
|
|
159
|
+
'function App() {' + '\n' +
|
|
160
|
+
' return (' + '\n' +
|
|
161
|
+
' <div className="App">' + '\n' +
|
|
162
|
+
' <NerdChatWidget' + '\n' +
|
|
163
|
+
' agentName="' + config.agentName + '"' + '\n' +
|
|
164
|
+
' position="' + config.position + '"' + '\n' +
|
|
165
|
+
' width={' + config.width + '}' + '\n' +
|
|
166
|
+
' />' + '\n' +
|
|
167
|
+
' </div>' + '\n' +
|
|
168
|
+
' );' + '\n' +
|
|
169
|
+
'}' + '\n' + '\n' +
|
|
170
|
+
'export default App;';
|
|
171
|
+
} else if (framework === 'angular') {
|
|
172
|
+
return '// Install: npm install @nerdagent/chat-widget-angular' + '\n' +
|
|
173
|
+
'import { NerdChatWidgetModule } from \'@nerdagent/chat-widget-angular\';' + '\n' + '\n' +
|
|
174
|
+
'<!-- In your component template: -->' + '\n' +
|
|
175
|
+
'<nerd-chat-widget' + '\n' +
|
|
176
|
+
' [agentName]="' + config.agentName + '"' + '\n' +
|
|
177
|
+
' [position]="' + config.position + '"' + '\n' +
|
|
178
|
+
' [width]="' + config.width + '">' + '\n' +
|
|
179
|
+
'</nerd-chat-widget>';
|
|
180
|
+
} else if (framework === 'vue') {
|
|
181
|
+
return '// Install: npm install @nerdagent/chat-widget-vue' + '\n' +
|
|
182
|
+
'import { NerdChatWidget } from \'@nerdagent/chat-widget-vue\';' + '\n' + '\n' +
|
|
183
|
+
'<template>' + '\n' +
|
|
184
|
+
' <nerd-chat-widget' + '\n' +
|
|
185
|
+
' :agent-name="' + config.agentName + '"' + '\n' +
|
|
186
|
+
' :position="' + config.position + '"' + '\n' +
|
|
187
|
+
' :width="' + config.width + '"' + '\n' +
|
|
188
|
+
' />' + '\n' +
|
|
189
|
+
'</template>';
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return getCleanCode('html', config);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Enhanced copy function with better feedback
|
|
196
|
+
function copyCode() {
|
|
197
|
+
const activeTab = document.querySelector('.tab-btn.active');
|
|
198
|
+
const selectedFramework = activeTab ? activeTab.getAttribute('data-framework') : 'html';
|
|
199
|
+
const config = getCurrentConfig();
|
|
200
|
+
const cleanCode = getCleanCode(selectedFramework, config);
|
|
201
|
+
|
|
202
|
+
navigator.clipboard.writeText(cleanCode).then(() => {
|
|
203
|
+
const copyBtn = document.querySelector('.copy-btn');
|
|
204
|
+
const originalText = copyBtn.textContent;
|
|
205
|
+
const originalBg = copyBtn.style.background;
|
|
206
|
+
|
|
207
|
+
// Enhanced feedback
|
|
208
|
+
copyBtn.innerHTML = '✓ Copied!';
|
|
209
|
+
copyBtn.style.background = '#28a745';
|
|
210
|
+
copyBtn.style.transform = 'scale(0.95)';
|
|
211
|
+
|
|
212
|
+
setTimeout(() => {
|
|
213
|
+
copyBtn.textContent = originalText;
|
|
214
|
+
copyBtn.style.background = originalBg || '#4e8cff';
|
|
215
|
+
copyBtn.style.transform = 'scale(1)';
|
|
216
|
+
}, 2000);
|
|
217
|
+
}).catch(err => {
|
|
218
|
+
console.error('Failed to copy code:', err);
|
|
219
|
+
const copyBtn = document.querySelector('.copy-btn');
|
|
220
|
+
copyBtn.innerHTML = '✗ Failed';
|
|
221
|
+
copyBtn.style.background = '#dc3545';
|
|
222
|
+
|
|
223
|
+
setTimeout(() => {
|
|
224
|
+
copyBtn.textContent = 'Copy';
|
|
225
|
+
copyBtn.style.background = '#4e8cff';
|
|
226
|
+
}, 2000);
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Enhanced event listeners with dynamic code updates
|
|
231
|
+
document.addEventListener('DOMContentLoaded', function() {
|
|
232
|
+
console.log('DOM Content Loaded - setting up event listeners');
|
|
233
|
+
|
|
234
|
+
// Tab switching functionality with code updates
|
|
235
|
+
const tabButtons = document.querySelectorAll('.tab-btn');
|
|
236
|
+
console.log('Found tab buttons:', tabButtons.length);
|
|
237
|
+
tabButtons.forEach(button => {
|
|
238
|
+
button.addEventListener('click', function() {
|
|
239
|
+
console.log('Tab clicked:', this.getAttribute('data-framework'));
|
|
240
|
+
|
|
241
|
+
// Remove active class from all tabs
|
|
242
|
+
tabButtons.forEach(btn => btn.classList.remove('active'));
|
|
243
|
+
// Add active class to clicked tab
|
|
244
|
+
this.classList.add('active');
|
|
245
|
+
|
|
246
|
+
console.log('About to call updateCodeDisplay...');
|
|
247
|
+
// Update code display for new framework
|
|
248
|
+
updateCodeDisplay();
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
// Add event listeners to update both widget and code
|
|
253
|
+
const configInputs = document.querySelectorAll('#agentName, #agentRole, #primaryColor, #accentColor, #welcomeMessage, #placeholderText, #position, #width, #height, #showMinimizeButton, #showTimestamps, #enableFileUpload, #enableSpeech, #showPoweredBy');
|
|
254
|
+
configInputs.forEach(input => {
|
|
255
|
+
// Update widget only (code display is static for now)
|
|
256
|
+
input.addEventListener('input', function() {
|
|
257
|
+
updateWidget();
|
|
258
|
+
// updateCodeDisplay(); // Temporarily disabled
|
|
259
|
+
});
|
|
260
|
+
input.addEventListener('change', function() {
|
|
261
|
+
updateWidget();
|
|
262
|
+
// updateCodeDisplay(); // Temporarily disabled
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
// Initialize code display
|
|
267
|
+
setTimeout(() => {
|
|
268
|
+
console.log('Initializing code display...');
|
|
269
|
+
updateCodeDisplay();
|
|
270
|
+
}, 100);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
function updateWidget() {
|
|
274
|
+
if (widget) {
|
|
275
|
+
const config = getCurrentConfig();
|
|
276
|
+
|
|
277
|
+
// Update widget attributes using setAttribute for kebab-case
|
|
278
|
+
widget.setAttribute('agent-name', config.agentName);
|
|
279
|
+
widget.setAttribute('agent-role', config.agentRole);
|
|
280
|
+
widget.setAttribute('primary-color', config.primaryColor);
|
|
281
|
+
widget.setAttribute('accent-color', config.accentColor);
|
|
282
|
+
widget.setAttribute('welcome-message', config.welcomeMessage);
|
|
283
|
+
widget.setAttribute('placeholder-text', config.placeholderText);
|
|
284
|
+
widget.setAttribute('position', config.position);
|
|
285
|
+
widget.setAttribute('width', config.width.toString());
|
|
286
|
+
widget.setAttribute('height', config.height.toString());
|
|
287
|
+
widget.setAttribute('show-minimize-button', config.showMinimizeButton.toString());
|
|
288
|
+
widget.setAttribute('show-timestamps', config.showTimestamps.toString());
|
|
289
|
+
widget.setAttribute('enable-file-upload', config.enableFileUpload.toString());
|
|
290
|
+
widget.setAttribute('enable-speech', config.enableSpeech.toString());
|
|
291
|
+
widget.setAttribute('show-powered-by', config.showPoweredBy.toString());
|
|
292
|
+
|
|
293
|
+
console.log('Widget updated:', config.agentName);
|
|
294
|
+
} else {
|
|
295
|
+
console.log('Widget not ready yet, please wait...');
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// Wait for component to be defined
|
|
300
|
+
customElements.whenDefined('nerd-chat-widget').then(() => {
|
|
301
|
+
console.log('Chat widget component loaded!');
|
|
302
|
+
widget = document.getElementById('chatWidget');
|
|
303
|
+
|
|
304
|
+
// Initialize widget
|
|
305
|
+
updateWidget();
|
|
306
|
+
|
|
307
|
+
// Listen to widget events
|
|
308
|
+
widget.addEventListener('messageSent', (e) => {
|
|
309
|
+
console.log('Message sent:', e.detail.message);
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
widget.addEventListener('widgetOpened', (e) => {
|
|
313
|
+
console.log('Widget opened');
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
widget.addEventListener('widgetClosed', (e) => {
|
|
317
|
+
console.log('Widget closed');
|
|
318
|
+
});
|
|
319
|
+
}).catch(err => {
|
|
320
|
+
console.error('Failed to load chat widget:', err);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
// Widget should load successfully now
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the base path to where the assets can be found. Use "setAssetPath(path)"
|
|
3
|
+
* if the path needs to be customized.
|
|
4
|
+
*/
|
|
5
|
+
export declare const getAssetPath: (path: string) => string;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Used to manually set the base path where assets can be found.
|
|
9
|
+
* If the script is used as "module", it's recommended to use "import.meta.url",
|
|
10
|
+
* such as "setAssetPath(import.meta.url)". Other options include
|
|
11
|
+
* "setAssetPath(document.currentScript.src)", or using a bundler's replace plugin to
|
|
12
|
+
* dynamically set the path at build time, such as "setAssetPath(process.env.ASSET_PATH)".
|
|
13
|
+
* But do note that this configuration depends on how your script is bundled, or lack of
|
|
14
|
+
* bundling, and where your assets can be loaded from. Additionally custom bundling
|
|
15
|
+
* will have to ensure the static assets are copied to its build directory.
|
|
16
|
+
*/
|
|
17
|
+
export declare const setAssetPath: (path: string) => void;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Used to specify a nonce value that corresponds with an application's CSP.
|
|
21
|
+
* When set, the nonce will be added to all dynamically created script and style tags at runtime.
|
|
22
|
+
* Alternatively, the nonce value can be set on a meta tag in the DOM head
|
|
23
|
+
* (<meta name="csp-nonce" content="{ nonce value here }" />) which
|
|
24
|
+
* will result in the same behavior.
|
|
25
|
+
*/
|
|
26
|
+
export declare const setNonce: (nonce: string) => void
|
|
27
|
+
|
|
28
|
+
export interface SetPlatformOptions {
|
|
29
|
+
raf?: (c: FrameRequestCallback) => number;
|
|
30
|
+
ael?: (el: EventTarget, eventName: string, listener: EventListenerOrEventListenerObject, options: boolean | AddEventListenerOptions) => void;
|
|
31
|
+
rel?: (el: EventTarget, eventName: string, listener: EventListenerOrEventListenerObject, options: boolean | AddEventListenerOptions) => void;
|
|
32
|
+
}
|
|
33
|
+
export declare const setPlatformOptions: (opts: SetPlatformOptions) => void;
|