@solexllc/usx-react 0.10.0 → 0.12.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.
Files changed (208) hide show
  1. package/README.md +16 -0
  2. package/dist/Popover-BzDCTuQM.cjs +984 -0
  3. package/dist/Popover-LToVWsWc.js +985 -0
  4. package/dist/chat.cjs +1391 -0
  5. package/dist/chat.js +1391 -0
  6. package/dist/index.cjs +4426 -5231
  7. package/dist/index.js +168 -970
  8. package/package.json +9 -5
  9. package/src/chat.js +15 -0
  10. package/src/components/avatar/Avatar.tsx +54 -16
  11. package/src/components/avatar/avatar.django-snapshot.html +112 -0
  12. package/src/components/avatar/avatar.django.html +2 -2
  13. package/src/components/avatar/avatar.html +25 -0
  14. package/src/components/avatar/avatar.react-snapshot.html +104 -0
  15. package/src/components/avatar/config.json +13 -15
  16. package/src/components/avatar-group/AvatarGroup.tsx +17 -15
  17. package/src/components/avatar-group/avatar-group.django-snapshot.html +22 -0
  18. package/src/components/avatar-group/avatar-group.django.html +1 -1
  19. package/src/components/avatar-group/avatar-group.react-snapshot.html +20 -0
  20. package/src/components/avatar-group/config.json +2 -2
  21. package/src/components/back-to-top/BackToTop.tsx +21 -57
  22. package/src/components/back-to-top/back-to-top.django-snapshot.html +101 -202
  23. package/src/components/back-to-top/back-to-top.django.html +11 -38
  24. package/src/components/back-to-top/back-to-top.html +22 -106
  25. package/src/components/back-to-top/back-to-top.react-snapshot.html +94 -148
  26. package/src/components/back-to-top/config.json +41 -10
  27. package/src/components/button/Button.tsx +12 -3
  28. package/src/components/button/button.django-snapshot.html +18 -0
  29. package/src/components/button/button.django.html +3 -2
  30. package/src/components/button/button.react-snapshot.html +16 -0
  31. package/src/components/button/config.json +11 -2
  32. package/src/components/callout/callout.django.html +1 -1
  33. package/src/components/callout/config.json +7 -16
  34. package/src/components/character-count/CharacterCount.tsx +2 -0
  35. package/src/components/character-count/character-count.react-snapshot.html +7 -0
  36. package/src/components/chat/Chat.tsx +575 -0
  37. package/src/components/chat/README.md +174 -0
  38. package/src/components/chat/avatarProps.ts +32 -0
  39. package/src/components/chat/chat.django-snapshot.html +23515 -0
  40. package/src/components/chat/chat.django.html +75 -0
  41. package/src/components/chat/chat.html +116 -0
  42. package/src/components/chat/chat.react-snapshot.html +16895 -0
  43. package/src/components/chat/config.json +1241 -0
  44. package/src/components/chat-attachment/ChatAttachment.tsx +39 -0
  45. package/src/components/chat-attachment/chat-attachment.django.html +24 -0
  46. package/src/components/chat-attachment/chat-attachment.html +10 -0
  47. package/src/components/chat-attachment/config.json +27 -0
  48. package/src/components/chat-attachments/ChatAttachments.tsx +17 -0
  49. package/src/components/chat-attachments/chat-attachments.django-snapshot.html +58 -0
  50. package/src/components/chat-attachments/chat-attachments.django.html +10 -0
  51. package/src/components/chat-attachments/chat-attachments.html +14 -0
  52. package/src/components/chat-attachments/chat-attachments.react-snapshot.html +46 -0
  53. package/src/components/chat-attachments/config.json +25 -0
  54. package/src/components/chat-bubble/ChatBubble.tsx +39 -0
  55. package/src/components/chat-bubble/ChatFormattedText.tsx +138 -0
  56. package/src/components/chat-bubble/chat-bubble.django-snapshot.html +128 -0
  57. package/src/components/chat-bubble/chat-bubble.django.html +19 -0
  58. package/src/components/chat-bubble/chat-bubble.html +1 -0
  59. package/src/components/chat-bubble/chat-bubble.react-snapshot.html +118 -0
  60. package/src/components/chat-bubble/config.json +70 -0
  61. package/src/components/chat-composer/ChatComposer.tsx +210 -0
  62. package/src/components/chat-composer/README.md +15 -0
  63. package/src/components/chat-composer/chat-composer.django-snapshot.html +575 -0
  64. package/src/components/chat-composer/chat-composer.django.html +77 -0
  65. package/src/components/chat-composer/chat-composer.html +44 -0
  66. package/src/components/chat-composer/chat-composer.react-snapshot.html +519 -0
  67. package/src/components/chat-composer/chat-formatting.django.html +59 -0
  68. package/src/components/chat-composer/config.json +137 -0
  69. package/src/components/chat-context/ChatContext.tsx +46 -0
  70. package/src/components/chat-context/chat-context.django-snapshot.html +35 -0
  71. package/src/components/chat-context/chat-context.django.html +20 -0
  72. package/src/components/chat-context/chat-context.html +9 -0
  73. package/src/components/chat-context/chat-context.react-snapshot.html +30 -0
  74. package/src/components/chat-context/config.json +36 -0
  75. package/src/components/chat-controls/ChatControls.tsx +67 -0
  76. package/src/components/chat-controls/chat-controls.django-snapshot.html +114 -0
  77. package/src/components/chat-controls/chat-controls.django.html +36 -0
  78. package/src/components/chat-controls/chat-controls.html +11 -0
  79. package/src/components/chat-controls/chat-controls.react-snapshot.html +107 -0
  80. package/src/components/chat-controls/config.json +67 -0
  81. package/src/components/chat-directory/ChatDirectory.tsx +168 -0
  82. package/src/components/chat-directory/chat-directory.django-snapshot.html +546 -0
  83. package/src/components/chat-directory/chat-directory.django.html +14 -0
  84. package/src/components/chat-directory/chat-directory.html +4 -0
  85. package/src/components/chat-directory/chat-directory.react-snapshot.html +471 -0
  86. package/src/components/chat-directory/config.json +242 -0
  87. package/src/components/chat-directory-item/ChatDirectoryItem.tsx +150 -0
  88. package/src/components/chat-directory-item/chat-directory-item.django-snapshot.html +281 -0
  89. package/src/components/chat-directory-item/chat-directory-item.django.html +38 -0
  90. package/src/components/chat-directory-item/chat-directory-item.html +9 -0
  91. package/src/components/chat-directory-item/chat-directory-item.react-snapshot.html +249 -0
  92. package/src/components/chat-directory-item/config.json +103 -0
  93. package/src/components/chat-history/ChatHistory.tsx +30 -0
  94. package/src/components/chat-history/chat-history.django-snapshot.html +113 -0
  95. package/src/components/chat-history/chat-history.django.html +20 -0
  96. package/src/components/chat-history/chat-history.html +9 -0
  97. package/src/components/chat-history/chat-history.react-snapshot.html +111 -0
  98. package/src/components/chat-history/config.json +24 -0
  99. package/src/components/chat-message/ChatMessage.tsx +148 -0
  100. package/src/components/chat-message/chat-message.django-snapshot.html +758 -0
  101. package/src/components/chat-message/chat-message.django.html +56 -0
  102. package/src/components/chat-message/chat-message.html +12 -0
  103. package/src/components/chat-message/chat-message.react-snapshot.html +627 -0
  104. package/src/components/chat-message/config.json +278 -0
  105. package/src/components/chat-message-actions/ChatMessageActions.tsx +133 -0
  106. package/src/components/chat-message-actions/chat-message-actions.django-snapshot.html +345 -0
  107. package/src/components/chat-message-actions/chat-message-actions.django.html +29 -0
  108. package/src/components/chat-message-actions/chat-message-actions.html +53 -0
  109. package/src/components/chat-message-actions/chat-message-actions.react-snapshot.html +295 -0
  110. package/src/components/chat-message-actions/config.json +121 -0
  111. package/src/components/chat-window/ChatWindow.tsx +133 -0
  112. package/src/components/chat-window/chat-window.django-snapshot.html +448 -0
  113. package/src/components/chat-window/chat-window.django.html +39 -0
  114. package/src/components/chat-window/chat-window.html +26 -0
  115. package/src/components/chat-window/chat-window.react-snapshot.html +286 -0
  116. package/src/components/chat-window/config.json +123 -0
  117. package/src/components/clickable/Clickable.tsx +19 -5
  118. package/src/components/clickable/clickable.django-snapshot.html +11 -2
  119. package/src/components/clickable/clickable.django.html +2 -0
  120. package/src/components/clickable/clickable.react-snapshot.html +10 -2
  121. package/src/components/clickable/config.json +4 -0
  122. package/src/components/code/code.django-snapshot.html +27 -22
  123. package/src/components/code/code.html +2 -2
  124. package/src/components/code/code.react-snapshot.html +43 -8
  125. package/src/components/copy-to-clipboard/CopyToClipboard.tsx +2 -7
  126. package/src/components/copy-to-clipboard/copy-to-clipboard.django-snapshot.html +6 -4
  127. package/src/components/copy-to-clipboard/copy-to-clipboard.django.html +3 -2
  128. package/src/components/copy-to-clipboard/copy-to-clipboard.react-snapshot.html +14 -2
  129. package/src/components/file-list/FileList.tsx +3 -2
  130. package/src/components/file-list/config.json +5 -0
  131. package/src/components/file-list/file-list.django-snapshot.html +63 -0
  132. package/src/components/file-list/file-list.django.html +1 -1
  133. package/src/components/file-list/file-list.react-snapshot.html +53 -0
  134. package/src/components/footer/footer.django-snapshot.html +0 -3
  135. package/src/components/header/header.django-snapshot.html +5 -167
  136. package/src/components/header/header.django.html +2 -2
  137. package/src/components/header/header.html +1 -11
  138. package/src/components/header/header.react-snapshot.html +3 -6
  139. package/src/components/hero/hero.django-snapshot.html +0 -20
  140. package/src/components/hero/hero.django.html +3 -3
  141. package/src/components/icon-list/IconList.tsx +10 -2
  142. package/src/components/icon-list/config.json +5 -1
  143. package/src/components/icon-list/icon-list.django-snapshot.html +39 -0
  144. package/src/components/icon-list/icon-list.django.html +2 -0
  145. package/src/components/icon-list/icon-list.react-snapshot.html +31 -0
  146. package/src/components/image/image.django.html +4 -4
  147. package/src/components/input/Input.tsx +1 -1
  148. package/src/components/input/config.json +2 -3
  149. package/src/components/input/input.django-snapshot.html +4 -21
  150. package/src/components/input/input.django.html +2 -2
  151. package/src/components/link/Link.tsx +7 -4
  152. package/src/components/link/config.json +2 -3
  153. package/src/components/link/link.django-snapshot.html +8 -0
  154. package/src/components/link/link.django.html +2 -2
  155. package/src/components/link/link.html +4 -1
  156. package/src/components/link/link.react-snapshot.html +8 -0
  157. package/src/components/list/List.tsx +10 -2
  158. package/src/components/list/config.json +5 -1
  159. package/src/components/list/list.django-snapshot.html +26 -0
  160. package/src/components/list/list.django.html +2 -0
  161. package/src/components/list/list.html +20 -0
  162. package/src/components/list/list.react-snapshot.html +20 -0
  163. package/src/components/memorable-date/memorable-date.django-snapshot.html +0 -8
  164. package/src/components/memorable-date/memorable-date.django.html +2 -2
  165. package/src/components/misc-banner/misc-banner.django-snapshot.html +12 -12
  166. package/src/components/misc-banner/misc-banner.django.html +4 -2
  167. package/src/components/page/Page.tsx +16 -0
  168. package/src/components/page/config.json +18 -1
  169. package/src/components/page/page.django-snapshot.html +74 -0
  170. package/src/components/page/page.django.html +8 -0
  171. package/src/components/page/page.html +60 -0
  172. package/src/components/page/page.react-snapshot.html +60 -0
  173. package/src/components/popover/Popover.tsx +60 -9
  174. package/src/components/popover/PopoverMenu.tsx +33 -15
  175. package/src/components/popover/config.json +88 -14
  176. package/src/components/popover/popover-menu.django.html +13 -2
  177. package/src/components/popover/popover.django-snapshot.html +229 -7
  178. package/src/components/popover/popover.django.html +3 -2
  179. package/src/components/popover/popover.react-snapshot.html +127 -4
  180. package/src/components/process-list/config.json +41 -3
  181. package/src/components/quote/Quote.tsx +9 -2
  182. package/src/components/search/Search.tsx +1 -1
  183. package/src/components/search/config.json +3 -4
  184. package/src/components/search/search.django-snapshot.html +262 -1684
  185. package/src/components/search/search.django.html +1 -20
  186. package/src/components/select/select.django-snapshot.html +7 -7
  187. package/src/components/select/select.react-snapshot.html +7 -7
  188. package/src/components/summary/Summary.tsx +4 -2
  189. package/src/components/summary/config.json +4 -0
  190. package/src/components/summary/summary.django.html +4 -4
  191. package/src/components/table/Table.tsx +58 -25
  192. package/src/components/table/config.json +61 -13
  193. package/src/components/tag/Tag.tsx +40 -7
  194. package/src/components/tag/config.json +18 -2
  195. package/src/components/tag/tag.django-snapshot.html +16 -1
  196. package/src/components/tag/tag.django.html +12 -6
  197. package/src/components/tag/tag.html +4 -0
  198. package/src/components/tag/tag.react-snapshot.html +16 -1
  199. package/src/components/tag-group/TagGroup.tsx +6 -9
  200. package/src/components/tag-group/config.json +4 -0
  201. package/src/components/tag-group/tag-group.django.html +1 -1
  202. package/src/components/theme-picker/ThemePicker.tsx +95 -52
  203. package/src/components/theme-picker/config.json +7 -4
  204. package/src/components/theme-picker/theme-picker-select.django.html +7 -0
  205. package/src/components/theme-picker/theme-picker.django-snapshot.html +101 -21
  206. package/src/components/theme-picker/theme-picker.django.html +22 -24
  207. package/src/components/theme-picker/theme-picker.html +86 -56
  208. package/src/components/theme-picker/theme-picker.react-snapshot.html +74 -18
