nerdagent-chat-widget-angular 1.0.2
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 +121 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/lib/chat-widget.component.d.ts +30 -0
- package/dist/lib/chat-widget.component.js +163 -0
- package/dist/lib/chat-widget.module.d.ts +2 -0
- package/dist/lib/chat-widget.module.js +30 -0
- package/dist/lib/chat-widget.types.d.ts +25 -0
- package/dist/lib/chat-widget.types.js +1 -0
- package/package.json +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# @nerdagent/chat-widget-angular
|
|
2
|
+
|
|
3
|
+
Angular wrapper for the NerdAgent Chat Widget built with Stencil.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @nerdagent/chat-widget-angular
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### 1. Import the Module
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { NgModule } from '@angular/core';
|
|
17
|
+
import { BrowserModule } from '@angular/platform-browser';
|
|
18
|
+
import { NerdChatWidgetModule } from '@nerdagent/chat-widget-angular';
|
|
19
|
+
|
|
20
|
+
import { AppComponent } from './app.component';
|
|
21
|
+
|
|
22
|
+
@NgModule({
|
|
23
|
+
declarations: [
|
|
24
|
+
AppComponent
|
|
25
|
+
],
|
|
26
|
+
imports: [
|
|
27
|
+
BrowserModule,
|
|
28
|
+
NerdChatWidgetModule
|
|
29
|
+
],
|
|
30
|
+
providers: [],
|
|
31
|
+
bootstrap: [AppComponent]
|
|
32
|
+
})
|
|
33
|
+
export class AppModule { }
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### 2. Use in Component Template
|
|
37
|
+
|
|
38
|
+
```html
|
|
39
|
+
<nerd-chat-widget
|
|
40
|
+
agentName="Support Agent"
|
|
41
|
+
agentRole="Customer Support"
|
|
42
|
+
primaryColor="#2d3e50"
|
|
43
|
+
accentColor="#4e8cff"
|
|
44
|
+
welcomeMessage="Hi! How can I help?"
|
|
45
|
+
position="bottom-right"
|
|
46
|
+
[width]="350"
|
|
47
|
+
[height]="500"
|
|
48
|
+
[showMinimizeButton]="true"
|
|
49
|
+
[showTimestamps]="true"
|
|
50
|
+
[enableFileUpload]="false"
|
|
51
|
+
[enableSpeech]="false"
|
|
52
|
+
[showPoweredBy]="true"
|
|
53
|
+
(messageSent)="onMessageSent($event)"
|
|
54
|
+
(widgetOpened)="onWidgetOpened()"
|
|
55
|
+
(widgetClosed)="onWidgetClosed()">
|
|
56
|
+
</nerd-chat-widget>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### 3. Handle Events in Component
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import { Component } from '@angular/core';
|
|
63
|
+
|
|
64
|
+
@Component({
|
|
65
|
+
selector: 'app-root',
|
|
66
|
+
templateUrl: './app.component.html'
|
|
67
|
+
})
|
|
68
|
+
export class AppComponent {
|
|
69
|
+
|
|
70
|
+
onMessageSent(event: { message: string; timestamp: Date }) {
|
|
71
|
+
console.log('Message sent:', event);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
onWidgetOpened() {
|
|
75
|
+
console.log('Widget opened');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
onWidgetClosed() {
|
|
79
|
+
console.log('Widget closed');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## API
|
|
85
|
+
|
|
86
|
+
### Properties
|
|
87
|
+
|
|
88
|
+
| Property | Type | Default | Description |
|
|
89
|
+
|----------|------|---------|-------------|
|
|
90
|
+
| `agentName` | `string` | `'Support Agent'` | Name of the chat agent |
|
|
91
|
+
| `agentRole` | `string` | `'Customer Support'` | Role/title of the agent |
|
|
92
|
+
| `primaryColor` | `string` | `'#2d3e50'` | Primary theme color |
|
|
93
|
+
| `accentColor` | `string` | `'#4e8cff'` | Accent color for buttons |
|
|
94
|
+
| `welcomeMessage` | `string` | `'Hi! How can I help?'` | Initial message from agent |
|
|
95
|
+
| `placeholderText` | `string` | `'Type your message...'` | Input placeholder text |
|
|
96
|
+
| `position` | `WidgetPosition` | `'bottom-right'` | Widget position |
|
|
97
|
+
| `width` | `string` | `'350'` | Widget width in pixels |
|
|
98
|
+
| `height` | `string` | `'500'` | Widget height in pixels |
|
|
99
|
+
| `showMinimizeButton` | `boolean` | `true` | Show/hide minimize button |
|
|
100
|
+
| `showTimestamps` | `boolean` | `true` | Show/hide message timestamps |
|
|
101
|
+
| `enableFileUpload` | `boolean` | `false` | Enable file upload feature |
|
|
102
|
+
| `enableSpeech` | `boolean` | `false` | Enable speech input |
|
|
103
|
+
| `showPoweredBy` | `boolean` | `true` | Show/hide "Powered by" footer |
|
|
104
|
+
|
|
105
|
+
### Events
|
|
106
|
+
|
|
107
|
+
| Event | Type | Description |
|
|
108
|
+
|-------|------|-------------|
|
|
109
|
+
| `messageSent` | `{ message: string; timestamp: Date }` | Emitted when a message is sent |
|
|
110
|
+
| `widgetOpened` | `void` | Emitted when the widget is opened |
|
|
111
|
+
| `widgetClosed` | `void` | Emitted when the widget is closed |
|
|
112
|
+
|
|
113
|
+
### Types
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
type WidgetPosition = 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## License
|
|
120
|
+
|
|
121
|
+
MIT
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { EventEmitter, ElementRef, AfterViewInit, OnDestroy } from '@angular/core';
|
|
2
|
+
import { WidgetPosition } from './chat-widget.types';
|
|
3
|
+
export declare class ChatWidgetComponent implements AfterViewInit, OnDestroy {
|
|
4
|
+
chatWidget: ElementRef<HTMLElement>;
|
|
5
|
+
agentName: string;
|
|
6
|
+
agentRole: string;
|
|
7
|
+
primaryColor: string;
|
|
8
|
+
accentColor: string;
|
|
9
|
+
welcomeMessage: string;
|
|
10
|
+
placeholderText: string;
|
|
11
|
+
position: WidgetPosition;
|
|
12
|
+
width: string;
|
|
13
|
+
height: string;
|
|
14
|
+
showMinimizeButton: boolean;
|
|
15
|
+
showTimestamps: boolean;
|
|
16
|
+
enableFileUpload: boolean;
|
|
17
|
+
enableSpeech: boolean;
|
|
18
|
+
showPoweredBy: boolean;
|
|
19
|
+
messageSent: EventEmitter<{
|
|
20
|
+
message: string;
|
|
21
|
+
timestamp: Date;
|
|
22
|
+
}>;
|
|
23
|
+
widgetOpened: EventEmitter<void>;
|
|
24
|
+
widgetClosed: EventEmitter<void>;
|
|
25
|
+
private eventListeners;
|
|
26
|
+
ngAfterViewInit(): void;
|
|
27
|
+
ngOnDestroy(): void;
|
|
28
|
+
private setupEventListeners;
|
|
29
|
+
private removeEventListeners;
|
|
30
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { Component, Input, Output, EventEmitter, ElementRef, ViewChild } from '@angular/core';
|
|
11
|
+
let ChatWidgetComponent = class ChatWidgetComponent {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.agentName = 'Support Agent';
|
|
14
|
+
this.agentRole = 'Customer Support';
|
|
15
|
+
this.primaryColor = '#2d3e50';
|
|
16
|
+
this.accentColor = '#4e8cff';
|
|
17
|
+
this.welcomeMessage = 'Hi! How can I help?';
|
|
18
|
+
this.placeholderText = 'Type your message...';
|
|
19
|
+
this.position = 'bottom-right';
|
|
20
|
+
this.width = '350';
|
|
21
|
+
this.height = '500';
|
|
22
|
+
this.showMinimizeButton = true;
|
|
23
|
+
this.showTimestamps = true;
|
|
24
|
+
this.enableFileUpload = false;
|
|
25
|
+
this.enableSpeech = false;
|
|
26
|
+
this.showPoweredBy = true;
|
|
27
|
+
this.messageSent = new EventEmitter();
|
|
28
|
+
this.widgetOpened = new EventEmitter();
|
|
29
|
+
this.widgetClosed = new EventEmitter();
|
|
30
|
+
this.eventListeners = [];
|
|
31
|
+
}
|
|
32
|
+
ngAfterViewInit() {
|
|
33
|
+
if (this.chatWidget?.nativeElement) {
|
|
34
|
+
this.setupEventListeners();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
ngOnDestroy() {
|
|
38
|
+
this.removeEventListeners();
|
|
39
|
+
}
|
|
40
|
+
setupEventListeners() {
|
|
41
|
+
const widget = this.chatWidget.nativeElement;
|
|
42
|
+
const messageSentListener = (event) => {
|
|
43
|
+
this.messageSent.emit(event.detail);
|
|
44
|
+
};
|
|
45
|
+
const widgetOpenedListener = (event) => {
|
|
46
|
+
this.widgetOpened.emit();
|
|
47
|
+
};
|
|
48
|
+
const widgetClosedListener = (event) => {
|
|
49
|
+
this.widgetClosed.emit();
|
|
50
|
+
};
|
|
51
|
+
widget.addEventListener('messageSent', messageSentListener);
|
|
52
|
+
widget.addEventListener('widgetOpened', widgetOpenedListener);
|
|
53
|
+
widget.addEventListener('widgetClosed', widgetClosedListener);
|
|
54
|
+
// Store cleanup functions
|
|
55
|
+
this.eventListeners = [
|
|
56
|
+
() => widget.removeEventListener('messageSent', messageSentListener),
|
|
57
|
+
() => widget.removeEventListener('widgetOpened', widgetOpenedListener),
|
|
58
|
+
() => widget.removeEventListener('widgetClosed', widgetClosedListener),
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
removeEventListeners() {
|
|
62
|
+
this.eventListeners.forEach(cleanup => cleanup());
|
|
63
|
+
this.eventListeners = [];
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
__decorate([
|
|
67
|
+
ViewChild('chatWidget', { static: false }),
|
|
68
|
+
__metadata("design:type", ElementRef)
|
|
69
|
+
], ChatWidgetComponent.prototype, "chatWidget", void 0);
|
|
70
|
+
__decorate([
|
|
71
|
+
Input(),
|
|
72
|
+
__metadata("design:type", String)
|
|
73
|
+
], ChatWidgetComponent.prototype, "agentName", void 0);
|
|
74
|
+
__decorate([
|
|
75
|
+
Input(),
|
|
76
|
+
__metadata("design:type", String)
|
|
77
|
+
], ChatWidgetComponent.prototype, "agentRole", void 0);
|
|
78
|
+
__decorate([
|
|
79
|
+
Input(),
|
|
80
|
+
__metadata("design:type", String)
|
|
81
|
+
], ChatWidgetComponent.prototype, "primaryColor", void 0);
|
|
82
|
+
__decorate([
|
|
83
|
+
Input(),
|
|
84
|
+
__metadata("design:type", String)
|
|
85
|
+
], ChatWidgetComponent.prototype, "accentColor", void 0);
|
|
86
|
+
__decorate([
|
|
87
|
+
Input(),
|
|
88
|
+
__metadata("design:type", String)
|
|
89
|
+
], ChatWidgetComponent.prototype, "welcomeMessage", void 0);
|
|
90
|
+
__decorate([
|
|
91
|
+
Input(),
|
|
92
|
+
__metadata("design:type", String)
|
|
93
|
+
], ChatWidgetComponent.prototype, "placeholderText", void 0);
|
|
94
|
+
__decorate([
|
|
95
|
+
Input(),
|
|
96
|
+
__metadata("design:type", String)
|
|
97
|
+
], ChatWidgetComponent.prototype, "position", void 0);
|
|
98
|
+
__decorate([
|
|
99
|
+
Input(),
|
|
100
|
+
__metadata("design:type", String)
|
|
101
|
+
], ChatWidgetComponent.prototype, "width", void 0);
|
|
102
|
+
__decorate([
|
|
103
|
+
Input(),
|
|
104
|
+
__metadata("design:type", String)
|
|
105
|
+
], ChatWidgetComponent.prototype, "height", void 0);
|
|
106
|
+
__decorate([
|
|
107
|
+
Input(),
|
|
108
|
+
__metadata("design:type", Boolean)
|
|
109
|
+
], ChatWidgetComponent.prototype, "showMinimizeButton", void 0);
|
|
110
|
+
__decorate([
|
|
111
|
+
Input(),
|
|
112
|
+
__metadata("design:type", Boolean)
|
|
113
|
+
], ChatWidgetComponent.prototype, "showTimestamps", void 0);
|
|
114
|
+
__decorate([
|
|
115
|
+
Input(),
|
|
116
|
+
__metadata("design:type", Boolean)
|
|
117
|
+
], ChatWidgetComponent.prototype, "enableFileUpload", void 0);
|
|
118
|
+
__decorate([
|
|
119
|
+
Input(),
|
|
120
|
+
__metadata("design:type", Boolean)
|
|
121
|
+
], ChatWidgetComponent.prototype, "enableSpeech", void 0);
|
|
122
|
+
__decorate([
|
|
123
|
+
Input(),
|
|
124
|
+
__metadata("design:type", Boolean)
|
|
125
|
+
], ChatWidgetComponent.prototype, "showPoweredBy", void 0);
|
|
126
|
+
__decorate([
|
|
127
|
+
Output(),
|
|
128
|
+
__metadata("design:type", Object)
|
|
129
|
+
], ChatWidgetComponent.prototype, "messageSent", void 0);
|
|
130
|
+
__decorate([
|
|
131
|
+
Output(),
|
|
132
|
+
__metadata("design:type", Object)
|
|
133
|
+
], ChatWidgetComponent.prototype, "widgetOpened", void 0);
|
|
134
|
+
__decorate([
|
|
135
|
+
Output(),
|
|
136
|
+
__metadata("design:type", Object)
|
|
137
|
+
], ChatWidgetComponent.prototype, "widgetClosed", void 0);
|
|
138
|
+
ChatWidgetComponent = __decorate([
|
|
139
|
+
Component({
|
|
140
|
+
selector: 'nerd-chat-widget',
|
|
141
|
+
template: `
|
|
142
|
+
<nerd-chat-widget
|
|
143
|
+
#chatWidget
|
|
144
|
+
[attr.agent-name]="agentName"
|
|
145
|
+
[attr.agent-role]="agentRole"
|
|
146
|
+
[attr.primary-color]="primaryColor"
|
|
147
|
+
[attr.accent-color]="accentColor"
|
|
148
|
+
[attr.welcome-message]="welcomeMessage"
|
|
149
|
+
[attr.placeholder-text]="placeholderText"
|
|
150
|
+
[attr.position]="position"
|
|
151
|
+
[attr.width]="width"
|
|
152
|
+
[attr.height]="height"
|
|
153
|
+
[attr.show-minimize-button]="showMinimizeButton?.toString()"
|
|
154
|
+
[attr.show-timestamps]="showTimestamps?.toString()"
|
|
155
|
+
[attr.enable-file-upload]="enableFileUpload?.toString()"
|
|
156
|
+
[attr.enable-speech]="enableSpeech?.toString()"
|
|
157
|
+
[attr.show-powered-by]="showPoweredBy?.toString()">
|
|
158
|
+
</nerd-chat-widget>
|
|
159
|
+
`,
|
|
160
|
+
styles: []
|
|
161
|
+
})
|
|
162
|
+
], ChatWidgetComponent);
|
|
163
|
+
export { ChatWidgetComponent };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
|
8
|
+
import { CommonModule } from '@angular/common';
|
|
9
|
+
import { ChatWidgetComponent } from './chat-widget.component';
|
|
10
|
+
// Import and define custom elements
|
|
11
|
+
import { defineCustomElements } from 'nerdagent-chat-widget/loader';
|
|
12
|
+
// Define custom elements when module is imported
|
|
13
|
+
defineCustomElements();
|
|
14
|
+
let NerdChatWidgetModule = class NerdChatWidgetModule {
|
|
15
|
+
};
|
|
16
|
+
NerdChatWidgetModule = __decorate([
|
|
17
|
+
NgModule({
|
|
18
|
+
declarations: [
|
|
19
|
+
ChatWidgetComponent
|
|
20
|
+
],
|
|
21
|
+
imports: [
|
|
22
|
+
CommonModule
|
|
23
|
+
],
|
|
24
|
+
exports: [
|
|
25
|
+
ChatWidgetComponent
|
|
26
|
+
],
|
|
27
|
+
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
|
28
|
+
})
|
|
29
|
+
], NerdChatWidgetModule);
|
|
30
|
+
export { NerdChatWidgetModule };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type WidgetPosition = 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
|
|
2
|
+
export interface ChatWidgetConfig {
|
|
3
|
+
agentName?: string;
|
|
4
|
+
agentRole?: string;
|
|
5
|
+
primaryColor?: string;
|
|
6
|
+
accentColor?: string;
|
|
7
|
+
welcomeMessage?: string;
|
|
8
|
+
placeholderText?: string;
|
|
9
|
+
position?: WidgetPosition;
|
|
10
|
+
width?: string;
|
|
11
|
+
height?: string;
|
|
12
|
+
showMinimizeButton?: boolean;
|
|
13
|
+
showTimestamps?: boolean;
|
|
14
|
+
enableFileUpload?: boolean;
|
|
15
|
+
enableSpeech?: boolean;
|
|
16
|
+
showPoweredBy?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface ChatWidgetEvents {
|
|
19
|
+
messageSent: CustomEvent<{
|
|
20
|
+
message: string;
|
|
21
|
+
timestamp: Date;
|
|
22
|
+
}>;
|
|
23
|
+
widgetOpened: CustomEvent<void>;
|
|
24
|
+
widgetClosed: CustomEvent<void>;
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nerdagent-chat-widget-angular",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "NerdAgent Chat Widget for Angular",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist/"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsc",
|
|
13
|
+
"prepublishOnly": "npm run build"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"angular",
|
|
17
|
+
"chat",
|
|
18
|
+
"widget",
|
|
19
|
+
"stencil",
|
|
20
|
+
"web-components"
|
|
21
|
+
],
|
|
22
|
+
"author": "NerdAgent",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@angular/common": "^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0",
|
|
26
|
+
"@angular/core": "^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"nerdagent-chat-widget": "^1.0.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@angular/common": "^18.0.0",
|
|
33
|
+
"@angular/core": "^18.0.0",
|
|
34
|
+
"@types/node": "^20.0.0",
|
|
35
|
+
"typescript": "^5.0.0"
|
|
36
|
+
},
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "https://github.com/nerdagent/chat-widget.git",
|
|
40
|
+
"directory": "packages/angular"
|
|
41
|
+
},
|
|
42
|
+
"gitHead": "baebff96671fd060b15aa0ca587f2c9a1556c06b"
|
|
43
|
+
}
|