@talkjs/web-components 0.1.6 → 0.1.8

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/default.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { AudioBlock } from '@talkjs/core';
2
2
  import { ContentBlock } from '@talkjs/core';
3
+ import { ConversationSearch } from '@talkjs/core';
4
+ import { ConversationSearchState } from '@talkjs/core';
3
5
  import { ConversationSnapshot } from '@talkjs/core';
4
6
  import { EditMessageParams } from '@talkjs/core';
5
7
  import { EditTextMessageParams } from '@talkjs/core';
@@ -9,11 +11,14 @@ import { GenericFileBlock } from '@talkjs/core';
9
11
  import { ImageBlock } from '@talkjs/core';
10
12
  import { JSX as JSX_2 } from 'react/jsx-runtime';
11
13
  import { LocationBlock } from '@talkjs/core';
14
+ import { MessageSearch } from '@talkjs/core';
15
+ import { MessageSearchState } from '@talkjs/core';
12
16
  import { MessageSnapshot } from '@talkjs/core';
13
17
  import { ParticipantSnapshot } from '@talkjs/core';
14
18
  import * as Preact from 'preact/compat';
15
19
  import * as React_2 from 'react';
16
20
  import { ReferencedMessageSnapshot } from '@talkjs/core';
21
+ import { SearchMessageSnapshot } from '@talkjs/core';
17
22
  import { SendMessageParams } from '@talkjs/core';
18
23
  import { SendTextMessageParams } from '@talkjs/core';
19
24
  import { TalkSession } from '@talkjs/core';
