@trixwell/ngx-parl 4.3.0 → 5.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
@@ -68,18 +68,22 @@ assets/ngx-parl/...
68
68
 
69
69
  ## Signal Data
70
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/...) |
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) |
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,69 @@ export interface MessageActionEvent {
136
147
  }
137
148
  ```
138
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
+
139
213
  ## Template
140
214
 
141
215
  ```
@@ -143,6 +217,10 @@ export interface MessageActionEvent {
143
217
  [(messageList)]="messageList"
144
218
  [(messageUpdate)]="messageUpdate"
145
219
  [(messageAction)]="messageAction"
220
+ [quickActionsResolver]="quickActionsResolver"
221
+ [quickActionsAutoSend]="true"
222
+ [mobileMode]="true"
223
+ [(quickActionClick)]="quickActionClick"
146
224
  [transportType]="transportType()"
147
225
  [transportTypeIcon]="transportTypeIcon()"
148
226
  [(isScrolledToTop)]="isScrolledToTop">