@cometchat/chat-uikit-react-native 5.4.1 → 5.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/.gradle/7.4/checksums/checksums.lock +0 -0
- package/android/.gradle/7.4/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.4/gc.properties +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/src/main/java/com/reactnativecometchatuikit/CometChatClipboardModule.kt +34 -0
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +542 -5
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorViewManager.kt +20 -1
- package/ios/CometChatClipboardModule.m +5 -0
- package/ios/CometChatClipboardModule.swift +22 -0
- package/ios/RichTextEditorView.swift +593 -31
- package/ios/RichTextEditorViewManager.m +2 -0
- package/ios/RichTextEditorViewManager.swift +16 -0
- package/package.json +1 -1
- package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +245 -55
- package/src/CometChatCompactMessageComposer/index.ts +2 -0
- package/src/CometChatConversations/CometChatConversations.tsx +291 -14
- package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +181 -12
- package/src/CometChatMessageList/CometChatMessageList.tsx +568 -15
- package/src/CometChatMessageList/MANUAL_TEST_CASES.md +154 -0
- package/src/CometChatMessageList/components/MessageModals.tsx +30 -0
- package/src/CometChatMessageList/components/MessageOptionsSheet.tsx +14 -1
- package/src/CometChatMessageList/components/MessageQuickActions.tsx +162 -0
- package/src/CometChatPinnedMessages/CometChatPinnedMessages.tsx +940 -0
- package/src/CometChatPinnedMessages/index.ts +5 -0
- package/src/CometChatPinnedMessages/style.ts +216 -0
- package/src/CometChatRichTextEditor/RichTextEditorViewNativeComponent.ts +5 -0
- package/src/CometChatRichTextEditor/index.tsx +27 -1
- package/src/CometChatRichTextEditor/types.ts +19 -1
- package/src/CometChatSavedMessages/CometChatSavedMessages.tsx +634 -0
- package/src/CometChatSavedMessages/index.ts +5 -0
- package/src/CometChatSavedMessages/style.ts +159 -0
- package/src/CometChatSearch/CometChatSearch.tsx +47 -340
- package/src/CometChatThreadHeader/CometChatThreadHeader.tsx +22 -2
- package/src/index.ts +60 -0
- package/src/shared/CometChatUiKit/CometChatUIKit.ts +16 -0
- package/src/shared/base/Types.ts +5 -0
- package/src/shared/constants/UIKitConstants.ts +13 -0
- package/src/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.ts +34 -0
- package/src/shared/events/CometChatUIEventHandler/Listener.ts +37 -0
- package/src/shared/events/ListenerInitializer.ts +20 -1
- package/src/shared/events/messages.ts +18 -0
- package/src/shared/formatters/CometChatRichTextFormatter/index.tsx +92 -6
- package/src/shared/formatters/index.ts +14 -0
- package/src/shared/formatters/richTextWireFormat.ts +165 -0
- package/src/shared/framework/MessageDataSource.tsx +296 -3
- package/src/shared/icons/components/thread-follow.tsx +13 -0
- package/src/shared/icons/components/thread-unfollow.tsx +13 -0
- package/src/shared/icons/components/unsave.tsx +13 -0
- package/src/shared/icons/icon-mapping.tsx +6 -0
- package/src/shared/index.ts +37 -0
- package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +54 -0
- package/src/shared/utils/MarkdownUtils.ts +25 -4
- package/src/shared/utils/MessageUtils.tsx +80 -5
- package/src/shared/utils/PinConversationHelper.ts +245 -0
- package/src/shared/utils/PinSaveFeatureGates.ts +178 -0
- package/src/shared/utils/PinSaveHelper.ts +549 -0
- package/src/shared/utils/SavedMessagesHelper.ts +231 -0
- package/src/shared/utils/ThreadSubscriptionHelper.ts +427 -0
- package/src/shared/utils/conversationUtils.ts +8 -1
- package/src/shared/utils/stripRichText.ts +7 -0
- package/src/shared/views/ClipboardPasteHandler/ClipboardPasteHandler.ts +21 -0
- package/src/shared/views/ClipboardPasteHandler/NativeCometChatClipboardModule.ts +6 -0
- package/src/shared/views/CometChatActionSheet/CometChatActionSheet.tsx +4 -0
- package/src/shared/views/CometChatAvatar/CometChatAvatar.tsx +17 -5
- package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +1 -0
- package/src/shared/views/CometChatConfirmDialog/CometChatConfirmDialog.tsx +2 -0
- package/src/shared/views/CometChatConversationStarter/CometChatConversationStarter.tsx +91 -20
- package/src/shared/views/CometChatList/CometChatList.tsx +6 -1
- package/src/shared/views/CometChatListItem/CometChatListItem.tsx +4 -0
- package/src/shared/views/CometChatRetryButton/CometChatRetryButton.tsx +1 -0
- package/src/shared/views/CometChatSuggestionList/CometChatSuggestionList.tsx +4 -0
- package/src/shared/views/ErrorEmptyView/ErrorEmptyView.tsx +4 -1
- package/src/theme/default/default.ts +6 -0
- package/src/theme/type.ts +4 -0
- package/src/CometChatMessageList/PERFORMANCE_ARCHITECTURE.md +0 -478
- package/src/CometChatMessageList/SEARCH_NAV_PERF_PLAN.md +0 -613
- package/src/CometChatMessageList/SEARCH_NAV_SLOWNESS_FINDINGS_AND_FIX.md +0 -313
- package/src/shared/CometChatUiKit/CometChatUIKit.changes.md +0 -76
- package/src/shared/CometChatUiKit/checkAuthSettings-review.md +0 -211
|
@@ -61,6 +61,8 @@ RCT_EXTERN_METHOD(toggleChecklistItem:(nonnull NSNumber *)node)
|
|
|
61
61
|
RCT_EXTERN_METHOD(setText:(nonnull NSNumber *)node text:(nonnull NSString *)text)
|
|
62
62
|
RCT_EXTERN_METHOD(setSelection:(nonnull NSNumber *)node start:(nonnull NSInteger)start end:(nonnull NSInteger)end)
|
|
63
63
|
RCT_EXTERN_METHOD(setMentionRanges:(nonnull NSNumber *)node ranges:(nonnull NSArray *)ranges)
|
|
64
|
+
RCT_EXTERN_METHOD(applyInlineStyle:(nonnull NSNumber *)node key:(nonnull NSString *)key value:(nonnull NSNumber *)value)
|
|
65
|
+
RCT_EXTERN_METHOD(removeInlineStyle:(nonnull NSNumber *)node key:(nonnull NSString *)key)
|
|
64
66
|
RCT_EXTERN_METHOD(removeLink:(nonnull NSNumber *)node location:(nonnull NSInteger)location length:(nonnull NSInteger)length)
|
|
65
67
|
RCT_EXTERN_METHOD(updateLink:(nonnull NSNumber *)node location:(nonnull NSInteger)location length:(nonnull NSInteger)length newUrl:(nonnull NSString *)newUrl newText:(nonnull NSString *)newText)
|
|
66
68
|
|
|
@@ -273,6 +273,22 @@ class RichTextEditorViewManager: RCTViewManager {
|
|
|
273
273
|
}
|
|
274
274
|
}
|
|
275
275
|
|
|
276
|
+
@objc func applyInlineStyle(_ node: NSNumber, key: NSString, value: NSNumber) {
|
|
277
|
+
DispatchQueue.main.async {
|
|
278
|
+
if let view = self.bridge?.uiManager.view(forReactTag: node) as? RichTextEditorView {
|
|
279
|
+
view.applyInlineStyle(key: key as String, value: value.intValue)
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
@objc func removeInlineStyle(_ node: NSNumber, key: NSString) {
|
|
285
|
+
DispatchQueue.main.async {
|
|
286
|
+
if let view = self.bridge?.uiManager.view(forReactTag: node) as? RichTextEditorView {
|
|
287
|
+
view.removeInlineStyle(key: key as String)
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
276
292
|
@objc func removeLink(_ node: NSNumber, location: Int, length: Int) {
|
|
277
293
|
DispatchQueue.main.async {
|
|
278
294
|
if let view = self.bridge?.uiManager.view(forReactTag: node) as? RichTextEditorView {
|
package/package.json
CHANGED
|
@@ -31,7 +31,22 @@ 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
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Stack-key prefix for the value-carrying text-colour style during send serialization.
|
|
46
|
+
* The `<color=#rrggbb>…</color>` wire grammar itself lives in richTextWireFormat, so the
|
|
47
|
+
* composer that produces it and the formatter that renders it can never drift.
|
|
48
|
+
*/
|
|
49
|
+
const TEXT_COLOR_STYLE_PREFIX = 'textColor:';
|
|
35
50
|
|
|
36
51
|
/**
|
|
37
52
|
* Link tap event data emitted by the native editor when a user taps an existing link.
|
|
@@ -520,6 +535,59 @@ export type SingleLineMessageComposerStyleInterface = DeepPartial<CometChatTheme
|
|
|
520
535
|
*
|
|
521
536
|
* This interface matches CometChatMessageComposerInterface for full API compatibility.
|
|
522
537
|
*/
|
|
538
|
+
/**
|
|
539
|
+
* Read/mutate surface for the composer input, handed to `ToolbarTrailingButtonsView`.
|
|
540
|
+
*
|
|
541
|
+
* Every method delegates to the same native `RichTextEditorRef` the built-in toolbar buttons use,
|
|
542
|
+
* so a consumer's trailing button behaves identically to a built-in one.
|
|
543
|
+
*/
|
|
544
|
+
export interface ComposerInputHandle {
|
|
545
|
+
/** Current plain-text content of the composer. */
|
|
546
|
+
getText: () => string;
|
|
547
|
+
/** Current selection. Collapsed (start === end) when there is only a caret. */
|
|
548
|
+
getSelection: () => { start: number; end: number };
|
|
549
|
+
/** Replaces the composer content. */
|
|
550
|
+
setText: (text: string) => void;
|
|
551
|
+
/** Moves the selection/caret. Omit `end` for a collapsed caret. */
|
|
552
|
+
setSelection: (start: number, end?: number) => void;
|
|
553
|
+
/** Inserts a hyperlink, wrapping the current selection when there is one. */
|
|
554
|
+
insertLink: (url: string, text: string) => void;
|
|
555
|
+
toggleBold: () => void;
|
|
556
|
+
toggleItalic: () => void;
|
|
557
|
+
toggleUnderline: () => void;
|
|
558
|
+
toggleStrikethrough: () => void;
|
|
559
|
+
toggleCode: () => void;
|
|
560
|
+
/** Removes all inline formatting from the current selection. */
|
|
561
|
+
clearFormatting: () => void;
|
|
562
|
+
/**
|
|
563
|
+
* Applies an arbitrary inline style to the current selection — the escape hatch for formats
|
|
564
|
+
* the built-in toolbar has no button for, e.g. a colour picker. `value` is any React Native
|
|
565
|
+
* colour string. Mentions inside the selection are skipped, and existing formatting on the
|
|
566
|
+
* range is preserved, so styles compose.
|
|
567
|
+
*/
|
|
568
|
+
applyInlineStyle: (key: InlineStyleKey, value: string) => void;
|
|
569
|
+
/** Removes a style previously applied with `applyInlineStyle` from the current selection. */
|
|
570
|
+
removeInlineStyle: (key: InlineStyleKey) => void;
|
|
571
|
+
/**
|
|
572
|
+
* Mention ranges in the composer's plain-text coordinates. Native reports them on every
|
|
573
|
+
* content change, so they stay correct as edits shift the text around them.
|
|
574
|
+
*/
|
|
575
|
+
getMentionRanges: () => Array<{ start: number; end: number }>;
|
|
576
|
+
/**
|
|
577
|
+
* Formatting state at the caret/selection — which inline styles are on, and the current
|
|
578
|
+
* block (`paragraph`, `codeBlock`, `bullet`, …).
|
|
579
|
+
*
|
|
580
|
+
* A trailing button needs this to decide whether it should be enabled or shown active.
|
|
581
|
+
* In particular `codeBlock` is true inside a fenced block, where send serializes raw text
|
|
582
|
+
* and drops every inline style — a colour applied there is visible in the composer and then
|
|
583
|
+
* silently lost on send, so a colour button must disable itself when this is true.
|
|
584
|
+
*
|
|
585
|
+
* Read from a ref, not render state, so it is correct immediately after a caret move rather
|
|
586
|
+
* than one render behind.
|
|
587
|
+
*/
|
|
588
|
+
getActiveStyles: () => ActiveStylesState;
|
|
589
|
+
}
|
|
590
|
+
|
|
523
591
|
export interface CometChatCompactMessageComposerInterface {
|
|
524
592
|
/**
|
|
525
593
|
* Message composer identifier.
|
|
@@ -635,6 +703,31 @@ export interface CometChatCompactMessageComposerInterface {
|
|
|
635
703
|
composerId: string | number;
|
|
636
704
|
}) => JSX.Element;
|
|
637
705
|
|
|
706
|
+
/**
|
|
707
|
+
* Renders consumer-supplied button(s) at the TRAILING end of the rich-text formatting toolbar,
|
|
708
|
+
* after a UIKit-inserted divider matching the toolbar's existing group separators.
|
|
709
|
+
*
|
|
710
|
+
* Only rendered while the toolbar itself is visible (`enableRichTextEditor` and not
|
|
711
|
+
* `hideRichTextFormattingOptions`) — the slot lives inside the toolbar. The native floating
|
|
712
|
+
* selection toolbar is out of scope; it cannot host injected JS views.
|
|
713
|
+
*
|
|
714
|
+
* Signature intentionally mirrors `AuxiliaryButtonView` / `SendButtonView`: every inline view slot
|
|
715
|
+
* on this composer is a `({ user, group, composerId }) => JSX.Element` render-prop, so consumers
|
|
716
|
+
* already expect this shape here rather than a bare `ReactNode`.
|
|
717
|
+
*/
|
|
718
|
+
ToolbarTrailingButtonsView?: ({
|
|
719
|
+
user,
|
|
720
|
+
group,
|
|
721
|
+
composerId,
|
|
722
|
+
composer,
|
|
723
|
+
}: {
|
|
724
|
+
user?: CometChat.User;
|
|
725
|
+
group?: CometChat.Group;
|
|
726
|
+
composerId: string | number;
|
|
727
|
+
/** Read/mutate handle for the composer input — without it a trailing button is a dead button. */
|
|
728
|
+
composer: ComposerInputHandle;
|
|
729
|
+
}) => JSX.Element;
|
|
730
|
+
|
|
638
731
|
/**
|
|
639
732
|
* Replaces the default Secondary Button (attachment button).
|
|
640
733
|
*/
|
|
@@ -1067,6 +1160,7 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
1067
1160
|
SendButtonView,
|
|
1068
1161
|
onSendButtonPress,
|
|
1069
1162
|
AuxiliaryButtonView,
|
|
1163
|
+
ToolbarTrailingButtonsView,
|
|
1070
1164
|
SecondaryButtonView,
|
|
1071
1165
|
auxiliaryButtonsAlignment,
|
|
1072
1166
|
auxiliaryButtonAlignment, // deprecated alias
|
|
@@ -2361,7 +2455,15 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
2361
2455
|
// §8.4 — total attachments across the whole batch, so the conversation-list preview can
|
|
2362
2456
|
// aggregate ("N attachments") from just the last fanned-out message it receives.
|
|
2363
2457
|
const batchTotalCount = groups.reduce((sum, g) => sum + g.attachments.length, 0);
|
|
2364
|
-
|
|
2458
|
+
// Serialize the caption exactly like a plain text send does. Reading the plain-text ref
|
|
2459
|
+
// instead dropped every inline style — a coloured caption arrived as unstyled text
|
|
2460
|
+
// (ENG-38258) — because the wire markup is produced by blocksToMarkdown, never by the
|
|
2461
|
+
// plain-text mirror.
|
|
2462
|
+
const caption = (
|
|
2463
|
+
enableRichTextEditor && blocksRef.current.length > 0
|
|
2464
|
+
? blocksToMarkdown(blocksRef.current)
|
|
2465
|
+
: plainTextInputRef.current
|
|
2466
|
+
).trim();
|
|
2365
2467
|
const currentReplyMessage = replyMessageRef.current;
|
|
2366
2468
|
const replyMessageId = currentReplyMessage?.message?.getId?.() ?? null;
|
|
2367
2469
|
|
|
@@ -3506,6 +3608,45 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
3506
3608
|
* - Clear the input field
|
|
3507
3609
|
* - Reset streaming state
|
|
3508
3610
|
*/
|
|
3611
|
+
/**
|
|
3612
|
+
* Composer-input handle handed to `ToolbarTrailingButtonsView`.
|
|
3613
|
+
*
|
|
3614
|
+
* A trailing toolbar button is only useful if its action can read and mutate what is being
|
|
3615
|
+
* composed — otherwise it renders but can do nothing to the message. This exposes the minimal
|
|
3616
|
+
* surface for that: read text + selection, replace text, move the selection, insert a link, and
|
|
3617
|
+
* toggle the built-in inline formats.
|
|
3618
|
+
*
|
|
3619
|
+
* Deliberately a separate object from the `useImperativeHandle` ref below rather than a
|
|
3620
|
+
* refactor of it: both delegate to the same `inputRef`, so behaviour is identical, and the
|
|
3621
|
+
* public ref contract stays untouched.
|
|
3622
|
+
*
|
|
3623
|
+
* Note `selection` is a snapshot taken at render. Native owns the live selection and reports it
|
|
3624
|
+
* via onSelectionChange, so a consumer acting on a stale value should re-read rather than cache.
|
|
3625
|
+
*/
|
|
3626
|
+
const composerInputHandle = useMemo(
|
|
3627
|
+
() => ({
|
|
3628
|
+
getText: () => plainTextInputRef.current,
|
|
3629
|
+
getSelection: () => selectionPosition,
|
|
3630
|
+
setText: (text: string) => setInputTextProgrammatic(text),
|
|
3631
|
+
setSelection: (start: number, end?: number) => inputRef.current?.setSelection(start, end),
|
|
3632
|
+
insertLink: (url: string, text: string) => inputRef.current?.insertLink(url, text),
|
|
3633
|
+
toggleBold: () => inputRef.current?.toggleBold(),
|
|
3634
|
+
toggleItalic: () => inputRef.current?.toggleItalic(),
|
|
3635
|
+
toggleUnderline: () => inputRef.current?.toggleUnderline(),
|
|
3636
|
+
toggleStrikethrough: () => inputRef.current?.toggleStrikethrough(),
|
|
3637
|
+
toggleCode: () => inputRef.current?.toggleCode(),
|
|
3638
|
+
clearFormatting: () => inputRef.current?.clearFormatting(),
|
|
3639
|
+
applyInlineStyle: (key: InlineStyleKey, value: string) =>
|
|
3640
|
+
inputRef.current?.applyInlineStyle(key, value),
|
|
3641
|
+
removeInlineStyle: (key: InlineStyleKey) => inputRef.current?.removeInlineStyle(key),
|
|
3642
|
+
getMentionRanges: () => inputRef.current?.getMentionRanges() ?? [],
|
|
3643
|
+
// Ref, not the state value: the memo would otherwise close over a stale snapshot and
|
|
3644
|
+
// report the previous caret's styles. Same reason shouldOpenList reads the ref.
|
|
3645
|
+
getActiveStyles: () => activeStylesRef.current,
|
|
3646
|
+
}),
|
|
3647
|
+
[selectionPosition, setInputTextProgrammatic]
|
|
3648
|
+
);
|
|
3649
|
+
|
|
3509
3650
|
useImperativeHandle(ref, () => ({
|
|
3510
3651
|
previewMessageForEdit: previewMessage,
|
|
3511
3652
|
sendTextMessage,
|
|
@@ -3643,13 +3784,30 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
3643
3784
|
const parseNested = (content: string, offset: number): string => {
|
|
3644
3785
|
const inner = parseInlineStyles(content);
|
|
3645
3786
|
for (const s of inner.styles) {
|
|
3646
|
-
|
|
3787
|
+
// Spread, don't hand-pick: picking only style/start/end drops the value-carrying
|
|
3788
|
+
// fields, so a link nested in bold loses its `url` and a colour run its `color`.
|
|
3789
|
+
styles.push({ ...s, start: s.start + offset, end: s.end + offset });
|
|
3647
3790
|
}
|
|
3648
3791
|
return inner.text;
|
|
3649
3792
|
};
|
|
3650
3793
|
|
|
3651
3794
|
let i = 0;
|
|
3652
3795
|
while (i < line.length) {
|
|
3796
|
+
// Text colour: <color=#rrggbb>text</color> — depth-aware match; the grammar lives in
|
|
3797
|
+
// richTextWireFormat so this stays in lock-step with the renderer.
|
|
3798
|
+
if (line[i] === '<') {
|
|
3799
|
+
const colorTag = matchColorTagAt(line, i);
|
|
3800
|
+
if (colorTag) {
|
|
3801
|
+
const start = plain.length;
|
|
3802
|
+
const content = line.substring(colorTag.contentStart, colorTag.contentEnd);
|
|
3803
|
+
// parseNested returns the inner text — it does not append to `plain` itself.
|
|
3804
|
+
plain += parseNested(content, start);
|
|
3805
|
+
styles.push({ style: 'textColor', start, end: plain.length, color: colorTag.hex });
|
|
3806
|
+
i = colorTag.endIndex;
|
|
3807
|
+
continue;
|
|
3808
|
+
}
|
|
3809
|
+
}
|
|
3810
|
+
|
|
3653
3811
|
// Markdown link: [text](url)
|
|
3654
3812
|
if (line[i] === '[') {
|
|
3655
3813
|
const closeBracket = line.indexOf('](', i + 1);
|
|
@@ -3672,7 +3830,11 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
3672
3830
|
const closeIdx = line.indexOf('```', i + 3);
|
|
3673
3831
|
if (closeIdx !== -1) {
|
|
3674
3832
|
const start = plain.length;
|
|
3675
|
-
|
|
3833
|
+
// Code carries no nested markup, so a `<color=…>` token inside one is not a style
|
|
3834
|
+
// here — but it must never be shown to the user as literal text either. Messages
|
|
3835
|
+
// already sent with the tag inside the span (see the serializer fix above) still
|
|
3836
|
+
// exist on the server, so strip rather than render (ENG-38253).
|
|
3837
|
+
const content = stripColorTags(line.substring(i + 3, closeIdx));
|
|
3676
3838
|
plain += content;
|
|
3677
3839
|
styles.push({ style: 'code', start, end: plain.length });
|
|
3678
3840
|
i = closeIdx + 3;
|
|
@@ -3685,7 +3847,8 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
3685
3847
|
const closeIdx = line.indexOf('`', i + 1);
|
|
3686
3848
|
if (closeIdx !== -1) {
|
|
3687
3849
|
const start = plain.length;
|
|
3688
|
-
|
|
3850
|
+
// Same as the triple-backtick case: strip, never surface raw markup.
|
|
3851
|
+
const content = stripColorTags(line.substring(i + 1, closeIdx));
|
|
3689
3852
|
plain += content;
|
|
3690
3853
|
styles.push({ style: 'code', start, end: plain.length });
|
|
3691
3854
|
i = closeIdx + 1;
|
|
@@ -3769,12 +3932,17 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
3769
3932
|
const afterOpen = line.substring(3);
|
|
3770
3933
|
const firstClose = afterOpen.indexOf('```');
|
|
3771
3934
|
|
|
3772
|
-
|
|
3935
|
+
// `>= 0`, not `> 0`: an EMPTY code block serialises as six backticks (```` `````` ````),
|
|
3936
|
+
// where the close sits at offset 0. Treating that as "no close on this line" made the
|
|
3937
|
+
// parser read it as an OPEN fence and swallow every following line into the code block —
|
|
3938
|
+
// so editing a message that contained one showed the rest of the message as raw code
|
|
3939
|
+
// instead of its own blocks (ENG-38253).
|
|
3940
|
+
if (firstClose >= 0) {
|
|
3773
3941
|
// Has closing ``` on the same line
|
|
3774
3942
|
const afterFirstBlock = afterOpen.substring(firstClose + 3).trim();
|
|
3775
3943
|
if (afterFirstBlock.length === 0) {
|
|
3776
3944
|
// Single ```content``` on this line — treat as one code block
|
|
3777
|
-
const content = afterOpen.substring(0, firstClose);
|
|
3945
|
+
const content = stripColorTags(afterOpen.substring(0, firstClose));
|
|
3778
3946
|
blocks.push({ type: 'codeBlock', text: content, styles: [] });
|
|
3779
3947
|
i++;
|
|
3780
3948
|
continue;
|
|
@@ -3799,7 +3967,9 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
3799
3967
|
blocks.push({ type: 'codeBlock', text: '', styles: [] });
|
|
3800
3968
|
} else {
|
|
3801
3969
|
for (const cl of codeLines) {
|
|
3802
|
-
|
|
3970
|
+
// Strip, never surface: a code block owns its styling, but legacy messages can
|
|
3971
|
+
// still carry a colour token inside the fence (ENG-38253).
|
|
3972
|
+
blocks.push({ type: 'codeBlock', text: stripColorTags(cl), styles: [] });
|
|
3803
3973
|
}
|
|
3804
3974
|
}
|
|
3805
3975
|
// Skip closing fence
|
|
@@ -3890,6 +4060,16 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
3890
4060
|
// Order matters: outer markers wrap inner ones
|
|
3891
4061
|
const styleOrder = ['bold', 'underline', 'strikethrough', 'italic', 'code'];
|
|
3892
4062
|
|
|
4063
|
+
// Text colour carries a value, so it cannot be a constant entry in markerMap — its
|
|
4064
|
+
// stack key is `textColor:#rrggbb` and its markers are derived from the hex.
|
|
4065
|
+
const markersFor = (styleKey: string): { open: string; close: string } | undefined => {
|
|
4066
|
+
if (styleKey.startsWith(TEXT_COLOR_STYLE_PREFIX)) {
|
|
4067
|
+
const hex = styleKey.slice(TEXT_COLOR_STYLE_PREFIX.length);
|
|
4068
|
+
return { open: openColorTag(hex), close: COLOR_CLOSE_TAG };
|
|
4069
|
+
}
|
|
4070
|
+
return markerMap[styleKey];
|
|
4071
|
+
};
|
|
4072
|
+
|
|
3893
4073
|
const applyInlineStyles = (text: string, styles: any[]): string => {
|
|
3894
4074
|
if (!styles || styles.length === 0 || !text) return text;
|
|
3895
4075
|
|
|
@@ -3966,6 +4146,14 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
3966
4146
|
if (sStart <= segStart && sEnd >= segEnd) {
|
|
3967
4147
|
if (s.style === 'link' && s.url) {
|
|
3968
4148
|
linkUrl = s.url;
|
|
4149
|
+
} else if (s.style === 'textColor' && s.color && HEX_COLOR_REGEX.test(s.color)) {
|
|
4150
|
+
const colorKey = `${TEXT_COLOR_STYLE_PREFIX}${String(s.color).toLowerCase()}`;
|
|
4151
|
+
// A character has exactly one colour. If ranges overlap, the later one is the
|
|
4152
|
+
// newer intent — replace rather than keep the first, which would silently render
|
|
4153
|
+
// the stale colour across the whole overlap.
|
|
4154
|
+
const prev = active.findIndex(a => a.startsWith(TEXT_COLOR_STYLE_PREFIX));
|
|
4155
|
+
if (prev !== -1) active.splice(prev, 1);
|
|
4156
|
+
active.push(colorKey);
|
|
3969
4157
|
} else if (markerMap[s.style] !== undefined && !active.includes(s.style)) {
|
|
3970
4158
|
active.push(s.style);
|
|
3971
4159
|
}
|
|
@@ -3989,54 +4177,35 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
3989
4177
|
for (let i = 0; i < segTexts.length; i++) {
|
|
3990
4178
|
const curr = segActiveStyles[i];
|
|
3991
4179
|
// Determine which styles in styleOrder should be active
|
|
3992
|
-
const
|
|
3993
|
-
|
|
3994
|
-
//
|
|
3995
|
-
|
|
3996
|
-
const
|
|
3997
|
-
|
|
3998
|
-
//
|
|
3999
|
-
//
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4180
|
+
const orderedStyles = styleOrder.filter(s => curr.includes(s));
|
|
4181
|
+
// Colour goes outermost so <color=…> always wraps **bold**, which keeps the token
|
|
4182
|
+
// contiguous and parseable by the render-side formatter.
|
|
4183
|
+
const colorKey = curr.find(s => s.startsWith(TEXT_COLOR_STYLE_PREFIX));
|
|
4184
|
+
const desired = colorKey ? [colorKey, ...orderedStyles] : orderedStyles;
|
|
4185
|
+
|
|
4186
|
+
// Unwind to the longest common prefix of what is OPEN and what is DESIRED, then open the
|
|
4187
|
+
// rest in `desired` order. The previous logic only closed markers that were not desired,
|
|
4188
|
+
// so a style that WAS desired but sat in the wrong ORDER stayed put — and a colour run
|
|
4189
|
+
// starting inside an already-open code span therefore opened its tag between the
|
|
4190
|
+
// backticks: `` `aaa<color=#e11d48>bbb</color>ccc` ``. A code span carries no nested
|
|
4191
|
+
// markup by definition, so the parser on the way back read those tags as literal text and
|
|
4192
|
+
// the edit composer showed raw `<color=…>` in code styling (ENG-38253). Matching the
|
|
4193
|
+
// prefix keeps `desired` order — colour outermost — wherever a run happens to start.
|
|
4194
|
+
let common = 0;
|
|
4195
|
+
while (
|
|
4196
|
+
common < openStack.length &&
|
|
4197
|
+
common < desired.length &&
|
|
4198
|
+
openStack[common] === desired[common]
|
|
4199
|
+
) common++;
|
|
4200
|
+
// Close from the top down to the divergence point (innermost first).
|
|
4201
|
+
for (let j = openStack.length - 1; j >= common; j--) {
|
|
4202
|
+
result += markersFor(openStack[j])!.close;
|
|
4005
4203
|
}
|
|
4006
|
-
|
|
4007
|
-
//
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
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
|
-
}
|
|
4204
|
+
openStack = openStack.slice(0, common);
|
|
4205
|
+
// Open what is missing, outermost first.
|
|
4206
|
+
for (let j = common; j < desired.length; j++) {
|
|
4207
|
+
result += markersFor(desired[j])!.open;
|
|
4208
|
+
openStack.push(desired[j]);
|
|
4040
4209
|
}
|
|
4041
4210
|
|
|
4042
4211
|
// Add segment text (with link wrapping if needed)
|
|
@@ -4049,7 +4218,7 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
4049
4218
|
|
|
4050
4219
|
// Close all remaining open styles (innermost first)
|
|
4051
4220
|
for (let j = openStack.length - 1; j >= 0; j--) {
|
|
4052
|
-
result +=
|
|
4221
|
+
result += markersFor(openStack[j])!.close;
|
|
4053
4222
|
}
|
|
4054
4223
|
|
|
4055
4224
|
return result;
|
|
@@ -5135,6 +5304,27 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
5135
5304
|
</TouchableOpacity>
|
|
5136
5305
|
);
|
|
5137
5306
|
})}
|
|
5307
|
+
{/* Consumer-supplied trailing button(s), after a UIKit-inserted divider that
|
|
5308
|
+
reuses the toolbar's own group-separator primitive (same style + theme
|
|
5309
|
+
token as the built-in separators above). Guarded so an unset prop leaves
|
|
5310
|
+
the toolbar byte-identical to today — no divider, no extra node. */}
|
|
5311
|
+
{ToolbarTrailingButtonsView && (
|
|
5312
|
+
<>
|
|
5313
|
+
<View
|
|
5314
|
+
key='sep-trailing'
|
|
5315
|
+
style={[
|
|
5316
|
+
richTextToolbarStyles.separator,
|
|
5317
|
+
{ backgroundColor: theme.color.borderLight as string },
|
|
5318
|
+
]}
|
|
5319
|
+
/>
|
|
5320
|
+
<ToolbarTrailingButtonsView
|
|
5321
|
+
user={user}
|
|
5322
|
+
group={group}
|
|
5323
|
+
composerId={id || 'single-line-composer'}
|
|
5324
|
+
composer={composerInputHandle}
|
|
5325
|
+
/>
|
|
5326
|
+
</>
|
|
5327
|
+
)}
|
|
5138
5328
|
</ScrollView>
|
|
5139
5329
|
</View>
|
|
5140
5330
|
)}
|
|
@@ -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,
|