@@ -191,6 +196,21 @@ export declare interface BaseChatboxProps {
191
196
  * be displayed.
192
197
  */
193
198
  userId: string;
199
+ /**
200
+ * The ID of the currently focused message.
201
+ *
202
+ * @remarks
203
+ * Whenever this value changes to a valid message ID, the relevant message
204
+ * will be scrolled into view.
205
+ *
206
+ * If you're using a modern web framework like React or Vue, also include an
207
+ * {@link onFocusMessage} prop where you'll update your local `focusedMessageId` state
208
+ * so that it stays in sync with the UI's internals.
209
+ *
210
+ * Note that updating the selected conversation through this prop **will not**
211
+ * trigger the {@link onFocusMessage} callback.
212
+ */
213
+ focusedMessageId?: string;
194
214
  /**
195
215
  * Lets you override theme components with your own implementations to
196
216
  * customize them.
@@ -281,6 +301,16 @@ export declare interface BaseChatboxProps {
281
301
  * for more info.
282
302
  */
283
303
  onMessageAction?: (event: MessageActionEvent) => void;
304
+ /**
305
+ * Callback that triggers when a message is focused or unfocused.
306
+ *
307
+ * @param event - Event object describing the message focus action
308
+ *
309
+ * @remarks
310
+ * Note that updating the focused message through the
311
+ * {@link focusedMessageId} prop **will not** trigger this callback.
312
+ */
313
+ onFocusMessage?: (event: FocusMessageEvent) => void;
284
314
  /**
285
315
  * Arbitrary custom data passed down to the theme.
286
316
  *
@@ -327,6 +357,10 @@ export declare interface BaseConversationListProps {
327
357
  * Changing the value of this prop will cause the ConversationList UI to
328
358
  * update.
329
359
  *
360
+ * If you're using a modern web framework like React or Vue, also include an
361
+ * {@link onSelectConversation} prop where you'll update your local `selectedConversationId` state
362
+ * so that it stays in sync with the UI's internals.
363
+ *
330
364
  * Note that updating the selected conversation through this prop **will not**
331
365
  * trigger the {@link onSelectConversation} callback.
332
366
  */
@@ -489,8 +523,9 @@ export declare class ChatboxController {
489
523
  *
490
524
  * @param messageId - The ID of the message you want to toggle the reaction on. This message must exist in the current conversation.
491
525
  * @param emoji - The emoji you want to toggle. Must be a string of a single unicode emoji glyph, eg `"🎉"`.
526
+ * @param force - If included, turns the toggle into a one way-only operation. Setting to `true` will add this reaction for the current user and setting to `false` will remove it if it was already added for the current user
492
527
  */
493
- toggleReaction(messageId: string, emoji: string): Promise<void>;
528
+ toggleReaction(messageId: string, emoji: string, force?: boolean): Promise<void>;
494
529
  /**
495
530
  * Get the plaintext from the message field
496
531
  *
@@ -506,13 +541,55 @@ export declare class ChatboxController {
506
541
  */
507
542
  focusMessageField(): void;
508
543
  /**
509
- * Emits a {@link ChatboxController.onBackButtonClick} event.
544
+ * Toggles whether the `ChatSearchBox` should be visible or not.
545
+ *
546
+ * @param force - If included, turns the toggle into a one way-only operation. Setting to `true` will enable the search box, and setting to `false` will disable it.
547
+ */
548
+ toggleSearchBox(force?: boolean): void;
549
+ /**
550
+ * Scrolls to the message with the given messageId and marks it as "focused",
551
+ * meaning the {@link CommonChatboxProps.focusedMessage} field will be
552
+ * populated.
553
+ *
554
+ * If `null` is passed the `focusedMessage` will be cleared.
555
+ *
556
+ * @returns `true` if a message with the given ID was found and was scrolled
557
+ * to.
558
+ */
559
+ focusMessage(messageId: string | null): Promise<MessageSnapshot | null>;
560
+ /**
561
+ * Highlights certain strings in messages
510
562
  *
511
563
  * @remarks
512
- * Called from the default ChatHeader theme component for the "back" button
513
- * which is shown when the chatbox is part of an inbox that's being rendered
514
- * in mobile mode.
564
+ * The TalkJS search feature includes the ability to highlight certain strings in messages. Call
565
+ * this method to highlight certain strings without having the user invoke the search feature.
566
+ * Call again with an empty array to disable highlighting.
567
+ *
568
+ * Note: like the search feature, this option only works on the Growth plan and up.
515
569
  */
570
+ setHighlightedStrings(words: string[]): void;
571
+ /**
572
+ * Searches for a message upwards that contains highlighted strings.
573
+ * If a message is found, the UI will scroll that message into view.
574
+ *
575
+ * Strings are highlighted when you explicitly call {@link setHighlightedStrings} or
576
+ * when a user types a word/phrase into the `ChatSearchBox`.
577
+ *
578
+ * @returns A promise resolving to a {@link MessageSnapshot} if a message was found. The promise
579
+ * resolves to `null` otherwise.
580
+ */
581
+ jumpToPreviousHighlight(): Promise<MessageSnapshot | null>;
582
+ /**
583
+ * Searches for messages downwards that contains highlighted strings.
584
+ * If a message is found, the UI will scroll that message into view.
585
+ *
586
+ * Strings are highlighted when you explicitly call {@link setHighlightedStrings} or
587
+ * when a user types a word/phrase into the `ChatSearchBox`.
588
+ *
589
+ * @returns A promise resolving to a {@link MessageSnapshot} if a message was found. The promise
590
+ * resolves to `null` otherwise.
591
+ */
592
+ jumpToNextHighlight(): Promise<MessageSnapshot | null>;
516
593
  clickBackButton(): void;
517
594
  }
518
595
 
@@ -534,7 +611,7 @@ export declare interface ChatboxProps extends BaseChatboxProps {
534
611
  *
535
612
  * @remarks
536
613
  * If the conversation doesn't exist or if the current user isn't a
537
- * participant of the current conversation, a "Chat not found" message will be
614
+ * participant of the current conversation, a "Conversation not found" message will be
538
615
  * displayed (after a timeout). If you create the conversation in parallel (eg
539
616
  * via the REST API or via the Data API), it will show in the chatbox
540
617
  * automatically. This means that you can safely point a chatbox at a
@@ -606,6 +683,36 @@ export declare interface ChatHeaderProps {
606
683
  permissions: UserPermissions;
607
684
  }
608
685
 
686
+ /**
687
+ * @public
688
+ */
689
+ export declare interface ChatSearchBoxProps {
690
+ /**
691
+ * A collection of objects which are passed to all Chatbox theme components.
692
+ */
693
+ common: CommonChatboxProps;
694
+ }
695
+
696
+ /**
697
+ * The current state of the chat search
698
+ *
699
+ * @remarks
700
+ * This type can have one of these values:
701
+ *
702
+ * - `"hidden"` - The {@link Theme.ChatSearchBox} is not shown to the user.
703
+ *
704
+ * - `"visible"` - The {@link Theme.ChatSearchBox} is shown to the user.
705
+ *
706
+ * - `"searching"` - Waiting for more older messages to be loaded from the server.
707
+ *
708
+ * - `"noResults"` - There are 0 messages that contain the phrase entered by the user.
709
+ *
710
+ * - `"noMoreResults"` - There are not any more messages in the given direction that contain a match for the phrase entered by the user.
711
+ *
712
+ * @public
713
+ */
714
+ export declare type ChatSearchState = "hidden" | "visible" | "searching" | "noResults" | "noMoreResults";
715
+
609
716
  /**
610
717
  * A collection of props that's shared by every themed component used in the Chatbox UI.
611
718
  *
@@ -642,7 +749,7 @@ export declare interface CommonChatboxProps {
642
749
  */
643
750
  device: DeviceFeatures;
644
751
  /**
645
- * The theme object that the chatbox's is currently using.
752
+ * The theme object that the chatbox is currently using.
646
753
  */
647
754
  theme: Theme;
648
755
  /**
@@ -659,13 +766,23 @@ export declare interface CommonChatboxProps {
659
766
  */
660
767
  conversation: ConversationSnapshot;
661
768
  /**
662
- * Tells you which participants are currently typing
769
+ * Tells you which participants are currently typing.
663
770
  */
664
771
  typing: TypingSnapshot;
665
772
  /**
666
773
  * The underlying TalkJS session object that handles sending and receiving chat data.
667
774
  */
668
775
  session: TalkSession;
776
+ /**
777
+ * The message that was most recently scrolled into view as a result of calling one of the following methods:
778
+ * {@link ChatboxController.focusMessage}, {@link ChatboxController.jumpToPreviousHighlight}
779
+ * or {@link ChatboxController.jumpToNextHighlight}
780
+ */
781
+ focusedMessage: MessageSnapshot | null;
782
+ /**
783
+ * The current state of the chat search
784
+ */
785
+ chatSearchState: ChatSearchState;
669
786
  }
670
787
 
671
788
  /**
@@ -700,7 +817,7 @@ export declare interface CommonConversationListProps {
700
817
  */
701
818
  device: DeviceFeatures;
702
819
  /**
703
- * The theme object that the chatbox's is currently using.
820
+ * The theme object that the conversation list is currently using.
704
821
  */
705
822
  theme: Theme;
706
823
  /**
@@ -763,7 +880,8 @@ export declare interface ConversationImageProps {
763
880
  export declare class ConversationListController {
764
881
  #private;
765
882
  /**
766
- * Select a conversation.
883
+ * Selects a conversation with the given ID, or de-select a conversation by
884
+ * passing `null`.
767
885
  *
768
886
  * @remarks
769
887
  * This method is called from the theme's ConversationListItem component when
@@ -777,8 +895,11 @@ export declare class ConversationListController {
777
895
  * to the {@link ConversationListProps.selectedConversationId} prop
778
896
  * instead, as that lets you keep your local state in sync with the props
779
897
  * passed to the conversation list.
898
+ *
899
+ * You can also optionally pass a `focusedMessageId` to signify the intent
900
+ * of scrolling to a particular message within that conversation.
780
901
  */
781
- selectConversation(conversationId: string | null): void;
902
+ selectConversation(conversationId: string | null, focusedMessageId?: string): Promise<void>;
782
903
  }
