@bbq-chat/widgets-angular 1.0.9 → 1.0.11

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 (42) hide show
  1. package/fesm2022/index.mjs +2152 -0
  2. package/fesm2022/index.mjs.map +1 -0
  3. package/package.json +15 -20
  4. package/types/index.d.ts +660 -0
  5. package/.angular/cache/21.0.5/ng-packagr/97cbacd0e5e4cb18d1fead4d7f3aee1c3863ba3ffbe7cb7dd7780f237a848a5c +0 -1
  6. package/.angular/cache/21.0.5/ng-packagr/tsbuildinfo/index.tsbuildinfo +0 -1
  7. package/.eslintrc.json +0 -23
  8. package/.prettierrc.json +0 -8
  9. package/EXAMPLES.md +0 -484
  10. package/angular.json +0 -36
  11. package/ng-package.json +0 -9
  12. package/src/angular-widget-renderer.spec.ts +0 -157
  13. package/src/components/button.component.ts +0 -35
  14. package/src/components/card.component.ts +0 -52
  15. package/src/components/datepicker.component.ts +0 -63
  16. package/src/components/dropdown.component.ts +0 -65
  17. package/src/components/fileupload.component.ts +0 -71
  18. package/src/components/form.component.ts +0 -433
  19. package/src/components/image.component.ts +0 -33
  20. package/src/components/imagecollection.component.ts +0 -39
  21. package/src/components/index.ts +0 -20
  22. package/src/components/input.component.ts +0 -63
  23. package/src/components/multiselect.component.ts +0 -67
  24. package/src/components/progressbar.component.ts +0 -50
  25. package/src/components/slider.component.ts +0 -67
  26. package/src/components/textarea.component.ts +0 -63
  27. package/src/components/themeswitcher.component.ts +0 -46
  28. package/src/components/toggle.component.ts +0 -63
  29. package/src/custom-widget-renderer.types.ts +0 -120
  30. package/src/examples/form-validation-listener.component.ts +0 -41
  31. package/src/public_api.ts +0 -107
  32. package/src/renderers/AngularWidgetRenderer.ts +0 -100
  33. package/src/renderers/built-in-components.ts +0 -41
  34. package/src/renderers/index.ts +0 -7
  35. package/src/services/form-validation.service.ts +0 -21
  36. package/src/widget-di.tokens.ts +0 -95
  37. package/src/widget-registry.service.ts +0 -128
  38. package/src/widget-renderer.component.ts +0 -421
  39. package/tsconfig.json +0 -37
  40. package/tsconfig.lib.json +0 -18
  41. package/tsconfig.lib.prod.json +0 -11
  42. package/tsconfig.spec.json +0 -13
