@trixwell/ngx-parl 5.0.0 → 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 CHANGED
@@ -1,228 +1,235 @@
1
- # NgxParl Component Documentation
2
-
3
- ## Overview
4
-
5
- ![NgxParl Preview](https://raw.githubusercontent.com/Trixwell/parl/main/projects/ngx-parl/src/assets/img/chat_view.png)
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
- | mobileMode | boolean | Enables mobile UI behavior (layout + quick actions) |
84
- | quickActionsResolver | ParlQuickActionsResolver | Maps `ChatMessage` -> quick action buttons (mobile only) |
85
- | quickActionsAutoSend | boolean | Auto-send quick action text on click. Default `true` |
86
- | quickActionClick | ParlQuickActionClickEvent | Emits when a quick action is clicked (two-way bind) |
87
-
88
- ## Scrolling to the Bottom
89
-
90
- Scrolling to the latest message is handled internally via the scrollToBottomTrigger signal.
91
-
92
- To trigger scrolling programmatically, update the scrollToBottomTrigger value (for example, increment it). Each update triggers a scroll to the bottom.
93
-
94
- - use the scrollToBottom() to control scrolling down.
95
- - loadHistory is used only for loading older messages and does not control scrolling.
96
-
97
- ```
98
- this.scrollToBottomTrigger.update(value => value + 1);
99
- ```
100
-
101
- # Example Usage
102
-
103
- ## Component Setup
104
-
105
- ```
106
- public header = input<boolean>(true);
107
- public messageList = model<ChatMessage[]>([]);
108
- public messageUpdate = model<ChatMessage>();
109
- ```
110
-
111
- ## Entity
112
-
113
- ```
114
- export interface ChatMessageDTO {
115
- id: number;
116
- chat_id: number;
117
- cr_time: string; // ISO or 'YYYY-MM-DD HH:mm:ss'
118
- type: ChatMessageType;
119
- transport_type?: string | null;
120
- transport_type_icon?: string | null;
121
- user: string;
122
- content: string;
123
- avatar?: string | null;
124
- file_path?: string[] | [] | null;
125
- file_list?: File[] | [] | null;
126
- checked?: boolean | null;
127
- pending?: boolean;
128
- actions?: ChatQuickButton[] | null;
129
- }
130
-
131
- export type ChatMessageType = 'incoming' | 'outgoing';
132
-
133
- export interface ChatQuickButton {
134
- id: number;
135
- title: string;
136
- value: string;
137
- }
138
-
139
- export interface MessageActionEvent {
140
- action: MessageActionType;
141
- chatMessageId?: number;
142
- content: string;
143
- file_path?: string[];
144
- file_list?: File[];
145
- user_id?: number;
146
- user?: string;
147
- }
148
- ```
149
-
150
- ## Quick actions (mobile)
151
-
152
- If your `ChatMessage` contains `actions`, you can expose them as UI buttons (quick actions) using `[quickActionsResolver]`.
153
-
154
- - `ChatQuickButton.title` is the button text; `ChatQuickButton.value` is the text that will be sent.
155
- - Each action must include a stable `id`.
156
- - `quickActionsAutoSend` defaults to `true` (clicking a quick action triggers `sendMessage()`).
157
-
158
- ### Types
159
-
160
- ```
161
- export interface ParlQuickAction {
162
- id: string;
163
- title: string;
164
- value: string;
165
- disabled?: boolean;
166
- }
167
-
168
- export interface ParlQuickActionContext {
169
- message: ChatMessage;
170
- isMobile: boolean;
171
- }
172
-
173
- export interface ParlQuickActionClickEvent {
174
- actionId: string;
175
- messageId: number;
176
- value: string;
177
- }
178
-
179
- export type ParlQuickActionsResolver = (context: ParlQuickActionContext) => ParlQuickAction[];
180
- ```
181
-
182
- ### Example resolver
183
-
184
- ```
185
- public quickActionsResolver: ParlQuickActionsResolver = ({message, isMobile}) => {
186
- if (!isMobile || message.type !== 'outgoing') {
187
- return [];
188
- }
189
-
190
- const actions = message.actions ?? [];
191
- return actions.map((a) => ({
192
- id: String(a.id),
193
- title: a.title, // button text
194
- value: a.value, // sent text
195
- }));
196
- };
197
- ```
198
-
199
- ## Mobile mode
200
-
201
- Set `[mobileMode]="true"` to enable mobile UI behavior:
202
-
203
- - Outgoing message avatars are hidden to save space.
204
- - Quick actions are only resolved/rendered when `mobileMode` is enabled.
205
- - Quick actions are shown as a separate “buttons-only” outgoing message when your resolver returns actions for that message.
206
-
207
- To enable quick actions on mobile:
208
-
209
- - Provide `[quickActionsResolver]` that returns an array of actions for a given message.
210
- - Optionally bind `[(quickActionClick)]` to observe clicks (analytics/logging).
211
- - Keep `[quickActionsAutoSend]="true"` to send `action.value` on click (default).
212
-
213
- ## Template
214
-
215
- ```
216
- <ngx-parl [header]="header()"
217
- [(messageList)]="messageList"
218
- [(messageUpdate)]="messageUpdate"
219
- [(messageAction)]="messageAction"
220
- [quickActionsResolver]="quickActionsResolver"
221
- [quickActionsAutoSend]="true"
222
- [mobileMode]="true"
223
- [(quickActionClick)]="quickActionClick"
224
- [transportType]="transportType()"
225
- [transportTypeIcon]="transportTypeIcon()"
226
- [(isScrolledToTop)]="isScrolledToTop">
227
- </ngx-parl>
228
- ```
1
+ # NgxParl Component Documentation
2
+
3
+ ## Overview
4
+
5
+ ![NgxParl Preview](https://raw.githubusercontent.com/Trixwell/parl/main/projects/ngx-parl/src/assets/img/chat_view.png)
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
+ ```