783
904
 
784
905
  /**
@@ -841,6 +962,10 @@ export declare interface ConversationListProps extends BaseConversationListProps
841
962
  tokenFetcher?: () => string | Promise<string>;
842
963
  }
843
964
 
965
+ export { ConversationSearch }
966
+
967
+ export { ConversationSearchState }
968
+
844
969
  export { ConversationSnapshot }
845
970
 
846
971
  /**
@@ -900,18 +1025,46 @@ export declare interface DeviceFeatures {
900
1025
  export declare function Editor({ placeholder, disabled, className, characterLimit, spellcheck, }: EditorProps): JSX_2.Element;
901
1026
 
902
1027
  /**
1028
+ * Lets you query and control the message editor.
1029
+ *
1030
+ * @remarks
1031
+ * Available inside the {@link https://talkjs.com/docs/UI_Components/Theme/Theme_components/MessageField | MessageField} theme component.
1032
+ * Connects with the internals of the {@link https://talkjs.com/docs/UI_Components/Theme/System_components/Editor | Editor} system component.
1033
+ *
903
1034
  * @public
904
1035
  */
905
1036
  export declare interface EditorController {
906
- isTyping: boolean;
1037
+ /**
1038
+ * True if the maximum message length has been exceeded.
1039
+ *
1040
+ * @remarks
1041
+ * Sending should be disabled when true
1042
+ */
907
1043
  atTextLimit: boolean;
1044
+ /**
1045
+ * True if the editor is empty.
1046
+ */
908
1047
  isEmpty: boolean;
1048
+ /**
1049
+ * The number of characters in the editor.
1050
+ *
1051
+ * @remarks
1052
+ * Note that this is an estimation, and it may slightly exceed the actual number of characters in the editor.
1053
+ */
909
1054
  characterCount: number;
1055
+ /**
1056
+ * Whether the emoji picker should be shown. Toggle with {@link toggleEmojiPicker}.
1057
+ */
910
1058
  showEmojiPicker: boolean;
1059
+ /** Send the message and clear the editor */
911
1060
  send(): void;
1061
+ /** Open the "share location" dialog */
912
1062
  shareLocation(): void;
1063
+ /** Open the "attach file" dialog */
913
1064
  attachFile(): void;
1065
+ /** Open or close the emoji picker */
914
1066
  toggleEmojiPicker(): void;
1067
+ /** Start recording a voice message */
915
1068
  recordVoiceMessage(): void;
916
1069
  }