package/EXAMPLES.md DELETED
@@ -1,484 +0,0 @@
1
- # Usage Examples
2
-
3
- ## Understanding Widget Rendering
4
-
5
- The `@bbq-chat/widgets-angular` package uses the **AngularWidgetRenderer** to render all built-in widgets as native Angular components. This provides better performance, type safety, and full Angular framework integration compared to HTML string rendering.
6
-
7
- ### Automatic Angular Rendering
8
-
9
- When you use `WidgetRendererComponent`, it automatically uses `AngularWidgetRenderer` for all built-in widget types:
10
-
11
- - ✅ **Built-in widgets** (button, card, form, etc.) → Rendered as Angular components
12
- - ✅ **Custom component renderers** → Your Angular components
13
- - ✅ **Custom template renderers** → Your Angular templates
14
- - ✅ **HTML function renderers** → Your custom HTML strings
15
- - ✅ **Fallback** → SSR renderer for compatibility
16
-
17
- No configuration needed - it just works!
18
-
19
- ## Basic Usage
20
-
21
- ### 1. Install the package
22
-
23
- ```bash
24
- npm install @bbq-chat/widgets-angular @bbq-chat/widgets
25
- ```
26
-
27
- ### 2. Import styles in your global styles file
28
-
29
- In `styles.css` or `styles.scss`:
30
-
31
- ```css
32
- @import '@bbq-chat/widgets/styles';
33
- ```
34
-
35
- ### 3. Create a chat component
36
-
37
- ```typescript
38
- import { Component } from '@angular/core';
39
- import { CommonModule } from '@angular/common';
40
- import { WidgetRendererComponent } from '@bbq-chat/widgets-angular';
41
- import type { ChatWidget } from '@bbq-chat/widgets-angular';
42
-
43
- @Component({
44
- selector: 'app-chat',
45
- standalone: true,
46
- imports: [CommonModule, WidgetRendererComponent],
47
- template: `
48
- <div class="chat-container">
49
- <div class="messages">
50
- @for (message of messages; track message.id) {
51
- <div class="message">
52
- <div class="message-content">{{ message.content }}</div>
53
- <bbq-widget-renderer
54
- [widgets]="message.widgets"
55
- (widgetAction)="handleWidgetAction($event)">
56
- </bbq-widget-renderer>
57
- </div>
58
- }
59
- </div>
60
-
61
- <div class="input-area">
62
- <input
63
- type="text"
64
- [(ngModel)]="userInput"
65
- (keyup.enter)="sendMessage()"
66
- placeholder="Type a message..."
67
- />
68
- <button (click)="sendMessage()">Send</button>
69
- </div>
70
- </div>
71
- `,
72
- styles: [`
73
- .chat-container {
74
- display: flex;
75
- flex-direction: column;
76
- height: 100vh;
77
- max-width: 800px;
78
- margin: 0 auto;
79
- }
80
-
81
- .messages {
82
- flex: 1;
83
- overflow-y: auto;
84
- padding: 1rem;
85
- }
86
-
87
- .message {
88
- margin-bottom: 1rem;
89
- }
90
-
91
- .message-content {
92
- margin-bottom: 0.5rem;
93
- }
94
-
95
- .input-area {
96
- display: flex;
97
- gap: 0.5rem;
98
- padding: 1rem;
99
- border-top: 1px solid #ccc;
100
- }
101
-
102
- input {
103
- flex: 1;
104
- padding: 0.5rem;
105
- }
106
- `]
107
- })
108
- export class ChatComponent {
109
- messages: Array<{ id: number; content: string; widgets?: ChatWidget[] }> = [];
110
- userInput = '';
111
- private messageId = 0;
112
-
113
- async sendMessage() {
114
- if (!this.userInput.trim()) return;
115
-
116
- // Add user message
117
- this.messages.push({
118
- id: this.messageId++,
119
- content: this.userInput,
120
- });
121
-
122
- const userMessage = this.userInput;
123
- this.userInput = '';
124
-
125
- // Send to backend
126
- try {
127
- const response = await fetch('/api/chat/message', {
128
- method: 'POST',
129
- headers: { 'Content-Type': 'application/json' },
130
- body: JSON.stringify({ message: userMessage }),
131
- });
132
-
133
- const data = await response.json();
134
-
135
- // Add assistant response with widgets
136
- this.messages.push({
137
- id: this.messageId++,
138
- content: data.content || '',
139
- widgets: data.widgets || [],
140
- });
141
- } catch (error) {
142
- console.error('Failed to send message:', error);
143
- }
144
- }
145
-
146
- async handleWidgetAction(event: { actionName: string; payload: any }) {
147
- console.log('Widget action:', event);
148
-
149
- try {
150
- const response = await fetch('/api/chat/action', {
151
- method: 'POST',
152
- headers: { 'Content-Type': 'application/json' },
153
- body: JSON.stringify({
154
- action: event.actionName,
155
- payload: event.payload,
156
- }),
157
- });
158
-
159
- const data = await response.json();
160
-
161
- // Add response with new widgets
162
- this.messages.push({
163
- id: this.messageId++,
164
- content: data.content || '',
165
- widgets: data.widgets || [],
166
- });
167
- } catch (error) {
168
- console.error('Failed to handle widget action:', error);
169
- }
170
- }
171
- }
172
- ```
173
-
174
- ## Using Custom Widgets
175
-
176
- ### 1. Define your custom widget
177
-
178
- ```typescript
179
- // custom-widgets/weather-widget.ts
180
- import { ChatWidget } from '@bbq-chat/widgets-angular';
181
-
182
- export class WeatherWidget extends ChatWidget {
183
- override type = 'weather';
184
-
185
- constructor(
186
- public label: string,
187
- public action: string,
188
- public city: string,
189
- public temperature: number,
190
- public condition: string
191
- ) {
192
- super(label, action);
193
- }
194
- }
195
- ```
196
-
197
- ### 2. Register the custom widget
198
-
199
- ```typescript
200
- // app.config.ts or component
201
- import { Component, OnInit } from '@angular/core';
202
- import { WidgetRegistryService } from '@bbq-chat/widgets-angular';
203
- import { WeatherWidget } from './custom-widgets/weather-widget';
204
-
205
- @Component({
206
- selector: 'app-root',
207
- template: '...'
208
- })
209
- export class AppComponent implements OnInit {
210
- constructor(private widgetRegistry: WidgetRegistryService) {}
211
-
212
- ngOnInit() {
213
- // Register custom widget factory
214
- this.widgetRegistry.registerFactory('weather', (obj: any) => {
215
- if (obj.type === 'weather') {
216
- return new WeatherWidget(
217
- obj.label,
218
- obj.action,
219
- obj.city,
220
- obj.temperature,
221
- obj.condition
222
- );
223
- }
224
- return null;
225
- });
226
- }
227
- }
228
- ```
229
-
230
- ### 3. Create custom renderers
231
-
232
- The library now supports three types of custom renderers:
233
-
234
- #### Option A: HTML Function Renderer
235
-
236
- Use a function that returns HTML strings:
237
-
238
- ```typescript
239
- import { Component, OnInit } from '@angular/core';
240
- import { WidgetRegistryService } from '@bbq-chat/widgets-angular';
241
- import { WeatherWidget } from './custom-widgets/weather-widget';
242
-
243
- @Component({
244
- selector: 'app-root',
245
- template: '...'
246
- })
247
- export class AppComponent implements OnInit {
248
- constructor(private widgetRegistry: WidgetRegistryService) {}
249
-
250
- ngOnInit() {
251
- // Register custom widget factory
252
- this.widgetRegistry.registerFactory('weather', (obj: any) => {
253
- if (obj.type === 'weather') {
254
- return new WeatherWidget(
255
- obj.label,
256
- obj.action,
257
- obj.city,
258
- obj.temperature,
259
- obj.condition
260
- );
261
- }
262
- return null;
263
- });
264
-
265
- // Register HTML renderer
266
- this.widgetRegistry.registerRenderer('weather', (widget) => {
267
- const w = widget as WeatherWidget;
268
- return `
269
- <div class="weather-widget">
270
- <h3>${w.city}</h3>
271
- <p>${w.temperature}°C - ${w.condition}</p>
272
- </div>
273
- `;
274
- });
275
- }
276
- }
277
- ```
278
-
279
- #### Option B: Angular Component Renderer (Recommended)
280
-
281
- Create an Angular component for better type safety and data binding:
282
-
283
- ```typescript
284
- // weather-widget.component.ts
285
- import { Component, Input } from '@angular/core';
286
- import { CommonModule } from '@angular/common';
287
- import { CustomWidgetComponent } from '@bbq-chat/widgets-angular';
288
- import { WeatherWidget } from './custom-widgets/weather-widget';
289
-
290
- @Component({
291
- selector: 'app-weather-widget',
292
- standalone: true,
293
- imports: [CommonModule],
294
- template: `
295
- <div class="weather-widget">
296
- <h3>{{ weatherWidget.city }}</h3>
297
- <div class="weather-info">
298
- <p class="temperature">{{ weatherWidget.temperature }}°C</p>
299
- <p class="condition">{{ weatherWidget.condition }}</p>
300
- </div>
301
- <button (click)="onRefresh()">Refresh</button>
302
- </div>
303
- `,
304
- styles: [`
305
- .weather-widget {
306
- padding: 1rem;
307
- border: 1px solid #ccc;
308
- border-radius: 8px;
309
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
310
- color: white;
311
- }
312
- .temperature {
313
- font-size: 2rem;
314
- font-weight: bold;
315
- }
316
- `]
317
- })
318
- export class WeatherWidgetComponent implements CustomWidgetComponent {
319
- @Input() widget!: ChatWidget;
320
- widgetAction?: (actionName: string, payload: unknown) => void;
321
-
322
- get weatherWidget(): WeatherWidget {
323
- return this.widget as WeatherWidget;
324
- }
325
-
326
- onRefresh() {
327
- if (this.widgetAction) {
328
- this.widgetAction('refresh_weather', {
329
- city: this.weatherWidget.city
330
- });
331
- }
332
- }
333
- }
334
- ```
335
-
336
- Then register the component:
337
-
338
- ```typescript
339
- import { Component, OnInit } from '@angular/core';
340
- import { WidgetRegistryService } from '@bbq-chat/widgets-angular';
341
- import { WeatherWidget } from './custom-widgets/weather-widget';
342
- import { WeatherWidgetComponent } from './weather-widget.component';
343
-
344
- @Component({
345
- selector: 'app-root',
346
- template: '...'
347
- })
348
- export class AppComponent implements OnInit {
349
- constructor(private widgetRegistry: WidgetRegistryService) {}
350
-
351
- ngOnInit() {
352
- // Register custom widget factory
353
- this.widgetRegistry.registerFactory('weather', (obj: any) => {
354
- if (obj.type === 'weather') {
355
- return new WeatherWidget(
356
- obj.label,
357
- obj.action,
358
- obj.city,
359
- obj.temperature,
360
- obj.condition
361
- );
362
- }
363
- return null;
364
- });
365
-
366
- // Register component renderer - enables full Angular features
367
- this.widgetRegistry.registerRenderer('weather', WeatherWidgetComponent);
368
- }
369
- }
370
- ```
371
-
372
- #### Option C: Angular Template Renderer
373
-
374
- Use Angular templates for inline rendering with data binding:
375
-
376
- ```typescript
377
- import { Component, OnInit, ViewChild, TemplateRef } from '@angular/core';
378
- import { WidgetRegistryService, WidgetTemplateContext } from '@bbq-chat/widgets-angular';
379
- import { WeatherWidget } from './custom-widgets/weather-widget';
380
-
381
- @Component({
382
- selector: 'app-root',
383
- template: `
384
- <ng-template #weatherTemplate let-widget let-emitAction="emitAction">
385
- <div class="weather-widget">
386
- <h3>{{ widget.city }}</h3>
387
- <p>{{ widget.temperature }}°C - {{ widget.condition }}</p>
388
- <button (click)="emitAction('refresh_weather', { city: widget.city })">
389
- Refresh
390
- </button>
391
- </div>
392
- </ng-template>
393
-
394
- <bbq-widget-renderer
395
- [widgets]="widgets"
396
- (widgetAction)="handleWidgetAction($event)">
397
- </bbq-widget-renderer>
398
- `
399
- })
400
- export class AppComponent implements OnInit {
401
- @ViewChild('weatherTemplate', { static: true })
402
- weatherTemplate!: TemplateRef<WidgetTemplateContext>;
403
-
404
- widgets: ChatWidget[] = [];
405
-
406
- constructor(private widgetRegistry: WidgetRegistryService) {}
407
-
408
- ngOnInit() {
409
- // Register custom widget factory
410
- this.widgetRegistry.registerFactory('weather', (obj: any) => {
411
- if (obj.type === 'weather') {
412
- return new WeatherWidget(
413
- obj.label,
414
- obj.action,
415
- obj.city,
416
- obj.temperature,
417
- obj.condition
418
- );
419
- }
420
- return null;
421
- });
422
-
423
- // Register template renderer - enables inline Angular templates
424
- this.widgetRegistry.registerRenderer('weather', this.weatherTemplate);
425
- }
426
-
427
- handleWidgetAction(event: { actionName: string; payload: any }) {
428
- console.log('Widget action:', event);
429
- }
430
- }
431
- ```
432
-
433
- ### Benefits of Component-Based Renderers
434
-
435
- Using Angular components for custom widgets provides several advantages:
436
-
437
- 1. **Type Safety**: Full TypeScript support with interfaces and types
438
- 2. **Data Binding**: Use Angular's powerful two-way data binding
439
- 3. **Lifecycle Hooks**: Access to Angular lifecycle hooks (ngOnInit, ngOnDestroy, etc.)
440
- 4. **Change Detection**: Automatic UI updates when data changes
441
- 5. **Dependency Injection**: Inject services directly into widget components
442
- 6. **Animations**: Use Angular animations for smooth transitions
443
- 7. **Reactive Forms**: Integrate with Angular reactive forms
444
- 8. **Testing**: Easier unit testing with Angular TestBed
445
-
446
- ## Integration with Forms
447
-
448
- The package automatically handles form submissions. Example:
449
-
450
- ```typescript
451
- handleWidgetAction(event: { actionName: string; payload: any }) {
452
- if (event.actionName === 'submit_form') {
453
- console.log('Form data:', event.payload);
454
- // payload contains all form field values
455
- // { name: 'John', email: 'john@example.com', ... }
456
- }
457
- }
458
- ```
459
-
460
- ## Theming
461
-
462
- Import different themes:
463
-
464
- ```css
465
- /* Light theme (default) */
466
- @import '@bbq-chat/widgets/styles/light';
467
-
468
- /* Dark theme */
469
- @import '@bbq-chat/widgets/styles/dark';
470
-
471
- /* Corporate theme */
472
- @import '@bbq-chat/widgets/styles/corporate';
473
- ```
474
-
475
- Or customize with CSS variables:
476
-
477
- ```css
478
- :root {
479
- --bbq-primary-color: #007bff;
480
- --bbq-secondary-color: #6c757d;
481
- --bbq-border-radius: 8px;
482
- /* ... other variables */
483
- }
484
- ```
package/angular.json DELETED
@@ -1,36 +0,0 @@
1
- {
2
- "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3
- "version": 1,
4
- "cli": {
5
- "packageManager": "npm"
6
- },
7
- "newProjectRoot": "projects",
8
- "projects": {
9
- "js-angular": {
10
- "projectType": "library",
11
- "root": "./",
12
- "sourceRoot": "src",
13
- "prefix": "lib",
14
- "architect": {
15
- "build": {
16
- "builder": "@angular/build:ng-packagr",
17
- "configurations": {
18
- "production": {
19
- "tsConfig": "tsconfig.lib.prod.json"
20
- },
21
- "development": {
22
- "tsConfig": "tsconfig.lib.json"
23
- }
24
- },
25
- "defaultConfiguration": "production"
26
- },
27
- "test": {
28
- "builder": "@angular/build:unit-test",
29
- "options": {
30
- "tsConfig": "tsconfig.spec.json"
31
- }
32
- }
33
- }
34
- }
35
- }
36
- }
package/ng-package.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "$schema": "node_modules/ng-packagr/ng-package.schema.json",
3
- "dest": "dist",
4
- "lib": {
5
- "entryFile": "src/public_api.ts",
6
- "flatModuleFile": "index"
7
- },
8
- "deleteDestPath": true
9
- }
@@ -1,157 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { AngularWidgetRenderer } from './renderers/AngularWidgetRenderer';
3
- import { ButtonWidgetComponent } from './components/button.component';
4
- import { InputWidgetComponent } from './components/input.component';
5
- import { CardWidgetComponent } from './components/card.component';
6
-
7
- describe('AngularWidgetRenderer', () => {
8
- it('should create an instance', () => {
9
- const renderer = new AngularWidgetRenderer();
10
- expect(renderer).toBeTruthy();
11
- expect(renderer.framework).toBe('Angular');
12
- });
13
-
14
- it('should register components', () => {
15
- const renderer = new AngularWidgetRenderer();
16
- renderer.registerComponent('button', ButtonWidgetComponent);
17
-
18
- const mockWidget = {
19
- type: 'button',
20
- label: 'Test',
21
- action: 'test_action',
22
- toJson: () => '{}',
23
- toObject: () => ({})
24
- };
25
-
26
- const componentType = renderer.getComponentType(mockWidget);
27
- expect(componentType).toBe(ButtonWidgetComponent);
28
- });
29
-
30
- it('should register multiple components at once', () => {
31
- const renderer = new AngularWidgetRenderer();
32
- renderer.registerComponents({
33
- button: ButtonWidgetComponent,
34
- input: InputWidgetComponent
35
- });
36
-
37
- const mockButtonWidget = {
38
- type: 'button',
39
- label: 'Test',
40
- action: 'test_action',
41
- toJson: () => '{}',
42
- toObject: () => ({})
43
- };
44
-
45
- const mockInputWidget = {
46
- type: 'input',
47
- label: 'Test',
48
- action: 'test_action',
49
- toJson: () => '{}',
50
- toObject: () => ({})
51
- };
52
-
53
- expect(renderer.getComponentType(mockButtonWidget)).toBe(ButtonWidgetComponent);
54
- expect(renderer.getComponentType(mockInputWidget)).toBe(InputWidgetComponent);
55
- });
56
-
57
- it('should return null for unregistered widget types', () => {
58
- const renderer = new AngularWidgetRenderer();
59
-
60
- const mockWidget = {
61
- type: 'unknown',
62
- label: 'Test',
63
- action: 'test_action',
64
- toJson: () => '{}',
65
- toObject: () => ({})
66
- };
67
-
68
- const componentType = renderer.getComponentType(mockWidget);
69
- expect(componentType).toBeNull();
70
- });
71
-
72
- it('should respect custom overrides from constructor', () => {
73
- const customComponent = ButtonWidgetComponent; // Use as a stand-in for custom component
74
- const renderer = new AngularWidgetRenderer({
75
- components: {
76
- button: customComponent
77
- }
78
- });
79
-
80
- const mockWidget = {
81
- type: 'button',
82
- label: 'Test',
83
- action: 'test_action',
84
- toJson: () => '{}',
85
- toObject: () => ({})
86
- };
87
-
88
- const componentType = renderer.getComponentType(mockWidget);
89
- expect(componentType).toBe(customComponent);
90
- });
91
-
92
- it('should prioritize constructor overrides over registered components', () => {
93
- const constructorComponent = CardWidgetComponent;
94
- const registeredComponent = ButtonWidgetComponent;
95
-
96
- const renderer = new AngularWidgetRenderer({
97
- components: {
98
- button: constructorComponent
99
- }
100
- });
101
-
102
- // Register a different component
103
- renderer.registerComponent('button', registeredComponent);
104
-
105
- const mockWidget = {
106
- type: 'button',
107
- label: 'Test',
108
- action: 'test_action',
109
- toJson: () => '{}',
110
- toObject: () => ({})
111
- };
112
-
113
- // Constructor override should take precedence
114
- const componentType = renderer.getComponentType(mockWidget);
115
- expect(componentType).toBe(constructorComponent);
116
- });
117
-
118
- it('should register built-in components', () => {
119
- const renderer = new AngularWidgetRenderer();
120
-
121
- const builtInComponents = {
122
- button: ButtonWidgetComponent,
123
- input: InputWidgetComponent,
124
- card: CardWidgetComponent
125
- };
126
-
127
- renderer.registerBuiltInComponents(builtInComponents);
128
-
129
- const mockButtonWidget = {
130
- type: 'button',
131
- label: 'Test',
132
- action: 'test_action',
133
- toJson: () => '{}',
134
- toObject: () => ({})
135
- };
136
-
137
- const mockInputWidget = {
138
- type: 'input',
139
- label: 'Test',
140
- action: 'test_action',
141
- toJson: () => '{}',
142
- toObject: () => ({})
143
- };
144
-
145
- const mockCardWidget = {
146
- type: 'card',
147
- label: 'Test',
148
- action: 'test_action',
149
- toJson: () => '{}',
150
- toObject: () => ({})
151
- };
152
-
153
- expect(renderer.getComponentType(mockButtonWidget)).toBe(ButtonWidgetComponent);
154
- expect(renderer.getComponentType(mockInputWidget)).toBe(InputWidgetComponent);
155
- expect(renderer.getComponentType(mockCardWidget)).toBe(CardWidgetComponent);
156
- });
157
- });