@cometchat/chat-uikit-react-native 5.4.1 → 5.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/android/src/main/java/com/reactnativecometchatuikit/CometChatClipboardModule.kt +34 -0
  2. package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +562 -5
  3. package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorViewManager.kt +28 -1
  4. package/ios/CometChatClipboardModule.m +5 -0
  5. package/ios/CometChatClipboardModule.swift +22 -0
  6. package/ios/RichTextEditorView.swift +636 -31
  7. package/ios/RichTextEditorViewManager.m +3 -0
  8. package/ios/RichTextEditorViewManager.swift +24 -0
  9. package/package.json +5 -2
  10. package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +283 -64
  11. package/src/CometChatCompactMessageComposer/index.ts +2 -0
  12. package/src/CometChatConversations/CometChatConversations.tsx +299 -15
  13. package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +2 -2
  14. package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +15 -3
  15. package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +181 -12
  16. package/src/CometChatMessageInformation/CometChatMessageInformation.tsx +10 -1
  17. package/src/CometChatMessageList/CometChatMessageList.tsx +572 -16
  18. package/src/CometChatMessageList/components/MessageModals.tsx +30 -0
  19. package/src/CometChatMessageList/components/MessageOptionsSheet.tsx +21 -9
  20. package/src/CometChatMessageList/components/MessageQuickActions.tsx +162 -0
  21. package/src/CometChatPinnedMessages/CometChatPinnedMessages.tsx +964 -0
  22. package/src/CometChatPinnedMessages/index.ts +5 -0
  23. package/src/CometChatPinnedMessages/style.ts +216 -0
  24. package/src/CometChatRichTextEditor/RichTextEditorViewNativeComponent.ts +5 -0
  25. package/src/CometChatRichTextEditor/index.tsx +31 -1
  26. package/src/CometChatRichTextEditor/types.ts +21 -1
  27. package/src/CometChatSavedMessages/CometChatSavedMessages.tsx +871 -0
  28. package/src/CometChatSavedMessages/index.ts +5 -0
  29. package/src/CometChatSavedMessages/style.ts +159 -0
  30. package/src/CometChatSearch/CometChatSearch.tsx +71 -341
  31. package/src/CometChatThreadHeader/CometChatThreadHeader.tsx +22 -2
  32. package/src/index.ts +60 -0
  33. package/src/shared/CometChatUiKit/CometChatUIKit.ts +18 -1
  34. package/src/shared/base/Types.ts +5 -0
  35. package/src/shared/constants/UIKitConstants.ts +16 -17
  36. package/src/shared/constants/textPatterns.ts +27 -0
  37. package/src/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.ts +25 -225
  38. package/src/shared/events/CometChatUIEventHandler/Listener.ts +37 -0
  39. package/src/shared/events/ListenerInitializer.ts +20 -1
  40. package/src/shared/events/messages.ts +18 -0
  41. package/src/shared/formatters/CometChatRichTextFormatter/index.tsx +123 -25
  42. package/src/shared/formatters/CometChatTextFormatter.ts +22 -0
  43. package/src/shared/formatters/applyRawFormatters.ts +31 -0
  44. package/src/shared/formatters/index.ts +14 -0
  45. package/src/shared/formatters/richTextWireFormat.ts +165 -0
  46. package/src/shared/framework/MessageDataSource.tsx +309 -10
  47. package/src/shared/icons/components/thread-follow.tsx +13 -0
  48. package/src/shared/icons/components/thread-unfollow.tsx +13 -0
  49. package/src/shared/icons/components/unsave.tsx +13 -0
  50. package/src/shared/icons/icon-mapping.tsx +6 -0
  51. package/src/shared/index.ts +37 -0
  52. package/src/shared/resources/CometChatLocalizeNew/CometChatI18nProvider.tsx +15 -30
  53. package/src/shared/resources/CometChatLocalizeNew/CometChatLocalizationHelper.ts +138 -19
  54. package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +74 -1
  55. package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +54 -1
  56. package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +54 -1
  57. package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +54 -1
  58. package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +54 -1
  59. package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +54 -1
  60. package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +54 -1
  61. package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +54 -1
  62. package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +54 -1
  63. package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +54 -1
  64. package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +54 -1
  65. package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +54 -1
  66. package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +54 -1
  67. package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +54 -1
  68. package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +54 -1
  69. package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +54 -1
  70. package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +54 -1
  71. package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +54 -1
  72. package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +11 -0
  73. package/src/shared/utils/MarkdownUtils.ts +57 -6
  74. package/src/shared/utils/MessageUtils.tsx +80 -5
  75. package/src/shared/utils/PinConversationHelper.ts +245 -0
  76. package/src/shared/utils/PinSaveFeatureGates.ts +178 -0
  77. package/src/shared/utils/PinSaveHelper.ts +549 -0
  78. package/src/shared/utils/PinnedMessagesHelper.ts +65 -0
  79. package/src/shared/utils/SavedMessagesHelper.ts +267 -0
  80. package/src/shared/utils/ThreadSubscriptionHelper.ts +427 -0
  81. package/src/shared/utils/__testUtils__/messagesRequestBuilderMock.ts +37 -0
  82. package/src/shared/utils/cloneRequestBuilder.ts +25 -0
  83. package/src/shared/utils/conversationUtils.ts +8 -1
  84. package/src/shared/utils/stripRichText.ts +7 -0
  85. package/src/shared/views/ClipboardPasteHandler/ClipboardPasteHandler.ts +32 -0
  86. package/src/shared/views/ClipboardPasteHandler/NativeCometChatClipboardModule.ts +6 -0
  87. package/src/shared/views/CometChatActionSheet/CometChatActionSheet.tsx +4 -0
  88. package/src/shared/views/CometChatAudiosBubble/CometChatAudiosBubble.tsx +5 -0
  89. package/src/shared/views/CometChatAvatar/CometChatAvatar.tsx +17 -5
  90. package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +5 -1
  91. package/src/shared/views/CometChatCaptionText/CometChatCaptionText.tsx +8 -1
  92. package/src/shared/views/CometChatConfirmDialog/CometChatConfirmDialog.tsx +2 -0
  93. package/src/shared/views/CometChatConversationStarter/CometChatConversationStarter.tsx +91 -20
  94. package/src/shared/views/CometChatFilesBubble/CometChatFilesBubble.tsx +5 -0
  95. package/src/shared/views/CometChatImagesBubble/CometChatImagesBubble.tsx +5 -0
  96. package/src/shared/views/CometChatList/CometChatList.tsx +6 -1
  97. package/src/shared/views/CometChatList/Header.tsx +8 -2
  98. package/src/shared/views/CometChatListItem/CometChatListItem.tsx +4 -0
  99. package/src/shared/views/CometChatRetryButton/CometChatRetryButton.tsx +1 -0
  100. package/src/shared/views/CometChatSuggestionList/CometChatSuggestionList.tsx +4 -0
  101. package/src/shared/views/CometChatVideosBubble/CometChatVideosBubble.tsx +5 -0
  102. package/src/shared/views/CometChatVoiceNoteBubble/CometChatVoiceNoteBubble.tsx +5 -0
  103. package/src/shared/views/ErrorEmptyView/ErrorEmptyView.tsx +4 -1
  104. package/src/theme/default/default.ts +6 -0
  105. package/src/theme/type.ts +4 -0