917
1070
 
@@ -1011,6 +1164,18 @@ export declare interface FileBlockProps {
1011
1164
  downloadUrl?: string;
1012
1165
  }
1013
1166
 
1167
+ /**
1168
+ * An event object dispatched by the {@link ChatboxProps.onFocusMessage} event.
1169
+ *
1170
+ * @public
1171
+ */
1172
+ export declare interface FocusMessageEvent {
1173
+ /**
1174
+ * The message that was focused (or `null` if the focus was cleared)
1175
+ */
1176
+ message: MessageSnapshot | null;
1177
+ }
1178
+
1014
1179
  /**
1015
1180
  * Displays the given number of seconds in a human-friendly MM:SS or HH:MM:SS
1016
1181
  * format; whichever's shorter.
@@ -1055,6 +1220,79 @@ export declare function getPhotoUrlWithFallback(user: UserSnapshot): string;
1055
1220
  */
1056
1221
  export declare function getRandomColor(id: string): string;
1057
1222
 
1223
+ /**
1224
+ * Props passed to the GlobalSearchBox theme component.
1225
+ *
1226
+ * @public
1227
+ */
1228
+ export declare interface GlobalSearchBoxProps {
1229
+ /**
1230
+ * A collection of objects which are passed to all ConversationList theme components.
1231
+ */
1232
+ common: CommonConversationListProps;
1233
+ /**
1234
+ * Marks the given message ID or conversation ID as the currently selected search result.
1235
+ */
1236
+ query: string;
1237
+ /**
1238
+ * Sets a search query for the global search
1239
+ */
1240
+ setQuery(query: string): void;
1241
+ /**
1242
+ * Cancels the current search
1243
+ */
1244
+ cancel(): void;
1245
+ }
1246
+
1247
+ /**
1248
+ * Props passed to the GlobalSearchResultHeader theme component.
1249
+ *
1250
+ * @public
1251
+ */
1252
+ export declare interface GlobalSearchResultHeaderProps {
1253
+ /**
1254
+ * A collection of objects which are passed to all ConversationList theme components.
1255
+ */
1256
+ common: CommonConversationListProps;
1257
+ /**
1258
+ * Whether this header is displayed above conversation search results or message search results.
1259
+ */
1260
+ type: "messages" | "conversations";
1261
+ /**
1262
+ * True if more search results can be loaded.
1263
+ */
1264
+ canLoadMore: boolean;
1265
+ /**
1266
+ * Call this function to load more search results.
1267
+ */
1268
+ loadMore(): void;
1269
+ }
1270
+
1271
+ export declare interface GlobalSearchResultItemProps {
1272
+ /**
1273
+ * A collection of objects which are passed to all GlobalSearchResultItem theme components.
1274
+ */
1275
+ common: CommonConversationListProps;
1276
+ /**
1277
+ * The conversation that's being displayed.
1278
+ */
1279
+ conversation: ConversationSnapshot;
1280
+ /**
1281
+ * The message containing the result item. If it's missing, then the search
1282
+ * match is on the conversation itself.
1283
+ */
1284
+ message?: MessageSnapshot;
1285
+ /**
1286
+ * If `true`, this search result is the currently selected one.
1287
+ */
1288
+ isSelected: boolean;
1289
+ }
1290
+
1291
+ /**
1292
+ * @public
1293
+ */
1294
+ export declare type GlobalSearchStatus = "idle" | "searching" | "noResults";
1295
+
1058
1296
  /**
1059
1297
  * @public
1060
1298
  */
