@trixwell/ngx-parl 4.3.0 → 5.0.1
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 +94 -12
- package/fesm2022/trixwell-ngx-parl.mjs +207 -23
- package/fesm2022/trixwell-ngx-parl.mjs.map +1 -1
- package/index.d.ts +61 -3
- package/package.json +4 -2
- package/src/assets/i18n/en.json +2 -0
- package/src/assets/i18n/uk.json +2 -0
- package/src/assets/icons/avatar_manager.svg +10 -5
package/README.md
CHANGED
|
@@ -68,18 +68,22 @@ assets/ngx-parl/...
|
|
|
68
68
|
|
|
69
69
|
## Signal Data
|
|
70
70
|
|
|
71
|
-
|
|
|
72
|
-
|
|
73
|
-
|
|
|
74
|
-
|
|
|
75
|
-
|
|
|
76
|
-
|
|
|
77
|
-
|
|
|
78
|
-
|
|
|
79
|
-
|
|
|
80
|
-
|
|
|
81
|
-
|
|
|
82
|
-
|
|
|
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 (e.g. outgoing avatar, layout) |
|
|
84
|
+
| quickActionsResolver | ParlQuickActionsResolver | Optional. Custom mapping; if omitted, `message.actions` uses `defaultParlQuickActionsResolver` |
|
|
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) |
|
|
83
87
|
|
|
84
88
|
## Scrolling to the Bottom
|
|
85
89
|
|
|
@@ -121,10 +125,17 @@ export interface ChatMessageDTO {
|
|
|
121
125
|
file_list?: File[] | [] | null;
|
|
122
126
|
checked?: boolean | null;
|
|
123
127
|
pending?: boolean;
|
|
128
|
+
actions?: ChatQuickButton[] | null;
|
|
124
129
|
}
|
|
125
130
|
|
|
126
131
|
export type ChatMessageType = 'incoming' | 'outgoing';
|
|
127
132
|
|
|
133
|
+
export interface ChatQuickButton {
|
|
134
|
+
id: number;
|
|
135
|
+
title: string;
|
|
136
|
+
value: string;
|
|
137
|
+
}
|
|
138
|
+
|
|
128
139
|
export interface MessageActionEvent {
|
|
129
140
|
action: MessageActionType;
|
|
130
141
|
chatMessageId?: number;
|
|
@@ -136,6 +147,74 @@ export interface MessageActionEvent {
|
|
|
136
147
|
}
|
|
137
148
|
```
|
|
138
149
|
|
|
150
|
+
## Quick actions
|
|
151
|
+
|
|
152
|
+
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).
|
|
153
|
+
|
|
154
|
+
- If you omit `[quickActionsResolver]`, the library uses `defaultParlQuickActionsResolver`, which maps `message.actions` to buttons.
|
|
155
|
+
- Provide a custom `[quickActionsResolver]` to filter, reorder, or replace actions; the context includes `isMobile` if you need different behavior per layout.
|
|
156
|
+
- `ChatQuickButton.title` is the button text; `ChatQuickButton.value` is the text that will be sent.
|
|
157
|
+
- Each action must include a stable `id`.
|
|
158
|
+
- `quickActionsAutoSend` defaults to `true` (clicking a quick action triggers `sendMessage()`).
|
|
159
|
+
|
|
160
|
+
### Types
|
|
161
|
+
|
|
162
|
+
```
|
|
163
|
+
export interface ParlQuickAction {
|
|
164
|
+
id: string;
|
|
165
|
+
title: string;
|
|
166
|
+
value: string;
|
|
167
|
+
disabled?: boolean;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export interface ParlQuickActionContext {
|
|
171
|
+
message: ChatMessage;
|
|
172
|
+
isMobile: boolean;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export interface ParlQuickActionClickEvent {
|
|
176
|
+
actionId: string;
|
|
177
|
+
messageId: number;
|
|
178
|
+
value: string;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export type ParlQuickActionsResolver = (context: ParlQuickActionContext) => ParlQuickAction[];
|
|
182
|
+
|
|
183
|
+
export function defaultParlQuickActionsResolver(context: ParlQuickActionContext): ParlQuickAction[];
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Example resolver
|
|
187
|
+
|
|
188
|
+
```
|
|
189
|
+
public quickActionsResolver: ParlQuickActionsResolver = ({ message }) => {
|
|
190
|
+
if (message.type !== 'outgoing') {
|
|
191
|
+
return [];
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const actions = message.actions ?? [];
|
|
195
|
+
return actions.map((a) => ({
|
|
196
|
+
id: String(a.id),
|
|
197
|
+
title: a.title, // button text
|
|
198
|
+
value: a.value, // sent text
|
|
199
|
+
}));
|
|
200
|
+
};
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## Mobile mode
|
|
204
|
+
|
|
205
|
+
Set `[mobileMode]="true"` to enable mobile UI behavior:
|
|
206
|
+
|
|
207
|
+
- Outgoing message avatars are hidden to save space.
|
|
208
|
+
- Quick actions use the default resolver from `message.actions` when `[quickActionsResolver]` is omitted, or your custom resolver when set (desktop and mobile).
|
|
209
|
+
- Quick actions are shown as a separate “buttons-only” outgoing message when the resolver returns actions for that message.
|
|
210
|
+
|
|
211
|
+
To use quick actions:
|
|
212
|
+
|
|
213
|
+
- Put `actions` on outgoing `ChatMessage` instances, and optionally omit `[quickActionsResolver]` to use the default mapping.
|
|
214
|
+
- Or provide `[quickActionsResolver]` for full control.
|
|
215
|
+
- Optionally bind `[(quickActionClick)]` to observe clicks (analytics/logging).
|
|
216
|
+
- Keep `[quickActionsAutoSend]="true"` to send `action.value` on click (default).
|
|
217
|
+
|
|
139
218
|
## Template
|
|
140
219
|
|
|
141
220
|
```
|
|
@@ -143,6 +222,9 @@ export interface MessageActionEvent {
|
|
|
143
222
|
[(messageList)]="messageList"
|
|
144
223
|
[(messageUpdate)]="messageUpdate"
|
|
145
224
|
[(messageAction)]="messageAction"
|
|
225
|
+
[quickActionsAutoSend]="true"
|
|
226
|
+
[mobileMode]="false"
|
|
227
|
+
[(quickActionClick)]="quickActionClick"
|
|
146
228
|
[transportType]="transportType()"
|
|
147
229
|
[transportTypeIcon]="transportTypeIcon()"
|
|
148
230
|
[(isScrolledToTop)]="isScrolledToTop">
|