@progress/kendo-react-conversational-ui 13.4.0-develop.2 → 13.4.0-develop.4
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/api/message.interface.d.ts +87 -9
- package/chat/ChatPropsAndState.d.ts +108 -9
- package/chat/Events.d.ts +9 -0
- package/chat/components/ActionGroup.js +1 -1
- package/chat/components/ActionGroup.mjs +58 -48
- package/chat/components/Chat.d.ts +1 -1
- package/chat/components/Chat.js +1 -1
- package/chat/components/Chat.mjs +318 -269
- package/chat/components/ChatContext.d.ts +6 -3
- package/chat/components/ChatMessage.js +1 -1
- package/chat/components/ChatMessage.mjs +237 -177
- package/chat/components/Header.js +1 -1
- package/chat/components/Header.mjs +3 -3
- package/chat/components/NewMessage.d.ts +5 -3
- package/chat/components/NewMessage.js +1 -1
- package/chat/components/NewMessage.mjs +174 -226
- package/chat/components/ScrollButtonsWrapper.js +1 -1
- package/chat/components/ScrollButtonsWrapper.mjs +34 -40
- package/chat/components/SuggestionsGroup.js +1 -1
- package/chat/components/SuggestionsGroup.mjs +40 -39
- package/chat/components/elements/FileBox.js +1 -1
- package/chat/components/elements/FileBox.mjs +33 -41
- package/chat/components/elements/PinnedMessage.js +1 -1
- package/chat/components/elements/PinnedMessage.mjs +24 -22
- package/chat/hooks/useScrollWithButtons.d.ts +4 -0
- package/chat/hooks/useScrollWithButtons.js +1 -1
- package/chat/hooks/useScrollWithButtons.mjs +25 -23
- package/chat/utils/fieldMapping.d.ts +1 -1
- package/chat/utils/fieldMapping.js +1 -1
- package/chat/utils/fieldMapping.mjs +37 -34
- package/chat/utils/scroll.d.ts +15 -1
- package/chat/utils/scroll.js +3 -3
- package/chat/utils/scroll.mjs +92 -65
- package/chat/utils.d.ts +4 -1
- package/chat/utils.js +1 -1
- package/chat/utils.mjs +37 -37
- package/dist/cdn/js/kendo-react-conversational-ui.js +1 -1
- package/index.d.mts +6 -0
- package/index.d.ts +6 -0
- package/index.js +1 -1
- package/index.mjs +39 -31
- package/messages/index.d.ts +50 -0
- package/messages/index.js +1 -1
- package/messages/index.mjs +60 -40
- package/package-metadata.js +1 -1
- package/package-metadata.mjs +1 -1
- package/package.json +11 -11
- package/prompt-box/Events.d.ts +66 -0
- package/prompt-box/FileBox.d.ts +22 -0
- package/prompt-box/FileBox.js +8 -0
- package/prompt-box/FileBox.mjs +72 -0
- package/prompt-box/PromptBox.d.ts +35 -0
- package/prompt-box/PromptBox.js +8 -0
- package/prompt-box/PromptBox.mjs +424 -0
- package/prompt-box/PromptBoxActionButton.d.ts +32 -0
- package/prompt-box/PromptBoxActionButton.js +8 -0
- package/prompt-box/PromptBoxActionButton.mjs +14 -0
- package/prompt-box/PromptBoxSpeechToTextButton.d.ts +32 -0
- package/prompt-box/PromptBoxSpeechToTextButton.js +8 -0
- package/prompt-box/PromptBoxSpeechToTextButton.mjs +14 -0
- package/prompt-box/PromptBoxUploadButton.d.ts +108 -0
- package/prompt-box/PromptBoxUploadButton.js +8 -0
- package/prompt-box/PromptBoxUploadButton.mjs +54 -0
- package/prompt-box/interfaces/PromptBoxProps.d.ts +390 -0
|
@@ -5,9 +5,50 @@
|
|
|
5
5
|
* Licensed under commercial license. See LICENSE.md in the package root for more information
|
|
6
6
|
*-------------------------------------------------------------------------------------------
|
|
7
7
|
*/
|
|
8
|
+
import { SVGIcon } from '@progress/kendo-react-common';
|
|
8
9
|
import { Action } from './action.interface.js';
|
|
9
10
|
import { Attachment, AttachmentLayout } from './attachment.interface.js';
|
|
10
11
|
import { User } from './user.interface.js';
|
|
12
|
+
/**
|
|
13
|
+
* Configuration for message status display with optional icon.
|
|
14
|
+
*/
|
|
15
|
+
export interface MessageStatus {
|
|
16
|
+
/**
|
|
17
|
+
* Sets the text for the message status.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```tsx
|
|
21
|
+
* const message: Message = {
|
|
22
|
+
* status: { text: 'Seen' }
|
|
23
|
+
* };
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
text?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Sets the name of a font icon from the Kendo UI theme for the message status.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```tsx
|
|
32
|
+
* const message: Message = {
|
|
33
|
+
* status: { text: 'Seen', icon: 'k-icon k-font-icon k-i-loading' }
|
|
34
|
+
* };
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
icon?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Sets an SVG icon to display inside the message status.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```tsx
|
|
43
|
+
* import { eyeIcon } from '@progress/kendo-svg-icons';
|
|
44
|
+
*
|
|
45
|
+
* const message: Message = {
|
|
46
|
+
* status: { text: 'Seen', svgIcon: eyeIcon }
|
|
47
|
+
* };
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
svgIcon?: SVGIcon;
|
|
51
|
+
}
|
|
11
52
|
/**
|
|
12
53
|
* Represents a Chat message.
|
|
13
54
|
*
|
|
@@ -39,10 +80,35 @@ export interface Message {
|
|
|
39
80
|
*/
|
|
40
81
|
suggestedActions?: Action[];
|
|
41
82
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
|
|
45
|
-
|
|
83
|
+
* Sets the current status of the message.
|
|
84
|
+
* The status appears when the message is selected by clicking or through keyboard navigation.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```tsx
|
|
88
|
+
* const message: Message = {
|
|
89
|
+
* id: 1,
|
|
90
|
+
* author: user,
|
|
91
|
+
* text: 'Hello',
|
|
92
|
+
* status: 'Seen'
|
|
93
|
+
* };
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```tsx
|
|
98
|
+
* import { eyeIcon } from '@progress/kendo-svg-icons';
|
|
99
|
+
*
|
|
100
|
+
* const message: Message = {
|
|
101
|
+
* id: 1,
|
|
102
|
+
* author: user,
|
|
103
|
+
* text: 'Hello',
|
|
104
|
+
* status: {
|
|
105
|
+
* text: 'Seen',
|
|
106
|
+
* svgIcon: eyeIcon
|
|
107
|
+
* }
|
|
108
|
+
* };
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
status?: string | MessageStatus;
|
|
46
112
|
/**
|
|
47
113
|
* Optional text for the message.
|
|
48
114
|
* Some messages contain only attachments or quick actions.
|
|
@@ -57,11 +123,6 @@ export interface Message {
|
|
|
57
123
|
* If `true`, the Chat displays a typing indicator instead of the message.
|
|
58
124
|
*/
|
|
59
125
|
typing?: boolean;
|
|
60
|
-
/**
|
|
61
|
-
* Indicates if the message is loading.
|
|
62
|
-
* If `true`, the Chat displays a skeleton placeholder instead of the content.
|
|
63
|
-
*/
|
|
64
|
-
isLoading?: boolean;
|
|
65
126
|
/**
|
|
66
127
|
* Indicates if the message is pinned.
|
|
67
128
|
*/
|
|
@@ -90,6 +151,23 @@ export interface Message {
|
|
|
90
151
|
* Index used for keyboard selection navigation.
|
|
91
152
|
*/
|
|
92
153
|
selectionIndex?: number;
|
|
154
|
+
/**
|
|
155
|
+
* Indicates whether the message has failed to send.
|
|
156
|
+
* When `true`, renders a retry button that fires the `onResendMessage` event.
|
|
157
|
+
*
|
|
158
|
+
* @default false
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```tsx
|
|
162
|
+
* const message: Message = {
|
|
163
|
+
* id: 1,
|
|
164
|
+
* author: user,
|
|
165
|
+
* text: 'Hello',
|
|
166
|
+
* isFailed: true
|
|
167
|
+
* };
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
isFailed?: boolean;
|
|
93
171
|
/**
|
|
94
172
|
* @hidden
|
|
95
173
|
* Original data item containing all the raw fields from the source message.
|
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
* Licensed under commercial license. See LICENSE.md in the package root for more information
|
|
6
6
|
*-------------------------------------------------------------------------------------------
|
|
7
7
|
*/
|
|
8
|
-
import { Message, ChatActionExecuteEvent, ChatSendMessageEvent } from '../index.js';
|
|
8
|
+
import { Message, ChatActionExecuteEvent, ChatSendMessageEvent, ChatResendMessageEvent, PromptBoxMode } from '../index.js';
|
|
9
9
|
import { ChatMessageProps, ChatMessageTemplateProps, FileAction, MessageAction } from './components/ChatMessage.js';
|
|
10
10
|
import { ChatSuggestion, SuggestionTemplateProps } from './components/SuggestionsGroup.js';
|
|
11
11
|
import { ButtonProps, SpeechToTextButtonProps } from '@progress/kendo-react-buttons';
|
|
12
|
-
import {
|
|
12
|
+
import { UploadButtonProps } from '../prompt-box/interfaces/PromptBoxProps.js';
|
|
13
13
|
import { DateMarker } from './ViewItem.js';
|
|
14
14
|
/**
|
|
15
15
|
* Represents the properties available to the `statusTemplate` custom component.
|
|
@@ -127,6 +127,13 @@ export interface FieldMappingConfig {
|
|
|
127
127
|
* @default 'suggestedActions'
|
|
128
128
|
*/
|
|
129
129
|
suggestedActionsField?: string;
|
|
130
|
+
/**
|
|
131
|
+
* Field name for message failed status.
|
|
132
|
+
* Indicates whether the message has failed to send.
|
|
133
|
+
*
|
|
134
|
+
* @default 'isFailed'
|
|
135
|
+
*/
|
|
136
|
+
isFailedField?: string;
|
|
130
137
|
}
|
|
131
138
|
/**
|
|
132
139
|
* Represents a file attachment in a Chat message.
|
|
@@ -161,10 +168,6 @@ export interface ChatMessageBoxProps {
|
|
|
161
168
|
* Input message element of the Chat.
|
|
162
169
|
*/
|
|
163
170
|
messageInput: React.ReactElement;
|
|
164
|
-
/**
|
|
165
|
-
* Send button element of the Chat.
|
|
166
|
-
*/
|
|
167
|
-
sendButton: React.ReactElement;
|
|
168
171
|
}
|
|
169
172
|
/**
|
|
170
173
|
* Controls how suggestions behave when they exceed available space.
|
|
@@ -199,6 +202,49 @@ export type MessageWidthMode = 'full' | 'standard';
|
|
|
199
202
|
* - `hidden`—Timestamps are never visible for any messages.
|
|
200
203
|
*/
|
|
201
204
|
export type TimestampVisibilityMode = 'onFocus' | 'hidden';
|
|
205
|
+
/**
|
|
206
|
+
* Configuration for the Message Box (PromptBox component).
|
|
207
|
+
*/
|
|
208
|
+
export interface MessageBoxSettings {
|
|
209
|
+
/**
|
|
210
|
+
* Defines the line mode for the Message Box.
|
|
211
|
+
* - `single`—Single-line input field.
|
|
212
|
+
* - `multi`—Multi-line textarea that expands/collapses based on content.
|
|
213
|
+
* - `auto`—Starts as single-line and automatically expands to multi-line when needed.
|
|
214
|
+
*
|
|
215
|
+
* @default 'multi'
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* ```tsx
|
|
219
|
+
* <Chat messageBoxSettings={{ mode: 'auto' }} />
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
mode?: PromptBoxMode;
|
|
223
|
+
/**
|
|
224
|
+
* Sets the number of visible rows for the Message Box textarea.
|
|
225
|
+
*
|
|
226
|
+
* @default 2
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```tsx
|
|
230
|
+
* <Chat messageBoxSettings={{ rows: 5 }} />
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
rows?: number;
|
|
234
|
+
/**
|
|
235
|
+
* Sets the maximum height of the Message Box textarea in px.
|
|
236
|
+
* When the height exceeds this value, the Message Box height is fixed and a scrollbar appears.
|
|
237
|
+
* Applicable for `multi` and `auto` modes.
|
|
238
|
+
*
|
|
239
|
+
* @default '110'
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* ```tsx
|
|
243
|
+
* <Chat messageBoxSettings={{ maxTextAreaHeight: '300' }} />
|
|
244
|
+
* ```
|
|
245
|
+
*/
|
|
246
|
+
maxTextAreaHeight?: string;
|
|
247
|
+
}
|
|
202
248
|
/**
|
|
203
249
|
* Configuration settings for message display and behavior.
|
|
204
250
|
*/
|
|
@@ -365,6 +411,18 @@ export interface ChatProps extends FieldMappingConfig {
|
|
|
365
411
|
* Only renders when there are no messages and this template is provided.
|
|
366
412
|
*/
|
|
367
413
|
noDataTemplate?: React.ReactElement | (() => React.ReactElement);
|
|
414
|
+
/**
|
|
415
|
+
* Enables or disables the scroll-to-bottom button that appears when the user scrolls up.
|
|
416
|
+
* When enabled, a floating action button appears to allow quick navigation to the latest messages.
|
|
417
|
+
*
|
|
418
|
+
* @default true
|
|
419
|
+
*
|
|
420
|
+
* @example
|
|
421
|
+
* ```tsx
|
|
422
|
+
* <Chat scrollToBottomButton={false} />
|
|
423
|
+
* ```
|
|
424
|
+
*/
|
|
425
|
+
scrollToBottomButton?: boolean;
|
|
368
426
|
/**
|
|
369
427
|
* Template for the timestamp of the message.
|
|
370
428
|
*/
|
|
@@ -460,11 +518,11 @@ export interface ChatProps extends FieldMappingConfig {
|
|
|
460
518
|
* Sets the upload configuration for the Chat component.
|
|
461
519
|
* This can be used to customize the file upload behavior, such as accepted file types and maximum file size.
|
|
462
520
|
*/
|
|
463
|
-
uploadConfig?: boolean |
|
|
521
|
+
uploadConfig?: boolean | UploadButtonProps;
|
|
464
522
|
/**
|
|
465
523
|
* Configures the appearance and behavior of the send button in the Chat component.
|
|
466
524
|
*/
|
|
467
|
-
sendButtonConfig?: ButtonProps;
|
|
525
|
+
sendButtonConfig?: boolean | ButtonProps;
|
|
468
526
|
/**
|
|
469
527
|
* Fires when a toolbar action is executed on a message. Provides the action and target message.
|
|
470
528
|
*/
|
|
@@ -486,9 +544,50 @@ export interface ChatProps extends FieldMappingConfig {
|
|
|
486
544
|
*/
|
|
487
545
|
onInputValueChange?: (value: string) => void;
|
|
488
546
|
/**
|
|
489
|
-
*
|
|
547
|
+
* Sets the controlled input value of the Chat component.
|
|
548
|
+
* When provided, the Chat operates in controlled mode and you must handle `onInputValueChange` to update the value.
|
|
549
|
+
*
|
|
550
|
+
* @example
|
|
551
|
+
* ```tsx
|
|
552
|
+
* const [inputValue, setInputValue] = useState('');
|
|
553
|
+
* <Chat inputValue={inputValue} onInputValueChange={setInputValue} />
|
|
554
|
+
* ```
|
|
490
555
|
*/
|
|
491
556
|
inputValue?: string;
|
|
557
|
+
/**
|
|
558
|
+
* Fires when the user clicks the Retry button on a failed message.
|
|
559
|
+
* Emits [`ChatResendMessageEvent`](https://www.telerik.com/kendo-react-ui/components/conversational-ui/api/chatresendmessageevent).
|
|
560
|
+
*
|
|
561
|
+
* @example
|
|
562
|
+
* ```tsx
|
|
563
|
+
* const handleResend = (event: ChatResendMessageEvent) => {
|
|
564
|
+
* console.log('Resending message:', event.message);
|
|
565
|
+
* // Implement retry logic
|
|
566
|
+
* };
|
|
567
|
+
* <Chat onResendMessage={handleResend} />
|
|
568
|
+
* ```
|
|
569
|
+
*/
|
|
570
|
+
onResendMessage?: (event: ChatResendMessageEvent) => void;
|
|
571
|
+
/**
|
|
572
|
+
* Configuration for the Message Box (PromptBox component).
|
|
573
|
+
*
|
|
574
|
+
* @example
|
|
575
|
+
* ```tsx
|
|
576
|
+
* <Chat messageBoxSettings={{ rows: 5, maxTextAreaHeight: '300' }} />
|
|
577
|
+
* ```
|
|
578
|
+
*/
|
|
579
|
+
messageBoxSettings?: MessageBoxSettings;
|
|
580
|
+
/**
|
|
581
|
+
* Specifies whether the Send button is transformed to a stop button.
|
|
582
|
+
*
|
|
583
|
+
* @default false
|
|
584
|
+
*
|
|
585
|
+
* @example
|
|
586
|
+
* ```tsx
|
|
587
|
+
* <Chat loading={true} />
|
|
588
|
+
* ```
|
|
589
|
+
*/
|
|
590
|
+
loading?: boolean;
|
|
492
591
|
}
|
|
493
592
|
/**
|
|
494
593
|
* @hidden
|
package/chat/Events.d.ts
CHANGED
|
@@ -39,6 +39,15 @@ export interface ChatSendMessageEvent extends BaseEvent<React.Component> {
|
|
|
39
39
|
*/
|
|
40
40
|
message: Message;
|
|
41
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Arguments for the `onResendMessage` event of the Chat.
|
|
44
|
+
*/
|
|
45
|
+
export interface ChatResendMessageEvent extends BaseEvent<React.Component> {
|
|
46
|
+
/**
|
|
47
|
+
* The message that will be resent.
|
|
48
|
+
*/
|
|
49
|
+
message: Message;
|
|
50
|
+
}
|
|
42
51
|
/**
|
|
43
52
|
* Arguments for the `toolbaractionexecute` event of the Chat.
|
|
44
53
|
*/
|
|
@@ -5,4 +5,4 @@
|
|
|
5
5
|
* Licensed under commercial license. See LICENSE.md in the package root for more information
|
|
6
6
|
*-------------------------------------------------------------------------------------------
|
|
7
7
|
*/
|
|
8
|
-
"use strict";const
|
|
8
|
+
"use strict";const K=require("react"),p=require("@progress/kendo-react-common"),I=require("./Action.js"),L=require("./ScrollButtonsWrapper.js"),N=require("../hooks/useScrollWithButtons.js");function O(r){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const a in r)if(a!=="default"){const u=Object.getOwnPropertyDescriptor(r,a);Object.defineProperty(t,a,u.get?u:{enumerable:!0,get:()=>r[a]})}}return t.default=r,Object.freeze(t)}const e=O(K),W=r=>{var y,C;const{group:t,onActionExecute:a,selected:u,onRequestSelection:b,quickActionsLayout:l="scroll",dir:m}=r,[o,i]=e.useState(null),k=e.useRef(null),{canScrollLeft:d,canScrollRight:f,scrollLeft:R,scrollRight:x}=N.useScrollWithButtons(k,{enabled:l==="scrollbuttons"||l==="scroll",dir:m,mode:l,itemsDependency:t.actions});e.useEffect(()=>{!u&&o!==null?i(null):u&&o===null&&i(0)},[u,o]);const S=e.useCallback(()=>t.actions?t.actions.length-1:-1,[t.actions]),g=e.useCallback((n,s=0)=>{let c=null;return n?o===null?c=s:o<S()&&(c=o+1):o===null?c=0:o>0&&(c=o-1),c!==null&&i(c),c},[o,S]),q=e.useCallback(()=>{b(t.selectionIndex)},[b,t.selectionIndex]),h=e.useCallback(n=>{let s=null;const c=p.Keys.left,D=p.Keys.right;n.keyCode===c?s=g(!1):n.keyCode===D&&(s=g(!0)),s!==null&&(n.preventDefault(),n.stopPropagation())},[g]),E=e.useCallback(()=>p.classNames("k-suggestion-group",{"k-suggestion-group-scrollable":l==="scroll","k-suggestion-group-scrollable-start":f&&(l==="scroll"||l==="scrollbuttons"),"k-suggestion-group-scrollable-end":d&&(l==="scroll"||l==="scrollbuttons")}),[l,f,d]),v=l==="scroll"||l==="scrollbuttons",A=e.createElement("div",{className:E(),onClick:q,onKeyDown:h,role:"toolbar",tabIndex:0,"aria-label":"Action group"},v?e.createElement("div",{className:"k-suggestions-scroll",ref:k},(y=t.actions)==null?void 0:y.map((n,s)=>e.createElement(I,{item:n,onActionExecute:a,selected:s===o,key:n.value}))):(C=t.actions)==null?void 0:C.map((n,s)=>e.createElement(I,{item:n,onActionExecute:a,selected:s===o,key:n.value})));return e.createElement(L.ScrollButtonsWrapper,{visible:l==="scrollbuttons",dir:m,canScrollLeft:d,canScrollRight:f,onScrollLeft:R,onScrollRight:x},A)};module.exports=W;
|
|
@@ -5,73 +5,83 @@
|
|
|
5
5
|
* Licensed under commercial license. See LICENSE.md in the package root for more information
|
|
6
6
|
*-------------------------------------------------------------------------------------------
|
|
7
7
|
*/
|
|
8
|
-
import * as
|
|
9
|
-
import { Keys as
|
|
10
|
-
import
|
|
8
|
+
import * as e from "react";
|
|
9
|
+
import { Keys as S, classNames as N } from "@progress/kendo-react-common";
|
|
10
|
+
import y from "./Action.mjs";
|
|
11
11
|
import { ScrollButtonsWrapper as q } from "./ScrollButtonsWrapper.mjs";
|
|
12
|
-
import { useScrollWithButtons as
|
|
13
|
-
const
|
|
14
|
-
var
|
|
15
|
-
const { group:
|
|
16
|
-
enabled:
|
|
17
|
-
dir:
|
|
18
|
-
|
|
12
|
+
import { useScrollWithButtons as D } from "../hooks/useScrollWithButtons.mjs";
|
|
13
|
+
const P = (I) => {
|
|
14
|
+
var k, C;
|
|
15
|
+
const { group: c, onActionExecute: d, selected: r, onRequestSelection: m, quickActionsLayout: l = "scroll", dir: g } = I, [t, a] = e.useState(null), p = e.useRef(null), { canScrollLeft: i, canScrollRight: u, scrollLeft: x, scrollRight: R } = D(p, {
|
|
16
|
+
enabled: l === "scrollbuttons" || l === "scroll",
|
|
17
|
+
dir: g,
|
|
18
|
+
mode: l,
|
|
19
|
+
itemsDependency: c.actions
|
|
19
20
|
});
|
|
20
|
-
|
|
21
|
-
!r &&
|
|
22
|
-
}, [r,
|
|
23
|
-
const
|
|
24
|
-
(
|
|
25
|
-
let
|
|
26
|
-
return
|
|
21
|
+
e.useEffect(() => {
|
|
22
|
+
!r && t !== null ? a(null) : r && t === null && a(0);
|
|
23
|
+
}, [r, t]);
|
|
24
|
+
const b = e.useCallback(() => c.actions ? c.actions.length - 1 : -1, [c.actions]), f = e.useCallback(
|
|
25
|
+
(o, s = 0) => {
|
|
26
|
+
let n = null;
|
|
27
|
+
return o ? t === null ? n = s : t < b() && (n = t + 1) : t === null ? n = 0 : t > 0 && (n = t - 1), n !== null && a(n), n;
|
|
27
28
|
},
|
|
28
|
-
[
|
|
29
|
-
),
|
|
30
|
-
|
|
31
|
-
}, [
|
|
32
|
-
(
|
|
29
|
+
[t, b]
|
|
30
|
+
), E = e.useCallback(() => {
|
|
31
|
+
m(c.selectionIndex);
|
|
32
|
+
}, [m, c.selectionIndex]), h = e.useCallback(
|
|
33
|
+
(o) => {
|
|
33
34
|
let s = null;
|
|
34
|
-
const
|
|
35
|
-
|
|
35
|
+
const n = S.left, K = S.right;
|
|
36
|
+
o.keyCode === n ? s = f(!1) : o.keyCode === K && (s = f(!0)), s !== null && (o.preventDefault(), o.stopPropagation());
|
|
36
37
|
},
|
|
37
|
-
[
|
|
38
|
-
),
|
|
38
|
+
[f]
|
|
39
|
+
), A = e.useCallback(() => N("k-suggestion-group", {
|
|
39
40
|
// Apply scrollable class only when layout is 'scroll' (no scroll buttons)
|
|
40
|
-
"k-suggestion-group-scrollable":
|
|
41
|
-
|
|
41
|
+
"k-suggestion-group-scrollable": l === "scroll",
|
|
42
|
+
"k-suggestion-group-scrollable-start": u && (l === "scroll" || l === "scrollbuttons"),
|
|
43
|
+
"k-suggestion-group-scrollable-end": i && (l === "scroll" || l === "scrollbuttons")
|
|
44
|
+
}), [l, u, i]), L = l === "scroll" || l === "scrollbuttons", v = /* @__PURE__ */ e.createElement(
|
|
42
45
|
"div",
|
|
43
46
|
{
|
|
44
|
-
className:
|
|
45
|
-
onClick:
|
|
46
|
-
onKeyDown:
|
|
47
|
+
className: A(),
|
|
48
|
+
onClick: E,
|
|
49
|
+
onKeyDown: h,
|
|
47
50
|
role: "toolbar",
|
|
48
51
|
tabIndex: 0,
|
|
49
|
-
"aria-label": "Action group"
|
|
50
|
-
ref: c === "scrollbuttons" ? d : void 0
|
|
52
|
+
"aria-label": "Action group"
|
|
51
53
|
},
|
|
52
|
-
(p =
|
|
53
|
-
|
|
54
|
+
L ? /* @__PURE__ */ e.createElement("div", { className: "k-suggestions-scroll", ref: p }, (k = c.actions) == null ? void 0 : k.map((o, s) => /* @__PURE__ */ e.createElement(
|
|
55
|
+
y,
|
|
54
56
|
{
|
|
55
|
-
item:
|
|
56
|
-
onActionExecute:
|
|
57
|
-
selected: s ===
|
|
58
|
-
key:
|
|
57
|
+
item: o,
|
|
58
|
+
onActionExecute: d,
|
|
59
|
+
selected: s === t,
|
|
60
|
+
key: o.value
|
|
61
|
+
}
|
|
62
|
+
))) : (C = c.actions) == null ? void 0 : C.map((o, s) => /* @__PURE__ */ e.createElement(
|
|
63
|
+
y,
|
|
64
|
+
{
|
|
65
|
+
item: o,
|
|
66
|
+
onActionExecute: d,
|
|
67
|
+
selected: s === t,
|
|
68
|
+
key: o.value
|
|
59
69
|
}
|
|
60
70
|
))
|
|
61
71
|
);
|
|
62
|
-
return /* @__PURE__ */
|
|
72
|
+
return /* @__PURE__ */ e.createElement(
|
|
63
73
|
q,
|
|
64
74
|
{
|
|
65
|
-
visible:
|
|
66
|
-
dir:
|
|
67
|
-
canScrollLeft:
|
|
68
|
-
canScrollRight:
|
|
69
|
-
onScrollLeft:
|
|
70
|
-
onScrollRight:
|
|
75
|
+
visible: l === "scrollbuttons",
|
|
76
|
+
dir: g,
|
|
77
|
+
canScrollLeft: i,
|
|
78
|
+
canScrollRight: u,
|
|
79
|
+
onScrollLeft: x,
|
|
80
|
+
onScrollRight: R
|
|
71
81
|
},
|
|
72
|
-
|
|
82
|
+
v
|
|
73
83
|
);
|
|
74
84
|
};
|
|
75
85
|
export {
|
|
76
|
-
|
|
86
|
+
P as default
|
|
77
87
|
};
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Licensed under commercial license. See LICENSE.md in the package root for more information
|
|
6
6
|
*-------------------------------------------------------------------------------------------
|
|
7
7
|
*/
|
|
8
|
-
import { ChatProps } from '
|
|
8
|
+
import { ChatProps } from '../ChatPropsAndState.js';
|
|
9
9
|
import * as React from 'react';
|
|
10
10
|
/**
|
|
11
11
|
* Represents the [KendoReact Chat component](https://www.telerik.com/kendo-react-ui/components/conversational-ui).
|
package/chat/components/Chat.js
CHANGED
|
@@ -5,4 +5,4 @@
|
|
|
5
5
|
* Licensed under commercial license. See LICENSE.md in the package root for more information
|
|
6
6
|
*-------------------------------------------------------------------------------------------
|
|
7
7
|
*/
|
|
8
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
8
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("@progress/kendo-react-common"),n=require("prop-types"),pt=require("react"),ft=require("@progress/kendo-react-buttons"),ht=require("@progress/kendo-svg-icons"),yt=require("../ViewItem.js"),Tt=require("./ActionGroup.js"),Ct=require("./AttachmentGroup.js"),St=require("./DateMarker.js"),Mt=require("./MessageGroup.js"),kt=require("./NewMessage.js"),bt=require("./Header.js"),Et=require("./elements/PinnedMessage.js"),wt=require("./Notification.js"),vt=require("./ChatContext.js"),xt=require("./ChatMessage.js"),De=require("../../package-metadata.js"),l=require("../../messages/index.js"),Rt=require("@progress/kendo-react-intl"),Oe=require("../utils/fieldMapping.js"),je=require("../utils/scroll.js"),At=require("../utils/messageSettings.js");function qt(d){const m=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(d){for(const i in d)if(i!=="default"){const M=Object.getOwnPropertyDescriptor(d,i);Object.defineProperty(m,i,M.get?M:{enumerable:!0,get:()=>d[i]})}}return m.default=d,Object.freeze(m)}const e=qt(pt),D=e.forwardRef((d,m)=>{const{messages:i=[],messageTemplate:M,messageContentTemplate:O,attachmentTemplate:v,width:Pe,height:Ue,onSendMessage:k,onSuggestionClick:j,onInputValueChange:P,onActionExecute:x,dir:T,messageBox:Ve,placeholder:He,className:U,style:Ke,message:V=xt.ChatMessage,authorId:u,suggestions:H,suggestionTemplate:We,suggestionsLayout:ze="scroll",quickActionsLayout:K="scroll",inputValue:Ge,headerTemplate:C,noDataTemplate:S,timestampTemplate:W,statusTemplate:z,userStatusTemplate:G,allowMessageCollapse:_,messageToolbarActions:$,messageContextMenuActions:J,fileActions:b,onUnpin:_e,messageWidthMode:Q,showAvatar:X,showUsername:Y,timestampVisibility:Z,authorMessageSettings:ee,receiverMessageSettings:te,onToolbarAction:se,onContextMenuAction:ne,onFileAction:oe,onDownload:ae,speechToTextConfig:re,uploadConfig:le,sendButtonConfig:$e,messageFilesLayout:ie,scrollToBottomButton:R=!0,textField:ce,statusField:ue,authorIdField:ge,authorNameField:me,authorImageUrlField:de,authorImageAltTextField:pe,idField:fe,timestampField:he,filesField:ye,attachmentsField:Te,replyToIdField:Ce,isDeletedField:Se,isPinnedField:Me,typingField:ke,suggestedActionsField:be,isFailedField:Ee,onResendMessage:we,messageBoxSettings:Je,loading:Qe,...Xe}=d,[p,A]=e.useState(null),[q,Ye]=e.useState(!1),[Ze,ve]=e.useState(!1),[xe,Re]=e.useState(null),[f,Ae]=e.useState(null),[et,qe]=e.useState(!1),F=e.useRef(null),Fe=e.useRef(null),r=e.useRef(null),Le=e.useRef(null),L=e.useRef(void 0),I=e.useRef(!1),N=e.useRef(null),Ie=e.useRef(""),a=e.useMemo(()=>{if(!i||i.length===0)return[];const s={textField:ce,statusField:ue,authorIdField:ge,authorNameField:me,authorImageUrlField:de,authorImageAltTextField:pe,idField:fe,timestampField:he,filesField:ye,attachmentsField:Te,replyToIdField:Ce,isDeletedField:Se,isPinnedField:Me,typingField:ke,suggestedActionsField:be,isFailedField:Ee};return!Object.values(s).some(o=>o!==void 0)&&Oe.isStandardMessageFormat(i[0])?i.map(o=>({...o,timestamp:o.timestamp?new Date(o.timestamp):o.timestamp})):Oe.mapDataArrayToMessages(i,s)},[i,ce,ue,ge,me,de,pe,fe,he,ye,Te,Ce,Se,Me,ke,be,Ee]);e.useEffect(()=>{if(u===Ie.current&&N.current){Ae(N.current);return}if(u&&a.length>0){const s=a.find(o=>o.author&&(o.author.id===u||o.author.id===String(u))),t=(s==null?void 0:s.author)||{id:u};N.current=t,Ie.current=u,Ae(t)}},[u,a]);const h=e.useMemo(()=>a.length>0?yt.convertMsgsToViewItems(a):[],[a]),tt=e.useMemo(()=>!g.validatePackage(De.packageMetadata,{component:"Chat"}),[]),st=g.getLicenseMessage(De.packageMetadata),Ne=e.useMemo(()=>a.find(s=>s.isPinned),[a]),E=Rt.useLocalization();je.useChatScroll({viewItemsWrapperRef:r,isKeyboardNavigationActiveRef:I,processedMessages:a,suggestions:H});const nt=je.useHasScrollbar({elementRef:r}),ot=e.useCallback(()=>{clearTimeout(L.current)},[]),at=e.useCallback(()=>{L.current=window.setTimeout(()=>{A(null)},0)},[]),w=e.useCallback(s=>{A(s)},[]),rt=e.useCallback(s=>{let t=null;const o=p!==null?p:h.lastSelectionIndex;s.keyCode===g.Keys.up?o===null?t=0:o>0&&(t=o-1):s.keyCode===g.Keys.down?o===null?t=0:o<h.lastSelectionIndex&&(t=o+1):s.keyCode===g.Keys.home?t=0:s.keyCode===g.Keys.end&&(t=h.lastSelectionIndex),t!==null&&(A(t),I.current=!0,s.preventDefault())},[p,h]),Be=e.useCallback((s,t,o)=>{var y;if(x&&x({action:{value:s.value,title:s.title,type:s.type},syntheticEvent:t,nativeEvent:t.nativeEvent,target:t.currentTarget}),!t.isDefaultPrevented()){switch(s.type){case"reply":k&&k({message:{id:"",author:f,text:s.value,timestamp:new Date},syntheticEvent:t,nativeEvent:t.nativeEvent,target:t.currentTarget});break;case"call":window.open("tel:"+s.value);break;case"openUrl":window.open(s.value);break}(y=Le.current)==null||y.focusInput()}},[x,k,f]),lt=e.useCallback(()=>{r.current&&(r.current.scrollTop=r.current.scrollHeight-r.current.clientHeight,qe(!1))},[]),it=e.useCallback(()=>g.classNames("k-chat",U,{"k-rtl":q}),[U,q]),ct=e.useCallback(()=>{const s=h.length-1;return h.map((t,o)=>{var y;if(t.type==="date-marker")return e.createElement(St,{item:t,key:t.trackBy,timestampTemplate:W});if(t.type==="message-group"){const B={allowMessageCollapse:_,messageWidthMode:Q,showAvatar:X,showUsername:Y,messageTemplate:M,messageContentTemplate:O,messageToolbarActions:$,messageContextMenuActions:J,fileActions:b},c=At.resolveMessageSettings((y=t==null?void 0:t.messages)==null?void 0:y[0],u,B,ee,te);return e.createElement(Mt,{group:t,itemTemplate:c.messageTemplate,contentTemplate:c.messageContentTemplate,attachmentTemplate:v,user:f,selectedItemIndex:p,onRequestSelection:w,isLastGroup:o===s,key:t.messages[0].selectionIndex,message:V,allowMessageCollapse:c.allowMessageCollapse,messageToolbarActions:c.messageToolbarActions,messageContextMenuActions:c.messageContextMenuActions,fileActions:c.fileActions,messageWidthMode:c.messageWidthMode,showAvatar:c.showAvatar,showUsername:c.showUsername})}else{if(t.type==="attachment-group")return e.createElement(Ct,{group:t,itemTemplate:v,onRequestSelection:w,selected:t.selectionIndex===p,isLastGroup:o===s,key:t.selectionIndex});if(t.type==="action-group")return e.createElement(Tt,{group:t,onActionExecute:Be,onRequestSelection:w,selected:t.selectionIndex===p,key:t.selectionIndex,quickActionsLayout:K,dir:T})}return null})},[h,W,M,O,v,f,p,w,V,_,$,J,b,Q,X,Y,u,ee,te,Be,K,T]),ut=e.useCallback(()=>C?typeof C=="function"?C():C:null,[C]),gt=e.useCallback(()=>S?typeof S=="function"?S():S:null,[S]);e.useEffect(()=>{const s=T!==void 0?T==="rtl":F.current&&getComputedStyle(F.current).direction==="rtl";Ye(!!s)},[T]),e.useEffect(()=>()=>{clearTimeout(L.current)},[]),e.useEffect(()=>{if(!R||!r.current)return;let s;const t=()=>{clearTimeout(s),s=window.setTimeout(()=>{if(r.current){const{scrollTop:y,scrollHeight:B,clientHeight:c}=r.current,dt=B-y-c<100;qe(!dt)}},150)},o=r.current;return o.addEventListener("scroll",t),()=>{o.removeEventListener("scroll",t),clearTimeout(s)}},[R]);const mt=e.useMemo(()=>({replyToMessage:xe,setReplyToMessage:Re,messages:a,user:f,internalScrollContainerRef:Fe,messageListScrollContainerRef:r,onToolbarAction:se,onContextMenuAction:ne,onFileAction:oe,setShowCopyNotification:ve,onDownload:ae,onResendMessage:we,fileActions:b,speechToTextConfig:re,uploadConfig:le,statusTemplate:z,userStatusTemplate:G,messageFilesLayout:ie,timestampVisibility:Z}),[xe,Re,a,f,se,ne,oe,ve,ae,we,b,re,le,z,G,ie,Z]);return e.createElement(vt.default.Provider,{value:mt},e.createElement("div",{style:{width:Pe,height:Ue,position:"relative",overflow:"hidden",...Ke},onKeyDown:rt,className:it(),ref:s=>{F.current=s,Fe.current=s,typeof m=="function"?m(s):m&&(m.current=s)},...Xe},C!==void 0&&e.createElement(bt,null,ut()),e.createElement("div",{className:"k-message-list",onBlur:at,onFocus:ot,role:"log","aria-label":E.toLanguageString(l.ariaLabelMessageList,l.messages[l.ariaLabelMessageList]),"aria-live":"polite",ref:r},Ne&&e.createElement(Et,{message:Ne,onUnpin:_e,user:f}),e.createElement("div",{className:g.classNames("k-message-list-content",{"k-message-list-content-empty":a.length===0})},a.length===0&&S!==void 0&>(),a.length>0&&ct()),R&&et&&e.createElement("div",{className:"k-chat-scroll-to-bottom-container"},e.createElement(ft.FloatingActionButton,{svgIcon:ht.arrowDownOutlineIcon,size:"small",themeColor:"light",rounded:"full",onClick:lt,"aria-label":E.toLanguageString(l.scrollToBottom,l.messages[l.scrollToBottom]),title:E.toLanguageString(l.scrollToBottom,l.messages[l.scrollToBottom])}))),nt&&e.createElement("div",{className:"k-separator"}),e.createElement(kt,{onSendMessage:(s,t)=>{k&&k({message:s,syntheticEvent:t,nativeEvent:t.nativeEvent,target:t.currentTarget})},onSuggestionClick:s=>{j&&j(s)},isDirectionRightToLeft:q,ref:Le,placeholder:He,MessageBox:Ve,suggestions:H,suggestionTemplate:We,inputValue:Ge,onInputValueChange:s=>{P&&P(s)},onInputClick:()=>{I.current=!1},sendButtonConfig:$e,suggestionsLayout:ze,dir:T,messageBoxSettings:Je,loading:Qe}),e.createElement(wt,{show:Ze,text:E.toLanguageString(l.chatCopyNotification,l.messages[l.chatCopyNotification])}),tt&&e.createElement(g.WatermarkOverlay,{message:st})))});D.displayName="Chat";D.propTypes={messages:n.arrayOf(n.object),user:n.object,messageTemplate:n.any,messageContentTemplate:n.any,attachmentTemplate:n.any,width:n.oneOfType([n.string,n.number]),style:n.object,onSendMessage:n.func,onActionExecute:n.func,dir:n.string,messageBox:n.any,noDataTemplate:n.oneOfType([n.element,n.func]),suggestionsLayout:n.oneOf(["scroll","wrap","scrollbuttons"]),quickActionsLayout:n.oneOf(["scroll","wrap","scrollbuttons"]),userStatusTemplate:n.elementType,messageFilesLayout:n.oneOf(["vertical","wrap","horizontal"]),showAvatar:n.bool,showUsername:n.bool,authorMessageSettings:n.object,receiverMessageSettings:n.object};exports.Chat=D;
|