@@ -38,6 +38,7 @@ RCT_EXTERN_METHOD(clear:(nonnull NSNumber *)node)
38
38
  RCT_EXTERN_METHOD(focus:(nonnull NSNumber *)node)
39
39
  RCT_EXTERN_METHOD(blur:(nonnull NSNumber *)node)
40
40
  RCT_EXTERN_METHOD(insertLink:(nonnull NSNumber *)node url:(nonnull NSString *)url text:(nonnull NSString *)text)
41
+ RCT_EXTERN_METHOD(replaceSelection:(nonnull NSNumber *)node text:(nonnull NSString *)text)
41
42
  RCT_EXTERN_METHOD(undo:(nonnull NSNumber *)node)
42
43
  RCT_EXTERN_METHOD(redo:(nonnull NSNumber *)node)
43
44
  RCT_EXTERN_METHOD(toggleBold:(nonnull NSNumber *)node)
@@ -61,6 +62,8 @@ RCT_EXTERN_METHOD(toggleChecklistItem:(nonnull NSNumber *)node)
61
62
  RCT_EXTERN_METHOD(setText:(nonnull NSNumber *)node text:(nonnull NSString *)text)
62
63
  RCT_EXTERN_METHOD(setSelection:(nonnull NSNumber *)node start:(nonnull NSInteger)start end:(nonnull NSInteger)end)
63
64
  RCT_EXTERN_METHOD(setMentionRanges:(nonnull NSNumber *)node ranges:(nonnull NSArray *)ranges)
65
+ RCT_EXTERN_METHOD(applyInlineStyle:(nonnull NSNumber *)node key:(nonnull NSString *)key value:(nonnull NSNumber *)value)
66
+ RCT_EXTERN_METHOD(removeInlineStyle:(nonnull NSNumber *)node key:(nonnull NSString *)key)
64
67
  RCT_EXTERN_METHOD(removeLink:(nonnull NSNumber *)node location:(nonnull NSInteger)location length:(nonnull NSInteger)length)
65
68
  RCT_EXTERN_METHOD(updateLink:(nonnull NSNumber *)node location:(nonnull NSInteger)location length:(nonnull NSInteger)length newUrl:(nonnull NSString *)newUrl newText:(nonnull NSString *)newText)
66
69
 
@@ -72,6 +72,14 @@ class RichTextEditorViewManager: RCTViewManager {
72
72
  }
73
73
  }
74
74
 
