@bbq-chat/widgets-angular 1.0.4 → 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/README.md +92 -3
- package/dist/README.md +92 -3
- package/dist/fesm2022/index.mjs +1468 -18
- package/dist/fesm2022/index.mjs.map +1 -1
- package/dist/types/index.d.ts +290 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
Angular components and services for BbQ ChatWidgets. This package provides Angular-native wrappers for the core [@bbq-chat/widgets](https://www.npmjs.com/package/@bbq-chat/widgets) library.
|
|
4
4
|
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ✨ **Native Angular Components** - All widgets render as Angular components with full framework support
|
|
8
|
+
- 🎨 **Type-Safe** - Full TypeScript support with comprehensive type definitions
|
|
9
|
+
- 🔄 **Two-Way Data Binding** - Leverage Angular's powerful data binding
|
|
10
|
+
- 🎯 **Automatic Rendering** - The `WidgetRendererComponent` automatically uses `AngularWidgetRenderer` for all built-in widgets
|
|
11
|
+
- 🔧 **Extensible** - Easy custom widget registration with full Angular component support
|
|
12
|
+
|
|
5
13
|
## Installation
|
|
6
14
|
|
|
7
15
|
```bash
|
|
@@ -65,7 +73,12 @@ Or import a specific theme:
|
|
|
65
73
|
|
|
66
74
|
### WidgetRendererComponent
|
|
67
75
|
|
|
68
|
-
The main component for rendering chat widgets.
|
|
76
|
+
The main component for rendering chat widgets. It automatically uses the `AngularWidgetRenderer` to render all built-in widgets as native Angular components.
|
|
77
|
+
|
|
78
|
+
**Rendering Modes:**
|
|
79
|
+
- Built-in widgets (button, card, form, etc.) are rendered as Angular components via `AngularWidgetRenderer`
|
|
80
|
+
- Custom widgets can use HTML functions, Angular components, or Angular templates
|
|
81
|
+
- Falls back to `SsrWidgetRenderer` (HTML string rendering) if needed for compatibility
|
|
69
82
|
|
|
70
83
|
**Inputs:**
|
|
71
84
|
- `widgets: ChatWidget[] | null | undefined` - Array of widgets to render
|
|
@@ -120,11 +133,11 @@ export class AppComponent implements OnInit {
|
|
|
120
133
|
|
|
121
134
|
## Widget Types
|
|
122
135
|
|
|
123
|
-
All standard widget types from `@bbq-chat/widgets` are supported:
|
|
136
|
+
All standard widget types from `@bbq-chat/widgets` are supported and rendered as native Angular components:
|
|
124
137
|
|
|
125
138
|
- `ButtonWidget` - Clickable buttons
|
|
126
139
|
- `CardWidget` - Information cards
|
|
127
|
-
- `FormWidget` - Form containers
|
|
140
|
+
- `FormWidget` - Form containers with validation
|
|
128
141
|
- `InputWidget` - Text input fields
|
|
129
142
|
- `TextAreaWidget` - Multi-line text input
|
|
130
143
|
- `DropdownWidget` - Dropdown selects
|
|
@@ -138,6 +151,82 @@ All standard widget types from `@bbq-chat/widgets` are supported:
|
|
|
138
151
|
- `ImageWidget` - Image displays
|
|
139
152
|
- `ImageCollectionWidget` - Image galleries
|
|
140
153
|
|
|
154
|
+
## AngularWidgetRenderer
|
|
155
|
+
|
|
156
|
+
The `AngularWidgetRenderer` is automatically used by `WidgetRendererComponent` to render all built-in widgets as native Angular components instead of HTML strings. This provides several advantages:
|
|
157
|
+
|
|
158
|
+
### Benefits
|
|
159
|
+
|
|
160
|
+
- **Native Angular Components** - Full Angular lifecycle hooks, change detection, and dependency injection
|
|
161
|
+
- **Type Safety** - Strong typing throughout the rendering pipeline
|
|
162
|
+
- **Better Performance** - No need for `innerHTML` or manual DOM manipulation
|
|
163
|
+
- **Reactive Updates** - Leverage Angular's reactive forms and data binding
|
|
164
|
+
- **Testability** - Easier to test with Angular TestBed
|
|
165
|
+
- **Easy Component Swapping** - Simple API to replace any widget component with your own
|
|
166
|
+
|
|
167
|
+
### How It Works
|
|
168
|
+
|
|
169
|
+
The `WidgetRendererComponent` automatically detects and uses `AngularWidgetRenderer` for all built-in widget types:
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
// The WidgetRendererComponent automatically uses AngularWidgetRenderer
|
|
173
|
+
// No configuration needed - it just works!
|
|
174
|
+
<bbq-widget-renderer
|
|
175
|
+
[widgets]="widgets"
|
|
176
|
+
(widgetAction)="handleWidgetAction($event)">
|
|
177
|
+
</bbq-widget-renderer>
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Swapping Widget Components
|
|
181
|
+
|
|
182
|
+
You can easily replace any built-in widget component with your own custom implementation:
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
import { Component, OnInit, Inject } from '@angular/core';
|
|
186
|
+
import { ANGULAR_WIDGET_RENDERER, AngularWidgetRenderer } from '@bbq-chat/widgets-angular';
|
|
187
|
+
import { MyCustomButtonComponent } from './my-custom-button.component';
|
|
188
|
+
|
|
189
|
+
@Component({
|
|
190
|
+
selector: 'app-root',
|
|
191
|
+
template: '...'
|
|
192
|
+
})
|
|
193
|
+
export class AppComponent implements OnInit {
|
|
194
|
+
constructor(@Inject(ANGULAR_WIDGET_RENDERER) private renderer: AngularWidgetRenderer) {}
|
|
195
|
+
|
|
196
|
+
ngOnInit() {
|
|
197
|
+
// Replace the built-in button component with your custom one
|
|
198
|
+
this.renderer.registerComponent('button', MyCustomButtonComponent);
|
|
199
|
+
|
|
200
|
+
// Or register multiple components at once
|
|
201
|
+
this.renderer.registerComponents({
|
|
202
|
+
button: MyCustomButtonComponent,
|
|
203
|
+
input: MyCustomInputComponent,
|
|
204
|
+
card: MyCustomCardComponent
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Built-in Widget Components
|
|
211
|
+
|
|
212
|
+
All built-in widgets are available as standalone Angular components:
|
|
213
|
+
|
|
214
|
+
```typescript
|
|
215
|
+
import {
|
|
216
|
+
ButtonWidgetComponent,
|
|
217
|
+
CardWidgetComponent,
|
|
218
|
+
FormWidgetComponent,
|
|
219
|
+
InputWidgetComponent,
|
|
220
|
+
// ... and more
|
|
221
|
+
} from '@bbq-chat/widgets-angular';
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
These components can be used directly in your templates if needed, though typically you'll use them through `WidgetRendererComponent`.
|
|
225
|
+
|
|
226
|
+
### Form Widget Dynamic Rendering
|
|
227
|
+
|
|
228
|
+
The `FormWidgetComponent` uses dynamic component rendering to render form fields. Instead of inline HTML, it dynamically instantiates the appropriate widget component (InputWidget, SliderWidget, etc.) for each field. This ensures consistency across all widgets and makes the form behavior automatically inherit any custom widget component replacements.
|
|
229
|
+
|
|
141
230
|
## Advanced Usage
|
|
142
231
|
|
|
143
232
|
### Handling Widget Actions
|
package/dist/README.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
Angular components and services for BbQ ChatWidgets. This package provides Angular-native wrappers for the core [@bbq-chat/widgets](https://www.npmjs.com/package/@bbq-chat/widgets) library.
|
|
4
4
|
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ✨ **Native Angular Components** - All widgets render as Angular components with full framework support
|
|
8
|
+
- 🎨 **Type-Safe** - Full TypeScript support with comprehensive type definitions
|
|
9
|
+
- 🔄 **Two-Way Data Binding** - Leverage Angular's powerful data binding
|
|
10
|
+
- 🎯 **Automatic Rendering** - The `WidgetRendererComponent` automatically uses `AngularWidgetRenderer` for all built-in widgets
|
|
11
|
+
- 🔧 **Extensible** - Easy custom widget registration with full Angular component support
|
|
12
|
+
|
|
5
13
|
## Installation
|
|
6
14
|
|
|
7
15
|
```bash
|
|
@@ -65,7 +73,12 @@ Or import a specific theme:
|
|
|
65
73
|
|
|
66
74
|
### WidgetRendererComponent
|
|
67
75
|
|
|
68
|
-
The main component for rendering chat widgets.
|
|
76
|
+
The main component for rendering chat widgets. It automatically uses the `AngularWidgetRenderer` to render all built-in widgets as native Angular components.
|
|
77
|
+
|
|
78
|
+
**Rendering Modes:**
|
|
79
|
+
- Built-in widgets (button, card, form, etc.) are rendered as Angular components via `AngularWidgetRenderer`
|
|
80
|
+
- Custom widgets can use HTML functions, Angular components, or Angular templates
|
|
81
|
+
- Falls back to `SsrWidgetRenderer` (HTML string rendering) if needed for compatibility
|
|
69
82
|
|
|
70
83
|
**Inputs:**
|
|
71
84
|
- `widgets: ChatWidget[] | null | undefined` - Array of widgets to render
|
|
@@ -120,11 +133,11 @@ export class AppComponent implements OnInit {
|
|
|
120
133
|
|
|
121
134
|
## Widget Types
|
|
122
135
|
|
|
123
|
-
All standard widget types from `@bbq-chat/widgets` are supported:
|
|
136
|
+
All standard widget types from `@bbq-chat/widgets` are supported and rendered as native Angular components:
|
|
124
137
|
|
|
125
138
|
- `ButtonWidget` - Clickable buttons
|
|
126
139
|
- `CardWidget` - Information cards
|
|
127
|
-
- `FormWidget` - Form containers
|
|
140
|
+
- `FormWidget` - Form containers with validation
|
|
128
141
|
- `InputWidget` - Text input fields
|
|
129
142
|
- `TextAreaWidget` - Multi-line text input
|
|
130
143
|
- `DropdownWidget` - Dropdown selects
|
|
@@ -138,6 +151,82 @@ All standard widget types from `@bbq-chat/widgets` are supported:
|
|
|
138
151
|
- `ImageWidget` - Image displays
|
|
139
152
|
- `ImageCollectionWidget` - Image galleries
|
|
140
153
|
|
|
154
|
+
## AngularWidgetRenderer
|
|
155
|
+
|
|
156
|
+
The `AngularWidgetRenderer` is automatically used by `WidgetRendererComponent` to render all built-in widgets as native Angular components instead of HTML strings. This provides several advantages:
|
|
157
|
+
|
|
158
|
+
### Benefits
|
|
159
|
+
|
|
160
|
+
- **Native Angular Components** - Full Angular lifecycle hooks, change detection, and dependency injection
|
|
161
|
+
- **Type Safety** - Strong typing throughout the rendering pipeline
|
|
162
|
+
- **Better Performance** - No need for `innerHTML` or manual DOM manipulation
|
|
163
|
+
- **Reactive Updates** - Leverage Angular's reactive forms and data binding
|
|
164
|
+
- **Testability** - Easier to test with Angular TestBed
|
|
165
|
+
- **Easy Component Swapping** - Simple API to replace any widget component with your own
|
|
166
|
+
|
|
167
|
+
### How It Works
|
|
168
|
+
|
|
169
|
+
The `WidgetRendererComponent` automatically detects and uses `AngularWidgetRenderer` for all built-in widget types:
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
// The WidgetRendererComponent automatically uses AngularWidgetRenderer
|
|
173
|
+
// No configuration needed - it just works!
|
|
174
|
+
<bbq-widget-renderer
|
|
175
|
+
[widgets]="widgets"
|
|
176
|
+
(widgetAction)="handleWidgetAction($event)">
|
|
177
|
+
</bbq-widget-renderer>
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Swapping Widget Components
|
|
181
|
+
|
|
182
|
+
You can easily replace any built-in widget component with your own custom implementation:
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
import { Component, OnInit, Inject } from '@angular/core';
|
|
186
|
+
import { ANGULAR_WIDGET_RENDERER, AngularWidgetRenderer } from '@bbq-chat/widgets-angular';
|
|
187
|
+
import { MyCustomButtonComponent } from './my-custom-button.component';
|
|
188
|
+
|
|
189
|
+
@Component({
|
|
190
|
+
selector: 'app-root',
|
|
191
|
+
template: '...'
|
|
192
|
+
})
|
|
193
|
+
export class AppComponent implements OnInit {
|
|
194
|
+
constructor(@Inject(ANGULAR_WIDGET_RENDERER) private renderer: AngularWidgetRenderer) {}
|
|
195
|
+
|
|
196
|
+
ngOnInit() {
|
|
197
|
+
// Replace the built-in button component with your custom one
|
|
198
|
+
this.renderer.registerComponent('button', MyCustomButtonComponent);
|
|
199
|
+
|
|
200
|
+
// Or register multiple components at once
|
|
201
|
+
this.renderer.registerComponents({
|
|
202
|
+
button: MyCustomButtonComponent,
|
|
203
|
+
input: MyCustomInputComponent,
|
|
204
|
+
card: MyCustomCardComponent
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Built-in Widget Components
|
|
211
|
+
|
|
212
|
+
All built-in widgets are available as standalone Angular components:
|
|
213
|
+
|
|
214
|
+
```typescript
|
|
215
|
+
import {
|
|
216
|
+
ButtonWidgetComponent,
|
|
217
|
+
CardWidgetComponent,
|
|
218
|
+
FormWidgetComponent,
|
|
219
|
+
InputWidgetComponent,
|
|
220
|
+
// ... and more
|
|
221
|
+
} from '@bbq-chat/widgets-angular';
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
These components can be used directly in your templates if needed, though typically you'll use them through `WidgetRendererComponent`.
|
|
225
|
+
|
|
226
|
+
### Form Widget Dynamic Rendering
|
|
227
|
+
|
|
228
|
+
The `FormWidgetComponent` uses dynamic component rendering to render form fields. Instead of inline HTML, it dynamically instantiates the appropriate widget component (InputWidget, SliderWidget, etc.) for each field. This ensures consistency across all widgets and makes the form behavior automatically inherit any custom widget component replacements.
|
|
229
|
+
|
|
141
230
|
## Advanced Usage
|
|
142
231
|
|
|
143
232
|
### Handling Widget Actions
|