@@ -1074,6 +1312,22 @@ export declare interface GroupChatImageProps {
1074
1312
  participants: ParticipantSnapshot[];
1075
1313
  }
1076
1314
 
1315
+ export declare function Highlightable({ text, className }: HighlightableProps): React_2.DetailedReactHTMLElement<{
1316
+ className: string;
1317
+ }, HTMLElement>;
1318
+
1319
+ /**
1320
+ * @public
1321
+ */
1322
+ export declare interface HighlightableProps {
1323
+ /** The text to display */
1324
+ text: string;
1325
+ /**
1326
+ * @hidden
1327
+ */
1328
+ className?: string;
1329
+ }
1330
+
1077
1331
  /**
1078
1332
  * Parses a JSX-like React string into a React element tree.
1079
1333
  *
@@ -1176,22 +1430,6 @@ export declare class InboxController {
1176
1430
  * ```
1177
1431
  */
1178
1432
  get chatbox(): ChatboxController;
1179
- /**
1180
- * Select a conversation.
1181
- *
1182
- * @remarks
1183
- * This method is called from the theme's ConversationListItem component when
1184
- * the user clicks on the given conversation. You can also call it
1185
- * programmatically from elsewhere to simulate a user click.
1186
- *
1187
- * This method will trigger the {@link InboxProps.onSelectConversation} event.
1188
- * In most cases, if you want to change the selected conversation
1189
- * programmatically from outside the conversation list, it's better to pass a
1190
- * different value to the {@link InboxProps.selectedConversationId} prop
1191
- * instead, as that lets you keep your local state in sync with the props
1192
- * passed to the conversation list.
1193
- */
1194
- selectConversation(conversationId: string): void;
1195
1433
  }
1196
1434
 
1197
1435
  /**
@@ -1442,6 +1680,10 @@ export declare interface MessageProps {
1442
1680
  permissions: MessagePermissions;
1443
1681
  }
1444
1682
 
1683
+ export { MessageSearch }
1684
+
1685
+ export { MessageSearchState }
1686
+
1445
1687
  export { MessageSnapshot }
1446
1688
 
1447
1689
  /**
@@ -1625,6 +1867,13 @@ export declare interface ReplyBarProps {
1625
1867
  referencedMessage: MessageSnapshot;
1626
1868
  }
1627
1869
 
1870
+ export declare function SearchInput(props: SearchInputProps): JSX_2.Element;
1871
+
1872
+ export declare interface SearchInputProps extends React_2.HTMLAttributes<HTMLInputElement> {
1873
+ }
1874
+
1875
+ export { SearchMessageSnapshot }
1876
+
1628
1877
  /**
1629
1878
  * An event object dispatched by the
1630
1879
  * {@link ConversationListProps.onSelectConversation} event.
@@ -1634,9 +1883,14 @@ export declare interface ReplyBarProps {
1634
1883
  export declare interface SelectConversationEvent {
1635
1884
  currentUser: UserSnapshot;
1636
1885
  /**
1637
- * The newly-selected conversation.
1886
+ * The newly-selected conversation, or `null` if a conversation was
1887
+ * de-selected.
1638
1888
  */