@@ -0,0 +1,575 @@
1
+ import type { SummaryProps } from '../summary/Summary';
2
+ import ChatWindow from '../chat-window/ChatWindow';
3
+ import ChatMessage from '../chat-message/ChatMessage';
4
+ import ChatControls from '../chat-controls/ChatControls';
5
+ import ChatDirectory from '../chat-directory/ChatDirectory';
6
+ import ChatContext from '../chat-context/ChatContext';
7
+ import ChatHistory from '../chat-history/ChatHistory';
8
+ import React from 'react';
9
+ import chatAvatarProps from './avatarProps';
10
+ import type { AvatarProps } from '../avatar/Avatar';
11
+ import AvatarGroup from '../avatar-group/AvatarGroup';
12
+ import Callout from '../callout/Callout';
13
+ import type { PopoverAlign, PopoverSide } from '../popover/Popover';
14
+ import chatConfig from './config.json';
15
+ import ChatComposer from '../chat-composer/ChatComposer';
16
+
17
+ const MAX_EMOJI = 100;
18
+
19
+ export interface ChatParticipant {
20
+ id: string;
21
+ name: string;
22
+ avatarProps?: Omit<AvatarProps, 'href'>;
23
+ /** Current host-supplied presence; omit when unavailable or unknown. */
24
+ presence?: 'online' | 'away';
25
+ /** Default actions for messages from this sender; [] disables host actions. */
26
+ messageActions?: ChatAction[];
27
+ }
28
+
29
+ export interface ChatAttachment {
30
+ name: string;
31
+ url?: string;
32
+ imageUrl?: string;
33
+ /** Description of the preview image; defaults to the file name. */
34
+ alt?: string;
35
+ }
36
+
37
+ export interface ChatOlderHistory {
38
+ /** Whether an earlier page exists. Omit olderHistory to disable paging controls. */
39
+ hasMore: boolean;
40
+ /** Opaque host-owned cursor for the next older page. */
41
+ cursor?: string;
42
+ loading?: boolean;
43
+ error?: string;
44
+ }
45
+
46
+ export interface ChatMessageData {
47
+ id: string;
48
+ /** Correlation ID supplied by the host after submission. */
49
+ clientMessageId?: string;
50
+ senderId: string;
51
+ /** Optional explicit grouping; both renderers derive it when omitted. */
52
+ groupPosition?: 'single' | 'first' | 'middle' | 'last';
53
+ /** Safe formatting subset: **bold**, *italic*, <u>underline</u>, ~~strike~~, lists, > quotes, and fenced code. */
54
+ text?: string;
55
+ /** Rich content; provide exportText for the plain-text copy action. */
56
+ content?: React.ReactNode;
57
+ /** Use a full-width neutral panel for host-owned editing or confirmation controls. */
58
+ layout?: 'bubble' | 'panel';
59
+ exportText?: string;
60
+ sentAt?: string;
61
+ timeLabel?: string;
62
+ attachments?: ChatAttachment[];
63
+ /** Optional replies rendered in a thread view. */
64
+ replies?: ChatMessageData[];
65
+ /** Paging state for replies when this message is the active thread root. */
66
+ olderReplies?: ChatOlderHistory;
67
+ replyCount?: number;
68
+ edited?: boolean;
69
+ deliveryStatus?: string;
70
+ /** Optional host-supplied delivery state for server-rendered messages. */
71
+ deliveryState?: 'sending' | 'failed';
72
+ actions?: ChatMessageAction[];
73
+ reactions?: ChatReaction[];
74
+ /** Override the chat-level emoji choices; an empty array disables adding reactions. */
75
+ reactionOptions?: ChatReactionOption[];
76
+ }
77
+
78
+ export interface ChatAction {
79
+ id: string;
80
+ label: string;
81
+ disabled?: boolean;
82
+ }
83
+ export type ChatMessageAction = ChatAction;
84
+ export interface ChatMessageActionDefaults {
85
+ sent?: ChatAction[];
86
+ received?: ChatAction[];
87
+ }
88
+
89
+ /** Pure markup defaults. Explicit message actions (including []) take precedence. */
90
+ export function resolveChatMessageActions(
91
+ message: ChatMessageData,
92
+ currentUserId: string,
93
+ participant?: ChatParticipant,
94
+ conversation?: ChatConversationData,
95
+ defaults?: ChatMessageActionDefaults
96
+ ): ChatAction[] {
97
+ const side = message.senderId === currentUserId ? 'sent' : 'received';
98
+ return (
99
+ message.actions ??
100
+ participant?.messageActions ??
101
+ conversation?.messageActions?.[side] ??
102
+ defaults?.[side] ??
103
+ []
104
+ );
105
+ }
106
+ export interface ChatReaction {
107
+ emoji: string;
108
+ label: string;
109
+ count: number;
110
+ selected?: boolean;
111
+ }
112
+ export interface ChatReactionOption {
113
+ emoji: string;
114
+ label: string;
115
+ }
116
+ export interface ChatEmoji extends ChatReactionOption {
117
+ /** Lowercase shortcode without colons, such as thumbsup. */
118
+ name: string;
119
+ aliases?: string[];
120
+ }
121
+ export interface ChatConversationContext {
122
+ /** Short category such as "Listing" or "Access request". */
123
+ label: string;
124
+ title: string;
125
+ /** Optional detail such as a price or request status. */
126
+ description?: string;
127
+ imageUrl?: string;
128
+ imageAlt?: string;
129
+ /** URL of the referenced item or record; navigation is owned by the host. */
130
+ href?: string;
131
+ }
132
+ export interface ChatConversationData {
133
+ id: string;
134
+ title: string;
135
+ /** Host-defined actions shared by the directory row and conversation/thread header. */
136
+ actions?: ChatAction[];
137
+ messageActions?: ChatMessageActionDefaults;
138
+ /** Other members shown in the inbox; the current user is omitted if supplied. */
139
+ participantIds?: string[];
140
+ /** Preserve group treatment when only one other member remains. */
141
+ isGroup?: boolean;
142
+ /** Optional conversation image or icon instead of member avatars. */
143
+ avatarProps?: Omit<AvatarProps, 'href'>;
144
+ preview?: string;
145
+ /** Sender of preview, shown before the preview in group inbox rows. */
146
+ previewSenderId?: string;
147
+ timeLabel?: string;
148
+ unreadCount?: number;
149
+ /** Stable ID of the first unread message in the supplied history. */
150
+ firstUnreadMessageId?: string;
151
+ href?: string;
152
+ context?: ChatConversationContext;
153
+ messages?: ChatMessageData[];
154
+ olderHistory?: ChatOlderHistory;
155
+ /** Override whether this conversation accepts new file uploads. */
156
+ allowAttachments?: boolean;
157
+ /** Enable threads for every message in this conversation. */
158
+ allowThreads?: boolean;
159
+ }
160
+ export interface ChatContactData {
161
+ participantId: string;
162
+ /** Optional host-defined actions for this directory entry. */
163
+ actions?: ChatAction[];
164
+ description?: string;
165
+ conversationId?: string;
166
+ href?: string;
167
+ /** Override whether a new conversation with this contact accepts uploads. */
168
+ allowAttachments?: boolean;
169
+ }
170
+ export type ChatView = 'inbox' | 'contacts' | 'conversation' | 'thread';
171
+
172
+ export interface ChatOption {
173
+ label: string;
174
+ value: string;
175
+ }
176
+
177
+ export interface ChatProps {
178
+ id: string;
179
+ title?: string;
180
+ status?: string;
181
+ /** Subject of a standalone conversation. A selected conversation overrides it. */
182
+ context?: ChatConversationContext;
183
+ participants?: ChatParticipant[];
184
+ currentUserId?: string;
185
+ messages?: ChatMessageData[];
186
+ messageActions?: ChatMessageActionDefaults;
187
+ /** Paging state for a standalone conversation. Selected conversations use their own state. */
188
+ olderHistory?: ChatOlderHistory;
189
+ /** First unread message for a standalone conversation. A selected conversation overrides it. */
190
+ firstUnreadMessageId?: string;
191
+ conversations?: ChatConversationData[];
192
+ contacts?: ChatContactData[];
193
+ /** View supplied by the host; defaults to the initial directory or conversation. */
194
+ view?: ChatView;
195
+ defaultView?: ChatView;
196
+ activeConversationId?: string;
197
+ defaultConversationId?: string;
198
+ activeThreadId?: string;
199
+ /** Recipient for a new conversation without an ID yet. */
200
+ recipientId?: string;
201
+ /** Initially selected recipients in the new-message picker. */
202
+ recipientIds?: string[];
203
+ emptyText?: string;
204
+ typingIds?: string[];
205
+ suggestedQuestions?: ChatOption[];
206
+ choices?: ChatOption[];
207
+ choicePrompt?: string;
208
+ actions?: React.ReactNode;
209
+ showCopyAction?: boolean;
210
+ /** Show Copy message in each message's More menu. */
211
+ showCopyMessageAction?: boolean;
212
+ /** Emoji choices for adding a reaction to any message. Defaults to emojiPack. Pass [] to disable reactions. */
213
+ reactionOptions?: ChatReactionOption[];
214
+ /** Composer emoji and shortcode choices. Defaults to the included pack; pass [] to disable emoji input. */
215
+ emojiPack?: ChatEmoji[];
216
+ children?: React.ReactNode;
217
+ summaryProps?: Omit<SummaryProps, 'unstyled'>;
218
+ side?: PopoverSide;
219
+ align?: PopoverAlign;
220
+ defaultOpen?: boolean;
221
+ groupWindowMinutes?: number;
222
+ /** Enable file uploads in the composer. Defaults to false; conversations and contacts may override it. */
223
+ allowAttachments?: boolean;
224
+ /** Enable threads for every message; individual conversations may override this. */
225
+ allowThreads?: boolean;
226
+ /** Show the composer formatting panel and enable its keyboard shortcuts. Defaults to false. */
227
+ allowFormatting?: boolean;
228
+ accept?: string;
229
+ formAction?: string;
230
+ disabled?: boolean;
231
+ className?: string;
232
+ }
233
+
234
+ const nameOf = (id: string, participants: ChatParticipant[]) =>
235
+ participants.find((participant) => participant.id === id)?.name || id;
236
+ // Only grouping uses normalized instants; displayed labels and datetime attributes stay literal.
237
+ function groupingTime(value: string | undefined): number {
238
+ const match = value?.match(
239
+ /^(\d{4}-\d{2}-\d{2})T((?:[01]\d|2[0-3]):[0-5]\d)(?::([0-5]\d)(?:\.(\d+))?)?(Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)?$/
240
+ );
241
+ if (!match || match[0] !== value) return NaN;
242
+ const [, date, time, seconds = '00', fraction = '', zone = 'Z'] = match;
243
+ const calendar = new Date(`${date}T00:00:00Z`);
244
+ if (
245
+ date.startsWith('0000') ||
246
+ !Number.isFinite(calendar.getTime()) ||
247
+ calendar.toISOString().slice(0, 10) !== date
248
+ )
249
+ return NaN;
250
+ return Date.parse(`${date}T${time}:${seconds}.${fraction.slice(0, 3).padEnd(3, '0')}${zone}`);
251
+ }
252
+
253
+ const sameGroup = (
254
+ a: ChatMessageData | undefined,
255
+ b: ChatMessageData | undefined,
256
+ minutes: number
257
+ ) => {
258
+ if (!a?.sentAt || !b?.sentAt || a.senderId !== b.senderId) return false;
259
+ const gap = groupingTime(b.sentAt) - groupingTime(a.sentAt);
260
+ return Number.isFinite(gap) && gap >= 0 && gap <= minutes * 60_000;
261
+ };
262
+
263
+ export default function Chat({
264
+ id,
265
+ title = 'Chat',
266
+ status,
267
+ context,
268
+ participants = [],
269
+ currentUserId = 'user',
270
+ messages = [],
271
+ messageActions,
272
+ olderHistory,
273
+ firstUnreadMessageId,
274
+ conversations = [],
275
+ contacts = [],
276
+ view,
277
+ defaultView,
278
+ activeConversationId,
279
+ defaultConversationId,
280
+ activeThreadId,
281
+ recipientId,
282
+ recipientIds = [],
283
+ emptyText = 'No messages yet. Start the conversation.',
284
+ typingIds = [],
285
+ suggestedQuestions = [],
286
+ choices = [],
287
+ choicePrompt = 'Choose an answer',
288
+ actions,
289
+ showCopyAction = false,
290
+ showCopyMessageAction = true,
291
+ reactionOptions,
292
+ emojiPack = chatConfig.props.emojiPack.default,
293
+ children,
294
+ summaryProps,
295
+ side,
296
+ align,
297
+ defaultOpen = false,
298
+ groupWindowMinutes = 5,
299
+ allowAttachments = false,
300
+ allowThreads = false,
301
+ allowFormatting = false,
302
+ accept,
303
+ formAction,
304
+ disabled = false,
305
+ className,
306
+ }: ChatProps) {
307
+ const currentView = view ?? defaultView ?? (conversations.length ? 'inbox' : 'conversation');
308
+ const conversationId = activeConversationId ?? defaultConversationId;
309
+ const conversation = conversations.find((item) => item.id === conversationId);
310
+ const conversationContext = conversation?.context ?? context;
311
+ const selectedRecipientId = recipientId;
312
+ const contactPerson = participants.find((item) => item.id === recipientId);
313
+ const selectedContact = !conversation
314
+ ? contacts.find((item) => item.participantId === recipientId)
315
+ : undefined;
316
+ const canAttach =
317
+ conversation?.allowAttachments ?? selectedContact?.allowAttachments ?? allowAttachments;
318
+ const activeEmojiPack = emojiPack.slice(0, MAX_EMOJI);
319
+ const conversationMessages =
320
+ recipientId && !conversation ? [] : (conversation?.messages ?? messages);
321
+ const unreadBoundaryId = conversation ? conversation.firstUnreadMessageId : firstUnreadMessageId;
322
+ const threadRootId = activeThreadId;
323
+ const threadRoot = conversationMessages.find((item) => item.id === threadRootId);
324
+ const threadReplyCount =
325
+ threadRoot?.replyCount ??
326
+ (threadRoot?.olderReplies?.hasMore ? null : (threadRoot?.replies?.length ?? 0));
327
+ const threadRootPreview =
328
+ threadRoot?.text ??
329
+ threadRoot?.exportText ??
330
+ (threadRoot?.attachments?.[0] ? 'Attachment: ' + threadRoot.attachments[0].name : '');
331
+ const visibleMessages =
332
+ currentView === 'thread'
333
+ ? threadRoot
334
+ ? [threadRoot, ...(threadRoot.replies ?? [])]
335
+ : []
336
+ : conversationMessages;
337
+ const activeOlderHistory =
338
+ currentView === 'thread'
339
+ ? threadRoot?.olderReplies
340
+ : recipientId && !conversation
341
+ ? undefined
342
+ : conversation
343
+ ? conversation.olderHistory
344
+ : olderHistory;
345
+ const olderLoading = Boolean(activeOlderHistory?.loading);
346
+ const canCopy = showCopyAction && (currentView === 'conversation' || currentView === 'thread');
347
+ const historyControl = activeOlderHistory ? <ChatHistory {...activeOlderHistory} /> : null;
348
+ return (
349
+ <ChatWindow
350
+ id={id}
351
+ title={
352
+ currentView === 'thread'
353
+ ? 'Thread'
354
+ : currentView === 'contacts'
355
+ ? 'New message'
356
+ : (conversation?.title ?? contactPerson?.name ?? title)
357
+ }
358
+ view={currentView}
359
+ status={
360
+ currentView === 'thread'
361
+ ? `In ${conversation?.title ?? title}`
362
+ : currentView === 'conversation'
363
+ ? status
364
+ : undefined
365
+ }
366
+ showBack={
367
+ currentView === 'thread' ||
368
+ currentView === 'contacts' ||
369
+ (currentView === 'conversation' && conversations.length > 0)
370
+ }
371
+ showNewMessage={contacts.length > 0 && currentView === 'inbox'}
372
+ showCopyAction={canCopy}
373
+ conversationId={conversation?.id}
374
+ conversationActions={
375
+ currentView === 'conversation' || currentView === 'thread'
376
+ ? conversation?.actions
377
+ : undefined
378
+ }
379
+ actions={actions}
380
+ summaryProps={summaryProps}
381
+ side={side}
382
+ align={align}
383
+ defaultOpen={defaultOpen}
384
+ className={className}
385
+ >
386
+ {(currentView === 'conversation' || currentView === 'thread') && conversationContext && (
387
+ <ChatContext {...conversationContext} />
388
+ )}
389
+ {currentView === 'thread' && threadRoot && (
390
+ <Callout
391
+ as="aside"
392
+ big={false}
393
+ strokeColor="primary"
394
+ backgroundColor="surface-2"
395
+ textColor="ink"
396
+ className="usx-chat__context"
397
+ aria-label="Thread context"
398
+ >
399
+ <div className="usx-chat__context-copy">
400
+ <strong>Replying to {nameOf(threadRoot.senderId, participants)}</strong>
401
+ {threadRootPreview && <span>{threadRootPreview}</span>}
402
+ </div>
403
+ </Callout>
404
+ )}
405
+ <ChatDirectory
406
+ id={`${id}-directory`}
407
+ view={currentView}
408
+ conversations={conversations}
409
+ contacts={contacts}
410
+ participants={participants}
411
+ currentUserId={currentUserId}
412
+ selectable={currentView === 'contacts'}
413
+ recipientIds={recipientIds}
414
+ formId={`${id}-composer`}
415
+ disabled={disabled}
416
+ />
417
+ {currentView === 'contacts' && (
418
+ <ChatComposer
419
+ id={id}
420
+ formAction={formAction}
421
+ requireRecipients
422
+ disabled={disabled}
423
+ allowAttachments={allowAttachments}
424
+ allowFormatting={allowFormatting}
425
+ accept={accept}
426
+ emojiPack={activeEmojiPack}
427
+ />
428
+ )}
429
+ {(currentView === 'conversation' || currentView === 'thread') && (
430
+ <>
431
+ <ol
432
+ className="usx-chat__messages"
433
+ role="log"
434
+ aria-label={currentView === 'thread' ? 'Thread messages' : 'Conversation'}
435
+ aria-live="polite"
436
+ aria-relevant="additions text"
437
+ aria-busy={olderLoading}
438
+ tabIndex={0}
439
+ data-usx-chat-older-cursor={activeOlderHistory?.cursor}
440
+ data-usx-chat-conversation-id={conversationId}
441
+ data-usx-chat-thread-id={currentView === 'thread' ? threadRootId : undefined}
442
+ >
443
+ {currentView !== 'thread' && historyControl}
444
+ {visibleMessages.length === 0 && (
445
+ <li className="usx-chat__empty">
446
+ {currentView === 'thread' ? 'Thread unavailable.' : emptyText}
447
+ </li>
448
+ )}
449
+ {currentView === 'thread' && threadRoot && (
450
+ <li className="usx-chat__thread-label" role="separator">
451
+ Original message
452
+ </li>
453
+ )}
454
+ {visibleMessages.map((message, index) => {
455
+ const participant = participants.find((item) => item.id === message.senderId);
456
+ const unconfirmed = Boolean(message.deliveryState);
457
+ const previous = visibleMessages[index - 1];
458
+ const next = visibleMessages[index + 1];
459
+ const starts =
460
+ (currentView === 'thread' && index === 1) ||
461
+ unconfirmed ||
462
+ Boolean(previous?.deliveryState) ||
463
+ !sameGroup(previous, message, groupWindowMinutes);
464
+ const ends =
465
+ (currentView === 'thread' && index === 0) ||
466
+ unconfirmed ||
467
+ Boolean(next?.deliveryState) ||
468
+ !sameGroup(message, next, groupWindowMinutes);
469
+ const position = unconfirmed
470
+ ? 'single'
471
+ : currentView === 'thread' && index < 2
472
+ ? starts
473
+ ? ends
474
+ ? 'single'
475
+ : 'first'
476
+ : ends
477
+ ? 'last'
478
+ : 'middle'
479
+ : (message.groupPosition ??
480
+ (starts ? (ends ? 'single' : 'first') : ends ? 'last' : 'middle'));
481
+ return (
482
+ <React.Fragment key={message.id}>
483
+ {currentView === 'conversation' && message.id === unreadBoundaryId && (
484
+ <li className="usx-chat__unread-divider" role="separator">
485
+ <span>Unread messages</span>
486
+ </li>
487
+ )}
488
+ <ChatMessage
489
+ id={id}
490
+ message={{
491
+ ...message,
492
+ groupPosition: position,
493
+ actions: resolveChatMessageActions(
494
+ message,
495
+ currentUserId,
496
+ participant,
497
+ conversation,
498
+ messageActions
499
+ ),
500
+ }}
501
+ participant={participant}
502
+ own={message.senderId === currentUserId}
503
+ isThread={currentView === 'thread'}
504
+ allowThreads={conversation?.allowThreads ?? allowThreads}
505
+ allowForward={contacts.length > 0}
506
+ showCopyMessageAction={showCopyMessageAction}
507
+ reactionOptions={reactionOptions ?? activeEmojiPack}
508
+ disabled={disabled}
509
+ />
510
+ {currentView === 'thread' && index === 0 && historyControl}
511
+ {currentView === 'thread' && index === 0 && (
512
+ <li className="usx-chat__thread-divider" role="separator">
513
+ <span>
514
+ {threadReplyCount === null
515
+ ? 'Replies'
516
+ : threadReplyCount === 1
517
+ ? '1 reply'
518
+ : `${threadReplyCount} replies`}
519
+ </span>
520
+ </li>
521
+ )}
522
+ </React.Fragment>
523
+ );
524
+ })}
525
+ {typingIds.length > 0 && (
526
+ <li className="usx-chat__typing" role="status" aria-live="polite">
527
+ <AvatarGroup
528
+ overlap
529
+ avatarProps={typingIds.map((personId) =>
530
+ chatAvatarProps(
531
+ participants.find((item) => item.id === personId),
532
+ nameOf(personId, participants)
533
+ )
534
+ )}
535
+ />
536
+ <span>
537
+ {typingIds.map((personId) => nameOf(personId, participants)).join(', ')}{' '}
538
+ {typingIds.length === 1 ? 'is' : 'are'} typing
539
+ </span>
540
+ <span className="usx-chat__typing-dots" aria-hidden="true">
541
+ <i />
542
+ <i />
543
+ <i />
544
+ </span>
545
+ </li>
546
+ )}
547
+ <ChatControls
548
+ suggestedQuestions={suggestedQuestions}
549
+ choices={choices}
550
+ choicePrompt={choicePrompt}
551
+ disabled={disabled}
552
+ >
553
+ {children}
554
+ </ChatControls>
555
+ </ol>
556
+ {(currentView !== 'thread' || threadRoot) && (
557
+ <ChatComposer
558
+ id={id}
559
+ formAction={formAction}
560
+ disabled={disabled}
561
+ allowAttachments={canAttach}
562
+ allowFormatting={allowFormatting}
563
+ accept={accept}
564
+ emojiPack={activeEmojiPack}
565
+ isThread={currentView === 'thread'}
566
+ conversationId={conversationId}
567
+ recipientId={selectedRecipientId}
568
+ threadRootId={threadRootId}
569
+ />
570
+ )}
571
+ </>
572
+ )}
573
+ </ChatWindow>
574
+ );
575
+ }