75
+ @objc func replaceSelection(_ node: NSNumber, text: NSString) {
76
+ DispatchQueue.main.async {
77
+ if let view = self.bridge?.uiManager.view(forReactTag: node) as? RichTextEditorView {
78
+ view.replaceSelection(with: text as String)
79
+ }
80
+ }
81
+ }
82
+
75
83
  @objc func undo(_ node: NSNumber) {
76
84
  DispatchQueue.main.async {
77
85
  if let view = self.bridge?.uiManager.view(forReactTag: node) as? RichTextEditorView {
@@ -273,6 +281,22 @@ class RichTextEditorViewManager: RCTViewManager {
273
281
  }
274
282
  }
275
283
 
284
+ @objc func applyInlineStyle(_ node: NSNumber, key: NSString, value: NSNumber) {
285
+ DispatchQueue.main.async {
286
+ if let view = self.bridge?.uiManager.view(forReactTag: node) as? RichTextEditorView {
287
+ view.applyInlineStyle(key: key as String, value: value.intValue)
288
+ }
289
+ }
290
+ }
291
+
292
+ @objc func removeInlineStyle(_ node: NSNumber, key: NSString) {
293
+ DispatchQueue.main.async {
294
+ if let view = self.bridge?.uiManager.view(forReactTag: node) as? RichTextEditorView {
295
+ view.removeInlineStyle(key: key as String)
296
+ }
297
+ }
298
+ }
299
+
276
300
  @objc func removeLink(_ node: NSNumber, location: Int, length: Int) {
277
301
  DispatchQueue.main.async {
278
302
  if let view = self.bridge?.uiManager.view(forReactTag: node) as? RichTextEditorView {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cometchat/chat-uikit-react-native",
3
- "version": "5.4.1",
3
+ "version": "5.5.1",
4
4
  "description": "Ready-to-use Chat UI Components for React Native",
5
5
  "main": "src/index",
6
6
  "module": "src/index",
@@ -90,7 +90,10 @@
90
90
  "preset": "react-native",
91
91
  "modulePathIgnorePatterns": [
92
92
  "<rootDir>/lib/"
93
- ]
93
+ ],
94
+ "moduleNameMapper": {
95
+ "\\.(wav|mp3|m4a|aac|ogg)$": "<rootDir>/jest/assetMock.js"
96
+ }
94
97
  },
95
98
  "commitlint": {
96
99
  "extends": [
@@ -31,7 +31,23 @@ import RichTextEditor, {
31
31
  type ContentChangeEvent,
32
32
  type ActiveStylesState,
33
33
  type PasteMediaItem,
34
+ type InlineStyleKey,
34
35
  } from '../CometChatRichTextEditor';
36
+ import {
37
+ COLOR_CLOSE_TAG,
38
+ HEX_COLOR_REGEX,
39
+ openColorTag,
40
+ matchColorTagAt,
41
+ stripColorTags,
42
+ } from '../shared/formatters/richTextWireFormat';
43
+ import { applyRawFormatters } from '../shared/formatters/applyRawFormatters';
44
+
45
+ /**
46
+ * Stack-key prefix for the value-carrying text-colour style during send serialization.
47
+ * The `<color=#rrggbb>…</color>` wire grammar itself lives in richTextWireFormat, so the
48
+ * composer that produces it and the formatter that renders it can never drift.
49
+ */
50
+ const TEXT_COLOR_STYLE_PREFIX = 'textColor:';
35
51
 
36
52
  /**
37
53
  * Link tap event data emitted by the native editor when a user taps an existing link.
@@ -267,7 +283,7 @@ const RecordAudio = (props: any) => {
267
283
  * MessagePreviewTray component for displaying edit/reply message preview (v5 pattern)
268
284
  */
269
285
  const MessagePreviewTray = (props: any) => {
270
- const { shouldShow = false, message = null, onClose = () => {}, title = '' } = props;
286
+ const { shouldShow = false, message = null, onClose = () => {}, title = '', textFormatters } = props;
271
287
  const { t } = useCometChatTranslation();
272
288
  if (!shouldShow) return null;
273
289
  // Editing a media caption: caption text is the editable subtitle; a muted overline (media-type icon +
@@ -277,9 +293,12 @@ const MessagePreviewTray = (props: any) => {
277
293
  <CometChatMessagePreview
278
294
  messagePreviewTitle={title}
279
295
  message={message}
296
+ textFormatters={textFormatters}
280
297
  {...(isMediaCaptionEdit
281
298
  ? {
282
- messagePreviewSubtitle: message.getCaption() ?? '',
299
+ // The caption goes in as a plain string, so a consumer's token is rewritten here —
300
+ // `textFormatters` above only reaches the message-text path.
301
+ messagePreviewSubtitle: applyRawFormatters(message.getCaption() ?? '', textFormatters),
283
302
  hideSubtitleIcon: true,
284
303
  overlineText: attachmentCountLabel(message.getType?.(), message.getAttachments?.()?.length ?? 1),
285
304
  }
@@ -520,6 +539,67 @@ export type SingleLineMessageComposerStyleInterface = DeepPartial<CometChatTheme
520
539
  *
521
540
  * This interface matches CometChatMessageComposerInterface for full API compatibility.
522
541
  */
542
+ /**
543
+ * Read/mutate surface for the composer input, handed to `ToolbarTrailingButtonsView`.
544
+ *
545
+ * Every method delegates to the same native `RichTextEditorRef` the built-in toolbar buttons use,
546
+ * so a consumer's trailing button behaves identically to a built-in one.
547
+ */
548
+ export interface ComposerInputHandle {
549
+ /** Current plain-text content of the composer. */
550
+ getText: () => string;
551
+ /** Current selection. Collapsed (start === end) when there is only a caret. */
552
+ getSelection: () => { start: number; end: number };
553
+ /** Replaces the composer content. */
554
+ setText: (text: string) => void;
555
+ /** Moves the selection/caret. Omit `end` for a collapsed caret. */
556
+ setSelection: (start: number, end?: number) => void;
557
+ /** Inserts a hyperlink, wrapping the current selection when there is one. */
558
+ insertLink: (url: string, text: string) => void;
559
+ /**
560
+ * Replaces the selected text, or inserts at the caret when nothing is selected — how a trailing
561
+ * button writes its own wire token into the composer.
562
+ *
563
+ * Prefer this over `getText` + `setText`: rewriting the whole input re-seeds the editor, while
564
+ * this touches only the selected run and leaves the formatting around it alone.
565
+ */
566
+ replaceSelection: (text: string) => void;
567
+ toggleBold: () => void;
568
+ toggleItalic: () => void;
569
+ toggleUnderline: () => void;
570
+ toggleStrikethrough: () => void;
571
+ toggleCode: () => void;
572
+ /** Removes all inline formatting from the current selection. */
573
+ clearFormatting: () => void;
574
+ /**
575
+ * Applies an arbitrary inline style to the current selection — the escape hatch for formats
576
+ * the built-in toolbar has no button for, e.g. a colour picker. `value` is any React Native
577
+ * colour string. Mentions inside the selection are skipped, and existing formatting on the
578
+ * range is preserved, so styles compose.
579
+ */
580
+ applyInlineStyle: (key: InlineStyleKey, value: string) => void;
581
+ /** Removes a style previously applied with `applyInlineStyle` from the current selection. */
582
+ removeInlineStyle: (key: InlineStyleKey) => void;
583
+ /**
584
+ * Mention ranges in the composer's plain-text coordinates. Native reports them on every
585
+ * content change, so they stay correct as edits shift the text around them.
586
+ */
587
+ getMentionRanges: () => Array<{ start: number; end: number }>;
588
+ /**
589
+ * Formatting state at the caret/selection — which inline styles are on, and the current
590
+ * block (`paragraph`, `codeBlock`, `bullet`, …).
591
+ *
592
+ * A trailing button needs this to decide whether it should be enabled or shown active.
593
+ * In particular `codeBlock` is true inside a fenced block, where send serializes raw text
594
+ * and drops every inline style — a colour applied there is visible in the composer and then
595
+ * silently lost on send, so a colour button must disable itself when this is true.
596
+ *
597
+ * Read from a ref, not render state, so it is correct immediately after a caret move rather
598
+ * than one render behind.
599
+ */
600
+ getActiveStyles: () => ActiveStylesState;
601
+ }
602
+
523
603
  export interface CometChatCompactMessageComposerInterface {
524
604
  /**
525
605
  * Message composer identifier.
@@ -635,6 +715,31 @@ export interface CometChatCompactMessageComposerInterface {
635
715
  composerId: string | number;
636
716
  }) => JSX.Element;
637
717
 
718
+ /**
719
+ * Renders consumer-supplied button(s) at the TRAILING end of the rich-text formatting toolbar,
720
+ * after a UIKit-inserted divider matching the toolbar's existing group separators.
721
+ *
722
+ * Only rendered while the toolbar itself is visible (`enableRichTextEditor` and not
723
+ * `hideRichTextFormattingOptions`) — the slot lives inside the toolbar. The native floating
724
+ * selection toolbar is out of scope; it cannot host injected JS views.
725
+ *
726
+ * Signature intentionally mirrors `AuxiliaryButtonView` / `SendButtonView`: every inline view slot
727
+ * on this composer is a `({ user, group, composerId }) => JSX.Element` render-prop, so consumers
728
+ * already expect this shape here rather than a bare `ReactNode`.
729
+ */
730
+ ToolbarTrailingButtonsView?: ({
731
+ user,
732
+ group,
733
+ composerId,
734
+ composer,
735
+ }: {
736
+ user?: CometChat.User;
737
+ group?: CometChat.Group;
738
+ composerId: string | number;
739
+ /** Read/mutate handle for the composer input — without it a trailing button is a dead button. */
740
+ composer: ComposerInputHandle;
741
+ }) => JSX.Element;
742
+
638
743
  /**
639
744
  * Replaces the default Secondary Button (attachment button).
640
745
  */
@@ -1067,6 +1172,7 @@ export const CometChatCompactMessageComposer = React.forwardRef(
1067
1172
  SendButtonView,
1068
1173
  onSendButtonPress,
1069
1174
  AuxiliaryButtonView,
1175
+ ToolbarTrailingButtonsView,
1070
1176
  SecondaryButtonView,
1071
1177
  auxiliaryButtonsAlignment,
1072
1178
  auxiliaryButtonAlignment, // deprecated alias
@@ -1928,13 +2034,15 @@ export const CometChatCompactMessageComposer = React.forwardRef(
1928
2034
 
1929
2035
  // Clone and store formatter using tracking character as key (matching MessageComposer pattern)
1930
2036
  const newFormatter = CommonUtils.clone(formatter);
1931
- if (trackingChar) {
1932
- allFormatters.current.set(trackingChar, newFormatter);
1933
-
1934
- // Set up tracking characters for mention detection
1935
- if (!trackingCharacters.current.includes(trackingChar)) {
1936
- trackingCharacters.current.push(trackingChar);
1937
- }
2037
+ // A formatter with no tracking character has no suggestion list, but it still takes part in
2038
+ // the send and edit-preview lifecycle — so key it by id instead of dropping it. The prefix
2039
+ // keeps it out of reach of the single-character lookup that opens the suggestion list.
2040
+ const formatterKey = trackingChar || `formatter:${formatter.getId?.() ?? allFormatters.current.size}`;
2041
+ allFormatters.current.set(formatterKey, newFormatter);
2042
+
2043
+ // Set up tracking characters for mention detection
2044
+ if (trackingChar && !trackingCharacters.current.includes(trackingChar)) {
2045
+ trackingCharacters.current.push(trackingChar);
1938
2046
  }
1939
2047
  });
1940
2048
  }, []);
@@ -2361,7 +2469,15 @@ export const CometChatCompactMessageComposer = React.forwardRef(
2361
2469
  // §8.4 — total attachments across the whole batch, so the conversation-list preview can
2362
2470
  // aggregate ("N attachments") from just the last fanned-out message it receives.
2363
2471
  const batchTotalCount = groups.reduce((sum, g) => sum + g.attachments.length, 0);
2364
- const caption = plainTextInputRef.current.trim();
2472
+ // Serialize the caption exactly like a plain text send does. Reading the plain-text ref
2473
+ // instead dropped every inline style — a coloured caption arrived as unstyled text
2474
+ // (ENG-38258) — because the wire markup is produced by blocksToMarkdown, never by the
2475
+ // plain-text mirror.
2476
+ const caption = (
2477
+ enableRichTextEditor && blocksRef.current.length > 0
2478
+ ? blocksToMarkdown(blocksRef.current)
2479
+ : plainTextInputRef.current
2480
+ ).trim();
2365
2481
  const currentReplyMessage = replyMessageRef.current;
2366
2482
  const replyMessageId = currentReplyMessage?.message?.getId?.() ?? null;
2367
2483
 
@@ -3445,6 +3561,11 @@ export const CometChatCompactMessageComposer = React.forwardRef(
3445
3561
  mode: ConversationOptionConstants.edit,
3446
3562
  });
3447
3563
 
3564
+ // A consumer's own wire token becomes UI Kit markup before the editor parses it, so an edit
3565
+ // opens showing the styling rather than the raw token. `handlePreMessageSend` below turns it
3566
+ // back into the consumer's format when the edit is saved.
3567
+ resolvedText = applyRawFormatters(resolvedText, textFormatters);
3568
+
3448
3569
  // Parse markdown into structured blocks and load into the native editor
3449
3570
  const blocks = markdownToBlocks(resolvedText);
3450
3571
  inputTextRef.current = resolvedText;
@@ -3506,6 +3627,46 @@ export const CometChatCompactMessageComposer = React.forwardRef(
3506
3627
  * - Clear the input field
3507
3628
  * - Reset streaming state
3508
3629
  */
3630
+ /**
3631
+ * Composer-input handle handed to `ToolbarTrailingButtonsView`.
3632
+ *
3633
+ * A trailing toolbar button is only useful if its action can read and mutate what is being
3634
+ * composed — otherwise it renders but can do nothing to the message. This exposes the minimal
3635
+ * surface for that: read text + selection, replace text, move the selection, insert a link, and
3636
+ * toggle the built-in inline formats.
3637
+ *
3638
+ * Deliberately a separate object from the `useImperativeHandle` ref below rather than a
3639
+ * refactor of it: both delegate to the same `inputRef`, so behaviour is identical, and the
3640
+ * public ref contract stays untouched.
3641
+ *
3642
+ * Note `selection` is a snapshot taken at render. Native owns the live selection and reports it
3643
+ * via onSelectionChange, so a consumer acting on a stale value should re-read rather than cache.
3644
+ */
3645
+ const composerInputHandle = useMemo(
3646
+ () => ({
3647
+ getText: () => plainTextInputRef.current,
3648
+ getSelection: () => selectionPosition,
3649
+ setText: (text: string) => setInputTextProgrammatic(text),
3650
+ setSelection: (start: number, end?: number) => inputRef.current?.setSelection(start, end),
3651
+ insertLink: (url: string, text: string) => inputRef.current?.insertLink(url, text),
3652
+ replaceSelection: (text: string) => inputRef.current?.replaceSelection(text),
3653
+ toggleBold: () => inputRef.current?.toggleBold(),
3654
+ toggleItalic: () => inputRef.current?.toggleItalic(),
3655
+ toggleUnderline: () => inputRef.current?.toggleUnderline(),
3656
+ toggleStrikethrough: () => inputRef.current?.toggleStrikethrough(),
3657
+ toggleCode: () => inputRef.current?.toggleCode(),
3658
+ clearFormatting: () => inputRef.current?.clearFormatting(),
3659
+ applyInlineStyle: (key: InlineStyleKey, value: string) =>
3660
+ inputRef.current?.applyInlineStyle(key, value),
3661
+ removeInlineStyle: (key: InlineStyleKey) => inputRef.current?.removeInlineStyle(key),
3662
+ getMentionRanges: () => inputRef.current?.getMentionRanges() ?? [],
3663
+ // Ref, not the state value: the memo would otherwise close over a stale snapshot and
3664
+ // report the previous caret's styles. Same reason shouldOpenList reads the ref.
3665
+ getActiveStyles: () => activeStylesRef.current,
3666
+ }),
3667
+ [selectionPosition, setInputTextProgrammatic]
3668
+ );
3669
+
3509
3670
  useImperativeHandle(ref, () => ({
3510
3671
  previewMessageForEdit: previewMessage,
3511
3672
  sendTextMessage,
@@ -3643,13 +3804,30 @@ export const CometChatCompactMessageComposer = React.forwardRef(
3643
3804
  const parseNested = (content: string, offset: number): string => {
3644
3805
  const inner = parseInlineStyles(content);
3645
3806
  for (const s of inner.styles) {
3646
- styles.push({ style: s.style, start: s.start + offset, end: s.end + offset });
3807
+ // Spread, don't hand-pick: picking only style/start/end drops the value-carrying
3808
+ // fields, so a link nested in bold loses its `url` and a colour run its `color`.
3809
+ styles.push({ ...s, start: s.start + offset, end: s.end + offset });
3647
3810
  }
3648
3811
  return inner.text;
3649
3812
  };
3650
3813
 
3651
3814
  let i = 0;
3652
3815
  while (i < line.length) {
3816
+ // Text colour: <color=#rrggbb>text</color> — depth-aware match; the grammar lives in
3817
+ // richTextWireFormat so this stays in lock-step with the renderer.
3818
+ if (line[i] === '<') {
3819
+ const colorTag = matchColorTagAt(line, i);
3820
+ if (colorTag) {
3821
+ const start = plain.length;
3822
+ const content = line.substring(colorTag.contentStart, colorTag.contentEnd);
3823
+ // parseNested returns the inner text — it does not append to `plain` itself.
3824
+ plain += parseNested(content, start);
3825
+ styles.push({ style: 'textColor', start, end: plain.length, color: colorTag.hex });
3826
+ i = colorTag.endIndex;
3827
+ continue;
3828
+ }
3829
+ }
3830
+
3653
3831
  // Markdown link: [text](url)
3654
3832
  if (line[i] === '[') {
3655
3833
  const closeBracket = line.indexOf('](', i + 1);
@@ -3672,7 +3850,11 @@ export const CometChatCompactMessageComposer = React.forwardRef(
3672
3850
  const closeIdx = line.indexOf('```', i + 3);
3673
3851
  if (closeIdx !== -1) {
3674
3852
  const start = plain.length;
3675
- const content = line.substring(i + 3, closeIdx);
3853
+ // Code carries no nested markup, so a `<color=…>` token inside one is not a style
3854
+ // here — but it must never be shown to the user as literal text either. Messages
3855
+ // already sent with the tag inside the span (see the serializer fix above) still
3856
+ // exist on the server, so strip rather than render (ENG-38253).
3857
+ const content = stripColorTags(line.substring(i + 3, closeIdx));
3676
3858
  plain += content;
3677
3859
  styles.push({ style: 'code', start, end: plain.length });
3678
3860
  i = closeIdx + 3;
@@ -3685,7 +3867,8 @@ export const CometChatCompactMessageComposer = React.forwardRef(
3685
3867
  const closeIdx = line.indexOf('`', i + 1);
3686
3868
  if (closeIdx !== -1) {
3687
3869
  const start = plain.length;
3688
- const content = line.substring(i + 1, closeIdx);
3870
+ // Same as the triple-backtick case: strip, never surface raw markup.
3871
+ const content = stripColorTags(line.substring(i + 1, closeIdx));
3689
3872
  plain += content;
3690
3873
  styles.push({ style: 'code', start, end: plain.length });
3691
3874
  i = closeIdx + 1;
@@ -3769,12 +3952,17 @@ export const CometChatCompactMessageComposer = React.forwardRef(
3769
3952
  const afterOpen = line.substring(3);
3770
3953
  const firstClose = afterOpen.indexOf('```');
3771
3954
 
3772
- if (firstClose > 0) {
3955
+ // `>= 0`, not `> 0`: an EMPTY code block serialises as six backticks (```` `````` ````),
3956
+ // where the close sits at offset 0. Treating that as "no close on this line" made the
3957
+ // parser read it as an OPEN fence and swallow every following line into the code block —
3958
+ // so editing a message that contained one showed the rest of the message as raw code
3959
+ // instead of its own blocks (ENG-38253).
3960
+ if (firstClose >= 0) {
3773
3961
  // Has closing ``` on the same line
3774
3962
  const afterFirstBlock = afterOpen.substring(firstClose + 3).trim();
3775
3963
  if (afterFirstBlock.length === 0) {
3776
3964
  // Single ```content``` on this line — treat as one code block
3777
- const content = afterOpen.substring(0, firstClose);
3965
+ const content = stripColorTags(afterOpen.substring(0, firstClose));
3778
3966
  blocks.push({ type: 'codeBlock', text: content, styles: [] });
3779
3967
  i++;
3780
3968
  continue;
@@ -3799,7 +3987,9 @@ export const CometChatCompactMessageComposer = React.forwardRef(
3799
3987
  blocks.push({ type: 'codeBlock', text: '', styles: [] });
3800
3988
  } else {
3801
3989
  for (const cl of codeLines) {
3802
- blocks.push({ type: 'codeBlock', text: cl, styles: [] });
3990
+ // Strip, never surface: a code block owns its styling, but legacy messages can
3991
+ // still carry a colour token inside the fence (ENG-38253).
3992
+ blocks.push({ type: 'codeBlock', text: stripColorTags(cl), styles: [] });
3803
3993
  }
3804
3994
  }
3805
3995
  // Skip closing fence
@@ -3890,6 +4080,16 @@ export const CometChatCompactMessageComposer = React.forwardRef(
3890
4080
  // Order matters: outer markers wrap inner ones
3891
4081
  const styleOrder = ['bold', 'underline', 'strikethrough', 'italic', 'code'];
3892
4082
 
4083
+ // Text colour carries a value, so it cannot be a constant entry in markerMap — its
4084
+ // stack key is `textColor:#rrggbb` and its markers are derived from the hex.
4085
+ const markersFor = (styleKey: string): { open: string; close: string } | undefined => {
4086
+ if (styleKey.startsWith(TEXT_COLOR_STYLE_PREFIX)) {
4087
+ const hex = styleKey.slice(TEXT_COLOR_STYLE_PREFIX.length);
4088
+ return { open: openColorTag(hex), close: COLOR_CLOSE_TAG };
4089
+ }
4090
+ return markerMap[styleKey];
4091
+ };
4092
+
3893
4093
  const applyInlineStyles = (text: string, styles: any[]): string => {
3894
4094
  if (!styles || styles.length === 0 || !text) return text;
3895
4095
 
@@ -3966,6 +4166,14 @@ export const CometChatCompactMessageComposer = React.forwardRef(
3966
4166
  if (sStart <= segStart && sEnd >= segEnd) {
3967
4167
  if (s.style === 'link' && s.url) {
3968
4168
  linkUrl = s.url;
4169
+ } else if (s.style === 'textColor' && s.color && HEX_COLOR_REGEX.test(s.color)) {
4170
+ const colorKey = `${TEXT_COLOR_STYLE_PREFIX}${String(s.color).toLowerCase()}`;
4171
+ // A character has exactly one colour. If ranges overlap, the later one is the
4172
+ // newer intent — replace rather than keep the first, which would silently render
4173
+ // the stale colour across the whole overlap.
4174
+ const prev = active.findIndex(a => a.startsWith(TEXT_COLOR_STYLE_PREFIX));
4175
+ if (prev !== -1) active.splice(prev, 1);
4176
+ active.push(colorKey);
3969
4177
  } else if (markerMap[s.style] !== undefined && !active.includes(s.style)) {
3970
4178
  active.push(s.style);
3971
4179
  }
@@ -3989,54 +4197,35 @@ export const CometChatCompactMessageComposer = React.forwardRef(
3989
4197
  for (let i = 0; i < segTexts.length; i++) {
3990
4198
  const curr = segActiveStyles[i];
3991
4199
  // Determine which styles in styleOrder should be active
3992
- const desired = styleOrder.filter(s => curr.includes(s));
3993
-
3994
- // Close styles that are open but not desired (pop from top of stack)
3995
- // We must close in reverse stack order (innermost first)
3996
- const toClose: string[] = [];
3997
- const toReopen: string[] = [];
3998
- // Find styles to close: anything in openStack not in desired
3999
- // But we may need to close styles above them too (and reopen)
4000
- const newStack: string[] = [];
4001
- for (const s of openStack) {
4002
- if (desired.includes(s)) {
4003
- newStack.push(s);
4004
- }
4200
+ const orderedStyles = styleOrder.filter(s => curr.includes(s));
4201
+ // Colour goes outermost so <color=…> always wraps **bold**, which keeps the token
4202
+ // contiguous and parseable by the render-side formatter.
4203
+ const colorKey = curr.find(s => s.startsWith(TEXT_COLOR_STYLE_PREFIX));
4204
+ const desired = colorKey ? [colorKey, ...orderedStyles] : orderedStyles;
4205
+
4206
+ // Unwind to the longest common prefix of what is OPEN and what is DESIRED, then open the
4207
+ // rest in `desired` order. The previous logic only closed markers that were not desired,
4208
+ // so a style that WAS desired but sat in the wrong ORDER stayed put — and a colour run
4209
+ // starting inside an already-open code span therefore opened its tag between the
4210
+ // backticks: `` `aaa<color=#e11d48>bbb</color>ccc` ``. A code span carries no nested
4211
+ // markup by definition, so the parser on the way back read those tags as literal text and
4212
+ // the edit composer showed raw `<color=…>` in code styling (ENG-38253). Matching the
4213
+ // prefix keeps `desired` order — colour outermost — wherever a run happens to start.
4214
+ let common = 0;
4215
+ while (
4216
+ common < openStack.length &&
4217
+ common < desired.length &&
4218
+ openStack[common] === desired[common]
4219
+ ) common++;
4220
+ // Close from the top down to the divergence point (innermost first).
4221
+ for (let j = openStack.length - 1; j >= common; j--) {
4222
+ result += markersFor(openStack[j])!.close;
4005
4223
  }
4006
- // Close everything from top of stack down to what we need
4007
- // Then reopen what should stay
4008
- if (openStack.length > 0) {
4009
- // Find the deepest style that needs to close
4010
- let closeFrom = -1;
4011
- for (let j = openStack.length - 1; j >= 0; j--) {
4012
- if (!desired.includes(openStack[j])) {
4013
- closeFrom = j;
4014
- break;
4015
- }
4016
- }
4017
- if (closeFrom >= 0) {
4018
- // Close everything from top down to closeFrom
4019
- for (let j = openStack.length - 1; j >= closeFrom; j--) {
4020
- result += markerMap[openStack[j]].close;
4021
- if (desired.includes(openStack[j])) {
4022
- toReopen.push(openStack[j]);
4023
- }
4024
- }
4025
- openStack = openStack.slice(0, closeFrom);
4026
- // Reopen styles that should stay (in their original order)
4027
- for (const s of toReopen.reverse()) {
4028
- result += markerMap[s].open;
4029
- openStack.push(s);
4030
- }
4031
- }
4032
- }
4033
-
4034
- // Open new styles that are desired but not yet open
4035
- for (const s of desired) {
4036
- if (!openStack.includes(s)) {
4037
- result += markerMap[s].open;
4038
- openStack.push(s);
4039
- }
4224
+ openStack = openStack.slice(0, common);
4225
+ // Open what is missing, outermost first.
4226
+ for (let j = common; j < desired.length; j++) {
4227
+ result += markersFor(desired[j])!.open;
4228
+ openStack.push(desired[j]);
4040
4229
  }
4041
4230
 
4042
4231
  // Add segment text (with link wrapping if needed)
@@ -4049,7 +4238,7 @@ export const CometChatCompactMessageComposer = React.forwardRef(
4049
4238
 
4050
4239
  // Close all remaining open styles (innermost first)
4051
4240
  for (let j = openStack.length - 1; j >= 0; j--) {
4052
- result += markerMap[openStack[j]].close;
4241
+ result += markersFor(openStack[j])!.close;
4053
4242
  }
4054
4243
 
4055
4244
  return result;
@@ -4354,6 +4543,13 @@ export const CometChatCompactMessageComposer = React.forwardRef(
4354
4543
  textMessage.setParentMessageId(parentMessageId as number);
4355
4544
  }
4356
4545
  outgoing = textMessage;
4546
+
4547
+ // An edit IS a send: without this a consumer's formatter never converts the text back to
4548
+ // its own wire format, and the mentions formatter never re-attaches the mentioned users.
4549
+ // Captions are left alone — the media send path does not run this hook either.
4550
+ allFormatters.current.forEach((formatter) => {
4551
+ outgoing = formatter.handlePreMessageSend(outgoing);
4552
+ });
4357
4553
  }
4358
4554
 
4359
4555
  // Clear input and preview
@@ -4879,6 +5075,7 @@ export const CometChatCompactMessageComposer = React.forwardRef(
4879
5075
  <MessagePreviewTray
4880
5076
  shouldShow={messagePreview !== null}
4881
5077
  message={messagePreview?.message}
5078
+ textFormatters={textFormatters}
4882
5079
  title={t('EDIT_MESSAGE')}
4883
5080
  onClose={() => {
4884
5081
  setMessagePreview(null);
@@ -4889,6 +5086,7 @@ export const CometChatCompactMessageComposer = React.forwardRef(
4889
5086
  {replyMessage && replyMessage.message && (
4890
5087
  <CometChatMessagePreview
4891
5088
  message={replyMessage.message}
5089
+ textFormatters={textFormatters}
4892
5090
  showCloseIcon={true}
4893
5091
  closeIconURL={ICONS.CLOSE}
4894
5092
  onCloseClick={closeReplyPreview}
@@ -5135,6 +5333,27 @@ export const CometChatCompactMessageComposer = React.forwardRef(
5135
5333
  </TouchableOpacity>
5136
5334
  );
5137
5335
  })}
5336
+ {/* Consumer-supplied trailing button(s), after a UIKit-inserted divider that
5337
+ reuses the toolbar's own group-separator primitive (same style + theme
5338
+ token as the built-in separators above). Guarded so an unset prop leaves
5339
+ the toolbar byte-identical to today — no divider, no extra node. */}
5340
+ {ToolbarTrailingButtonsView && (
5341
+ <>
5342
+ <View
5343
+ key='sep-trailing'
5344
+ style={[
5345
+ richTextToolbarStyles.separator,
5346
+ { backgroundColor: theme.color.borderLight as string },
5347
+ ]}
5348
+ />
5349
+ <ToolbarTrailingButtonsView
5350
+ user={user}
5351
+ group={group}
5352
+ composerId={id || 'single-line-composer'}
5353
+ composer={composerInputHandle}
5354
+ />
5355
+ </>
5356
+ )}
5138
5357
  </ScrollView>
5139
5358
  </View>
5140
5359
  )}
@@ -2,6 +2,7 @@ import {
2
2
  CometChatCompactMessageComposer,
3
3
  CometChatCompactMessageComposerInterface,
4
4
  SingleLineMessageComposerStyleInterface,
5
+ ComposerInputHandle,
5
6
  } from './CometChatCompactMessageComposer';
6
7
  import {
7
8
  SingleLineMessageComposerConfiguration,
@@ -34,6 +35,7 @@ export {
34
35
  SingleLineMessageComposerConfigurationInterface,
35
36
  CometChatCompactMessageComposerInterface,
36
37
  SingleLineMessageComposerStyleInterface,
38
+ ComposerInputHandle,
37
39
  // Default values exports
38
40
  SingleLineMessageComposerDefaults,
39
41
  SingleLineMessageComposerStyleDefaults,