1639
1889
  conversation: ConversationSnapshot | null;
1890
+ /**
1891
+ * The message that was scrolled into view within the conversation
1892
+ */
1893
+ focusedMessage?: MessageSnapshot;
1640
1894
  }
1641
1895
 
1642
1896
  /**
@@ -1730,6 +1984,7 @@ export declare interface Theme {
1730
1984
  TimeAgo: React_2.ComponentType<TimeAgoProps>;
1731
1985
  MessageActionMenu: React_2.ComponentType<MessageActionMenuProps>;
1732
1986
  CompactMessageContent: React_2.ComponentType<CompactMessageContentProps>;
1987
+ ChatSearchBox: React_2.ComponentType<ChatSearchBoxProps>;
1733
1988
  ChatHeader: React_2.ComponentType<ChatHeaderProps>;
1734
1989
  MessageListHeader: React_2.ComponentType<MessageListHeaderProps>;
1735
1990
  Message: React_2.ComponentType<MessageProps>;
@@ -1750,6 +2005,9 @@ export declare interface Theme {
1750
2005
  VoiceRecorder: React_2.ComponentType<VoiceRecorderProps>;
1751
2006
  RecordingPreview: React_2.ComponentType<RecordingPreviewProps>;
1752
2007
  ConversationListItem: React_2.ComponentType<ConversationListItemProps>;
2008
+ GlobalSearchResultItem: React_2.ComponentType<GlobalSearchResultItemProps>;
2009
+ GlobalSearchBox: React_2.ComponentType<GlobalSearchBoxProps>;
2010
+ GlobalSearchResultHeader: React_2.ComponentType<GlobalSearchResultHeaderProps>;
1753
2011
  }
1754
2012
 
1755
2013
  /**
@@ -1873,6 +2131,10 @@ export declare interface TranslationStrings {
1873
2131
  ARIA_MORE_ACTIONS: string;
1874
2132
  ARIA_REPLYING_TO: (senderName: string, content: string) => string;
1875
2133
  REPLY_MODE_LEAVE_ARIA_LABEL: string;
2134
+ SELECT_CONVERSATION: string;
2135
+ SEARCH_RESULTS_CONVERSATIONS: string;
2136
+ SEARCH_RESULTS_MESSAGES: string;
2137
+ SEARCH_RESULTS_SHOW_MORE: string;
1876
2138
  }
1877
2139
 
1878
2140
  export { TypingSnapshot }
@@ -1929,6 +2191,10 @@ export declare interface UserPermissions {
1929
2191
  * True if {@link https://talkjs.com/docs/Features/Messages/Mentions/ | mentions} are enabled.
1930
2192
  */
1931
2193
  canMention: boolean;
2194
+ /**
2195
+ * True if the user can use search and other related features.
2196
+ */
2197
+ canSearch: boolean;
1932
2198
  /**
1933
2199
  * True if
1934
2200
  * {@link https://talkjs.com/docs/Features/Conversations/Status_Indicator/ | online status indicators }
@@ -2008,7 +2274,7 @@ export declare interface VideoBlockProps {
2008
2274
  *
2009
2275
  * Uses the provided props to compose a complete {@link MessageSnapshot} object,
2010
2276
  * which is then passed to the
2011
- * {@link /UI_Components/Theme/Theme_components/Message | Message} component
2277
+ * {@link https://talkjs.com/docs/UI_Components/Theme/Theme_components/Message | Message} component
2012
2278
  * from your theme.
2013
2279
  *
2014
2280
  * Because the message isn't a real, stored message, the message is rendered as