@trixwell/ngx-parl 5.0.1 → 6.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 +235 -232
- package/fesm2022/trixwell-ngx-parl.mjs +131 -115
- package/fesm2022/trixwell-ngx-parl.mjs.map +1 -1
- package/package.json +16 -8
- package/{index.d.ts → types/trixwell-ngx-parl.d.ts} +6 -2
package/README.md
CHANGED
|
@@ -1,232 +1,235 @@
|
|
|
1
|
-
# NgxParl Component Documentation
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-

|
|
6
|
-
|
|
7
|
-
NgxParl is an Angular chat component that renders a fully interactive, customizable messaging interface. It supports features such as real-time message updates from external sources, sending and editing messages, deleting messages, day separators, and smooth auto-scrolling. The component is backend-agnostic, works with any data source, and integrates seamlessly with Angular Material, making it easy to plug into different projects as an open-source chat UI.
|
|
8
|
-
|
|
9
|
-
# GitHub Repository: [Trixwell/parl](https://github.com/Trixwell/parl)
|
|
10
|
-
|
|
11
|
-
## Installation
|
|
12
|
-
|
|
13
|
-
To use [NgxParl](https://www.npmjs.com/package/@trixwell/ngx-parl), ensure you have Angular and Angular Material installed. Then, import the component into your module:
|
|
14
|
-
|
|
15
|
-
```
|
|
16
|
-
npm install @trixwell/ngx-parl
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## Required peer dependencies:
|
|
20
|
-
|
|
21
|
-
```
|
|
22
|
-
npm install @angular/material
|
|
23
|
-
npm install @ngneat/transloco
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
In your app.module.ts:
|
|
27
|
-
|
|
28
|
-
```
|
|
29
|
-
import { NgxParl } from 'ngx-parl';
|
|
30
|
-
|
|
31
|
-
@NgModule({
|
|
32
|
-
declarations: [AppComponent],
|
|
33
|
-
imports: [NgxParl],
|
|
34
|
-
bootstrap: [AppComponent],
|
|
35
|
-
})
|
|
36
|
-
export class AppModule {}
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
Add the NgxParl providers to your application configuration:
|
|
40
|
-
|
|
41
|
-
```
|
|
42
|
-
export const appConfig: ApplicationConfig = {
|
|
43
|
-
providers: [provideNgxParl()]
|
|
44
|
-
}
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
Enables i18n, translations and core chat configuration
|
|
48
|
-
|
|
49
|
-
## Assets Setup
|
|
50
|
-
|
|
51
|
-
To enable media files (icons, images, etc.) used by @trixwell/ngx-parl, you must add the library’s assets path to your project’s angular.json:
|
|
52
|
-
|
|
53
|
-
```
|
|
54
|
-
"assets": [
|
|
55
|
-
{
|
|
56
|
-
"glob": "**/*",
|
|
57
|
-
"input": "node_modules/@trixwell/ngx-parl/src/assets",
|
|
58
|
-
"output": "assets/ngx-parl"
|
|
59
|
-
}
|
|
60
|
-
]
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
This makes the assets available at:
|
|
64
|
-
|
|
65
|
-
```
|
|
66
|
-
assets/ngx-parl/...
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
## Signal Data
|
|
70
|
-
|
|
71
|
-
| Name | Type |
|
|
72
|
-
|
|
73
|
-
| header | boolean |
|
|
74
|
-
| theme | string |
|
|
75
|
-
| language | string |
|
|
76
|
-
| messageList | ChatMessage[] |
|
|
77
|
-
| messageUpdate | ChatMessage |
|
|
78
|
-
| messageAction | MessageActionEvent |
|
|
79
|
-
| loadHistory | boolean |
|
|
80
|
-
| incomingUser | string |
|
|
81
|
-
| transportType | string |
|
|
82
|
-
| transportTypeIcon | string |
|
|
83
|
-
|
|
|
84
|
-
|
|
|
85
|
-
|
|
|
86
|
-
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
public
|
|
108
|
-
public
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
export
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
- `
|
|
157
|
-
-
|
|
158
|
-
- `
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
export
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
-
|
|
216
|
-
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
[(
|
|
225
|
-
[
|
|
226
|
-
[
|
|
227
|
-
[
|
|
228
|
-
[
|
|
229
|
-
[
|
|
230
|
-
[
|
|
231
|
-
|
|
232
|
-
|
|
1
|
+
# NgxParl Component Documentation
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
NgxParl is an Angular chat component that renders a fully interactive, customizable messaging interface. It supports features such as real-time message updates from external sources, sending and editing messages, deleting messages, day separators, and smooth auto-scrolling. The component is backend-agnostic, works with any data source, and integrates seamlessly with Angular Material, making it easy to plug into different projects as an open-source chat UI.
|
|
8
|
+
|
|
9
|
+
# GitHub Repository: [Trixwell/parl](https://github.com/Trixwell/parl)
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
To use [NgxParl](https://www.npmjs.com/package/@trixwell/ngx-parl), ensure you have Angular and Angular Material installed. Then, import the component into your module:
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
npm install @trixwell/ngx-parl
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Required peer dependencies:
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
npm install @angular/material
|
|
23
|
+
npm install @ngneat/transloco
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
In your app.module.ts:
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
import { NgxParl } from 'ngx-parl';
|
|
30
|
+
|
|
31
|
+
@NgModule({
|
|
32
|
+
declarations: [AppComponent],
|
|
33
|
+
imports: [NgxParl],
|
|
34
|
+
bootstrap: [AppComponent],
|
|
35
|
+
})
|
|
36
|
+
export class AppModule {}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Add the NgxParl providers to your application configuration:
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
export const appConfig: ApplicationConfig = {
|
|
43
|
+
providers: [provideNgxParl()]
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Enables i18n, translations and core chat configuration
|
|
48
|
+
|
|
49
|
+
## Assets Setup
|
|
50
|
+
|
|
51
|
+
To enable media files (icons, images, etc.) used by @trixwell/ngx-parl, you must add the library’s assets path to your project’s angular.json:
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
"assets": [
|
|
55
|
+
{
|
|
56
|
+
"glob": "**/*",
|
|
57
|
+
"input": "node_modules/@trixwell/ngx-parl/src/assets",
|
|
58
|
+
"output": "assets/ngx-parl"
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
This makes the assets available at:
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
assets/ngx-parl/...
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Signal Data
|
|
70
|
+
|
|
71
|
+
| Name | Type | Description |
|
|
72
|
+
|:--------------------:|:-------------------------:|:------------------------------------------------------------------------------------------------------------------:|
|
|
73
|
+
| header | boolean | Display the chat title with the name of the interlocutor |
|
|
74
|
+
| theme | string | Choose a theme color (```primary``` or ```secondary```) |
|
|
75
|
+
| language | string | Set language (```uk``` or ```en```). Default ```en``` |
|
|
76
|
+
| messageList | ChatMessage[] | List of chat messages, user information |
|
|
77
|
+
| messageUpdate | ChatMessage | Incoming message from external source (signal/subject/observable) |
|
|
78
|
+
| messageAction | MessageActionEvent | Emits chat events: send, edit, delete |
|
|
79
|
+
| loadHistory | boolean | Use scroll for load history |
|
|
80
|
+
| incomingUser | string | User writing in messenger |
|
|
81
|
+
| transportType | string | Transport type label (Telegram, etc.) |
|
|
82
|
+
| transportTypeIcon | string | Path to transport icon (e.g. assets/ngx-parl/...) |
|
|
83
|
+
| logoChat | string | Optional. Chat header and outgoing default avatar; use `[logoChat]="logoChat()"`. Defaults to the anonymous avatar |
|
|
84
|
+
| mobileMode | boolean | Enables mobile UI behavior (e.g. outgoing avatar, layout) |
|
|
85
|
+
| quickActionsResolver | ParlQuickActionsResolver | Optional. Custom mapping; if omitted, `message.actions` uses `defaultParlQuickActionsResolver` |
|
|
86
|
+
| quickActionsAutoSend | boolean | Auto-send quick action text on click. Default `true` |
|
|
87
|
+
| quickActionClick | ParlQuickActionClickEvent | Emits when a quick action is clicked (two-way bind) |
|
|
88
|
+
|
|
89
|
+
## Scrolling to the Bottom
|
|
90
|
+
|
|
91
|
+
Scrolling to the latest message is handled internally via the scrollToBottomTrigger signal.
|
|
92
|
+
|
|
93
|
+
To trigger scrolling programmatically, update the scrollToBottomTrigger value (for example, increment it). Each update triggers a scroll to the bottom.
|
|
94
|
+
|
|
95
|
+
- use the scrollToBottom() to control scrolling down.
|
|
96
|
+
- loadHistory is used only for loading older messages and does not control scrolling.
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
this.scrollToBottomTrigger.update(value => value + 1);
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
# Example Usage
|
|
103
|
+
|
|
104
|
+
## Component Setup
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
public header = input<boolean>(true);
|
|
108
|
+
public messageList = model<ChatMessage[]>([]);
|
|
109
|
+
public messageUpdate = model<ChatMessage>();
|
|
110
|
+
public logoChat = signal('');
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Entity
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
export interface ChatMessageDTO {
|
|
117
|
+
id: number;
|
|
118
|
+
chat_id: number;
|
|
119
|
+
cr_time: string; // ISO or 'YYYY-MM-DD HH:mm:ss'
|
|
120
|
+
type: ChatMessageType;
|
|
121
|
+
transport_type?: string | null;
|
|
122
|
+
transport_type_icon?: string | null;
|
|
123
|
+
user: string;
|
|
124
|
+
content: string;
|
|
125
|
+
avatar?: string | null;
|
|
126
|
+
file_path?: string[] | [] | null;
|
|
127
|
+
file_list?: File[] | [] | null;
|
|
128
|
+
checked?: boolean | null;
|
|
129
|
+
pending?: boolean;
|
|
130
|
+
actions?: ChatQuickButton[] | null;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export type ChatMessageType = 'incoming' | 'outgoing';
|
|
134
|
+
|
|
135
|
+
export interface ChatQuickButton {
|
|
136
|
+
id: number;
|
|
137
|
+
title: string;
|
|
138
|
+
value: string;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export interface MessageActionEvent {
|
|
142
|
+
action: MessageActionType;
|
|
143
|
+
chatMessageId?: number;
|
|
144
|
+
content: string;
|
|
145
|
+
file_path?: string[];
|
|
146
|
+
file_list?: File[];
|
|
147
|
+
user_id?: number;
|
|
148
|
+
user?: string;
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Quick actions
|
|
153
|
+
|
|
154
|
+
If your `ChatMessage` contains `actions`, they are shown as quick action buttons for **outgoing** messages in both desktop and mobile layouts (`mobileMode` does not hide them).
|
|
155
|
+
|
|
156
|
+
- If you omit `[quickActionsResolver]`, the library uses `defaultParlQuickActionsResolver`, which maps `message.actions` to buttons.
|
|
157
|
+
- Provide a custom `[quickActionsResolver]` to filter, reorder, or replace actions; the context includes `isMobile` if you need different behavior per layout.
|
|
158
|
+
- `ChatQuickButton.title` is the button text; `ChatQuickButton.value` is the text that will be sent.
|
|
159
|
+
- Each action must include a stable `id`.
|
|
160
|
+
- `quickActionsAutoSend` defaults to `true` (clicking a quick action triggers `sendMessage()`).
|
|
161
|
+
|
|
162
|
+
### Types
|
|
163
|
+
|
|
164
|
+
```
|
|
165
|
+
export interface ParlQuickAction {
|
|
166
|
+
id: string;
|
|
167
|
+
title: string;
|
|
168
|
+
value: string;
|
|
169
|
+
disabled?: boolean;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export interface ParlQuickActionContext {
|
|
173
|
+
message: ChatMessage;
|
|
174
|
+
isMobile: boolean;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export interface ParlQuickActionClickEvent {
|
|
178
|
+
actionId: string;
|
|
179
|
+
messageId: number;
|
|
180
|
+
value: string;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export type ParlQuickActionsResolver = (context: ParlQuickActionContext) => ParlQuickAction[];
|
|
184
|
+
|
|
185
|
+
export function defaultParlQuickActionsResolver(context: ParlQuickActionContext): ParlQuickAction[];
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### Example resolver
|
|
189
|
+
|
|
190
|
+
```
|
|
191
|
+
public quickActionsResolver: ParlQuickActionsResolver = ({ message }) => {
|
|
192
|
+
if (message.type !== 'outgoing') {
|
|
193
|
+
return [];
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const actions = message.actions ?? [];
|
|
197
|
+
return actions.map((a) => ({
|
|
198
|
+
id: String(a.id),
|
|
199
|
+
title: a.title, // button text
|
|
200
|
+
value: a.value, // sent text
|
|
201
|
+
}));
|
|
202
|
+
};
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## Mobile mode
|
|
206
|
+
|
|
207
|
+
Set `[mobileMode]="true"` to enable mobile UI behavior:
|
|
208
|
+
|
|
209
|
+
- Outgoing message avatars are hidden to save space.
|
|
210
|
+
- Quick actions use the default resolver from `message.actions` when `[quickActionsResolver]` is omitted, or your custom resolver when set (desktop and mobile).
|
|
211
|
+
- Quick actions are shown as a separate “buttons-only” outgoing message when the resolver returns actions for that message.
|
|
212
|
+
|
|
213
|
+
To use quick actions:
|
|
214
|
+
|
|
215
|
+
- Put `actions` on outgoing `ChatMessage` instances, and optionally omit `[quickActionsResolver]` to use the default mapping.
|
|
216
|
+
- Or provide `[quickActionsResolver]` for full control.
|
|
217
|
+
- Optionally bind `[(quickActionClick)]` to observe clicks (analytics/logging).
|
|
218
|
+
- Keep `[quickActionsAutoSend]="true"` to send `action.value` on click (default).
|
|
219
|
+
|
|
220
|
+
## Template
|
|
221
|
+
|
|
222
|
+
```
|
|
223
|
+
<ngx-parl [header]="header()"
|
|
224
|
+
[(messageList)]="messageList"
|
|
225
|
+
[(messageUpdate)]="messageUpdate"
|
|
226
|
+
[(messageAction)]="messageAction"
|
|
227
|
+
[quickActionsAutoSend]="true"
|
|
228
|
+
[mobileMode]="false"
|
|
229
|
+
[(quickActionClick)]="quickActionClick"
|
|
230
|
+
[transportType]="transportType()"
|
|
231
|
+
[transportTypeIcon]="transportTypeIcon()"
|
|
232
|
+
[(isScrolledToTop)]="isScrolledToTop"
|
|
233
|
+
[logoChat]="logoChat()">
|
|
234
|
+
</ngx-parl>
|
|
235
|
+
```
|