@cometchat/chat-uikit-react-native 5.2.11 → 5.3.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.
- package/android/build.gradle +3 -0
- package/android/src/main/java/com/reactnativecometchatuikit/CometchatUiKitPackage.java +4 -1
- package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +909 -10
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorPackage.kt +24 -0
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +5382 -0
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorViewManager.kt +452 -0
- package/ios/FileManager.m +430 -3
- package/ios/RichTextEditorView.swift +5504 -0
- package/ios/RichTextEditorViewManager.m +66 -0
- package/ios/RichTextEditorViewManager.swift +291 -0
- package/ios/ToolbarIcons.swift +736 -0
- package/package.json +1 -1
- package/react-native-cometchat-ui-kit.podspec +1 -1
- package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +4602 -0
- package/src/CometChatCompactMessageComposer/SingleLineTextComposerConfiguration.tsx +568 -0
- package/src/CometChatCompactMessageComposer/heightUtils.ts +204 -0
- package/src/CometChatCompactMessageComposer/index.ts +56 -0
- package/src/CometChatCompactMessageComposer/resources/index.ts +5 -0
- package/src/CometChatCompactMessageComposer/styles.ts +291 -0
- package/src/CometChatConversations/CometChatConversations.tsx +141 -14
- package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +6 -0
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +1 -20
- package/src/CometChatMessageComposer/styles.tsx +0 -1
- package/src/CometChatMessageList/CometChatMessageList.tsx +76 -30
- package/src/CometChatRichTextEditor/RichTextEditorViewNativeComponent.ts +105 -0
- package/src/CometChatRichTextEditor/index.tsx +385 -0
- package/src/CometChatRichTextEditor/types.ts +162 -0
- package/src/CometChatSearch/CometChatSearch.tsx +35 -29
- package/src/calls/CallUtils.ts +4 -4
- package/src/index.ts +48 -1
- package/src/shared/CometChatUiKit/CometChatUIKit.ts +2 -0
- package/src/shared/constants/UIKitConstants.ts +12 -1
- package/src/shared/events/ListenerInitializer.ts +6 -0
- package/src/shared/events/messages.ts +2 -0
- package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +5 -5
- package/src/shared/formatters/CometChatRichTextFormatter/index.tsx +768 -0
- package/src/shared/formatters/index.ts +3 -0
- package/src/shared/framework/MessageDataSource.tsx +93 -2
- package/src/shared/helper/composerHelpers.ts +553 -0
- package/src/shared/helper/useKeyboard.tsx +7 -17
- package/src/shared/icons/components/code-blocks.tsx +13 -0
- package/src/shared/icons/components/code.tsx +11 -0
- package/src/shared/icons/components/format-bold.tsx +11 -0
- package/src/shared/icons/components/format-italic.tsx +11 -0
- package/src/shared/icons/components/format-list-bulleted.tsx +11 -0
- package/src/shared/icons/components/format-list-numbered.tsx +11 -0
- package/src/shared/icons/components/format-quote.tsx +13 -0
- package/src/shared/icons/components/format-strikethrough.tsx +13 -0
- package/src/shared/icons/components/format-underlined.tsx +11 -0
- package/src/shared/icons/components/smileys-&-people.tsx +1 -1
- package/src/shared/icons/icon-mapping.tsx +18 -0
- package/src/shared/index.ts +54 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +37 -32
- package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +5 -0
- package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +17 -12
- package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +505 -500
- package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +18 -13
- package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +17 -12
- package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +504 -499
- package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +504 -499
- package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +504 -499
- package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +18 -13
- package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +17 -12
- package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +505 -500
- package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +17 -12
- package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +17 -12
- package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +18 -13
- package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +505 -500
- package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +17 -12
- package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +18 -13
- package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +132 -11
- package/src/shared/utils/CometChatMessagePreview/style.ts +1 -3
- package/src/shared/utils/CommonUtils.ts +18 -1
- package/src/shared/utils/MarkdownUtils.ts +143 -0
- package/src/shared/utils/MentionUtils.ts +37 -0
- package/src/shared/utils/MessageReceiptUtils.ts +5 -4
- package/src/shared/utils/MessageUtils.tsx +5 -3
- package/src/shared/utils/index.ts +5 -0
- package/src/shared/views/CometChatAudioBubble/CometChatAudioBubble.tsx +1 -1
- package/src/shared/views/CometChatInlineAudioRecorder/AudioWaveformVisualizer.tsx +417 -0
- package/src/shared/views/CometChatInlineAudioRecorder/CometChatInlineAudioRecorder.tsx +537 -0
- package/src/shared/views/CometChatInlineAudioRecorder/index.ts +34 -0
- package/src/shared/views/CometChatInlineAudioRecorder/style.ts +155 -0
- package/src/shared/views/CometChatInlineAudioRecorder/types.ts +303 -0
- package/src/shared/views/CometChatInlineAudioRecorder/useAudioRecorder.ts +1336 -0
- package/src/shared/views/CometChatLinkConfirmPopup/CometChatLinkConfirmPopup.tsx +183 -0
- package/src/shared/views/CometChatLinkConfirmPopup/index.ts +13 -0
- package/src/shared/views/CometChatLinkConfirmPopup/style.ts +128 -0
- package/src/shared/views/CometChatList/Header.tsx +2 -1
- package/src/shared/views/CometChatListItem/style.ts +1 -0
- package/src/shared/views/CometChatSendButtonView/CometChatSendButtonView.tsx +32 -29
- package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +64 -16
- package/src/shared/views/index.ts +39 -0
|
@@ -0,0 +1,768 @@
|
|
|
1
|
+
import { CometChat } from "@cometchat/chat-sdk-react-native";
|
|
2
|
+
import React, { JSX } from "react";
|
|
3
|
+
import { Text, TextStyle, ViewStyle, Platform, Linking, View } from "react-native";
|
|
4
|
+
import { CometChatTextFormatter } from "../CometChatTextFormatter";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Style configuration for rich text formatting
|
|
8
|
+
*/
|
|
9
|
+
export interface RichTextStyle {
|
|
10
|
+
boldStyle?: TextStyle;
|
|
11
|
+
italicStyle?: TextStyle;
|
|
12
|
+
underlineStyle?: TextStyle;
|
|
13
|
+
strikethroughStyle?: TextStyle;
|
|
14
|
+
inlineCodeStyle?: TextStyle;
|
|
15
|
+
inlineCodeContainerStyle?: TextStyle;
|
|
16
|
+
codeBlockStyle?: TextStyle;
|
|
17
|
+
codeBlockContainerStyle?: ViewStyle;
|
|
18
|
+
blockquoteContainerStyle?: ViewStyle;
|
|
19
|
+
blockquoteBarStyle?: ViewStyle;
|
|
20
|
+
bulletListStyle?: TextStyle;
|
|
21
|
+
orderedListStyle?: TextStyle;
|
|
22
|
+
linkStyle?: TextStyle;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Pre-compiled regex patterns — avoids recompilation on every call
|
|
26
|
+
const ORDERED_LIST_REGEX = /^(\d+)\.(?:\s(.*))?$/;
|
|
27
|
+
const ORDERED_LIST_DETECT_REGEX = /^\d+\.(\s|$)/;
|
|
28
|
+
const LINK_REGEX = /\[([^\]]+)\]\(([^)]+)\)/;
|
|
29
|
+
const URL_PROTOCOL_REGEX = /^(https?|mailto|tel):/i;
|
|
30
|
+
// Patterns for detecting list items inside blockquote content (ENG-31998)
|
|
31
|
+
const QUOTE_BULLET_REGEX = /^- (.*)$/;
|
|
32
|
+
const QUOTE_ORDERED_REGEX = /^(\d+)\.\s(.*)$/;
|
|
33
|
+
// Mention pattern — used to exclude mention UIDs from markdown marker detection
|
|
34
|
+
const MENTION_PATTERN_REGEX = /<@(?:uid|all):[^>]*>/g;
|
|
35
|
+
|
|
36
|
+
// Pre-allocated style objects — avoids creating new objects on every render
|
|
37
|
+
const LIST_ROW_STYLE = { flexDirection: 'row' as const, flexShrink: 1 as const };
|
|
38
|
+
const BULLET_MARKER_STYLE = { width: 18 };
|
|
39
|
+
const ORDERED_MARKER_STYLE = { width: 24 };
|
|
40
|
+
const LIST_CONTENT_STYLE = { flexShrink: 1, flexGrow: 1 };
|
|
41
|
+
const BQ_TEXT_ROW_STYLE = { flexDirection: 'row' as const, flexShrink: 1 as const };
|
|
42
|
+
|
|
43
|
+
// Blockquote container styles — matches Figma spec (node 14736:1573987)
|
|
44
|
+
// Rounded container with semi-transparent white bg, thick left bar, content area.
|
|
45
|
+
// The bubble itself sizes to the text content; the blockquote fills the bubble width.
|
|
46
|
+
const BQ_CONTAINER_STYLE = {
|
|
47
|
+
flexDirection: 'row' as const,
|
|
48
|
+
alignItems: 'stretch' as const,
|
|
49
|
+
backgroundColor: 'rgba(255,255,255,0.2)',
|
|
50
|
+
borderRadius: 8,
|
|
51
|
+
overflow: 'hidden' as const,
|
|
52
|
+
};
|
|
53
|
+
// Thick rounded vertical bar on the left — Figma "Border" element (node 14736:1573988)
|
|
54
|
+
const BQ_BAR_STYLE = {
|
|
55
|
+
width: 4,
|
|
56
|
+
backgroundColor: 'rgba(255,255,255,0.6)',
|
|
57
|
+
borderRadius: 2,
|
|
58
|
+
marginVertical: 4,
|
|
59
|
+
marginLeft: 4,
|
|
60
|
+
};
|
|
61
|
+
const BQ_CONTENT_STYLE = {
|
|
62
|
+
flexShrink: 1 as const,
|
|
63
|
+
paddingHorizontal: 8,
|
|
64
|
+
paddingVertical: 4,
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
/** Check if a line is a bullet list item (- prefix) */
|
|
70
|
+
function isBulletLine(l: string): boolean {
|
|
71
|
+
const trimmed = l.trim();
|
|
72
|
+
return trimmed.startsWith("- ") || trimmed === "-" || l.startsWith("- ");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const defaultRichTextStyle: RichTextStyle = {
|
|
76
|
+
boldStyle: { fontWeight: "700" },
|
|
77
|
+
// React Native Fabric (New Architecture, RN 0.76+) has a known bug on iOS where
|
|
78
|
+
// fontStyle: "italic" is ignored when a custom fontFamily (e.g. "Inter") is set
|
|
79
|
+
// on a parent <Text>. The workaround is to override fontFamily on the italic
|
|
80
|
+
// child with the iOS system font (".AppleSystemUIFont"), which allows fontStyle
|
|
81
|
+
// to work correctly. The visual difference between Inter italic and SF Pro italic
|
|
82
|
+
// at body size (14px) is minimal.
|
|
83
|
+
// See: https://github.com/facebook/react-native/issues/46090
|
|
84
|
+
italicStyle: Platform.OS === "ios"
|
|
85
|
+
? { fontFamily: ".AppleSystemUIFont", fontStyle: "italic" }
|
|
86
|
+
: { fontStyle: "italic" },
|
|
87
|
+
underlineStyle: { textDecorationLine: "underline" },
|
|
88
|
+
strikethroughStyle: { textDecorationLine: "line-through" },
|
|
89
|
+
inlineCodeStyle: {
|
|
90
|
+
fontSize: 14,
|
|
91
|
+
fontWeight: "400",
|
|
92
|
+
lineHeight: 16.8,
|
|
93
|
+
color: "#6852D6",
|
|
94
|
+
},
|
|
95
|
+
inlineCodeContainerStyle: {
|
|
96
|
+
backgroundColor: "#F5F5F5",
|
|
97
|
+
borderRadius: 2,
|
|
98
|
+
paddingHorizontal: 2,
|
|
99
|
+
paddingVertical: 0,
|
|
100
|
+
},
|
|
101
|
+
codeBlockStyle: {
|
|
102
|
+
fontFamily: Platform.OS === "ios" ? "Menlo" : "monospace",
|
|
103
|
+
fontSize: 13,
|
|
104
|
+
color: "#141414",
|
|
105
|
+
},
|
|
106
|
+
codeBlockContainerStyle: {
|
|
107
|
+
backgroundColor: "#FAFAFA",
|
|
108
|
+
borderRadius: 4,
|
|
109
|
+
borderWidth: 1,
|
|
110
|
+
borderColor: "#E8E8E8",
|
|
111
|
+
padding: 12,
|
|
112
|
+
},
|
|
113
|
+
blockquoteContainerStyle: {},
|
|
114
|
+
blockquoteBarStyle: {},
|
|
115
|
+
bulletListStyle: {},
|
|
116
|
+
orderedListStyle: {},
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* CometChatRichTextFormatter
|
|
121
|
+
*
|
|
122
|
+
* Parses markdown syntax in message text and renders styled React Native Text components.
|
|
123
|
+
*
|
|
124
|
+
* Supported formats:
|
|
125
|
+
* - Bold: **text**
|
|
126
|
+
* - Italic: _text_
|
|
127
|
+
* - Underline: __text__
|
|
128
|
+
* - Strikethrough: ~~text~~
|
|
129
|
+
* - Inline code: `text`
|
|
130
|
+
* - Code blocks: ```code```
|
|
131
|
+
* - Bullet lists: - item
|
|
132
|
+
* - Ordered lists: 1. item
|
|
133
|
+
* - Blockquotes: > text
|
|
134
|
+
*/
|
|
135
|
+
export class CometChatRichTextFormatter extends CometChatTextFormatter {
|
|
136
|
+
protected style: RichTextStyle = { ...defaultRichTextStyle };
|
|
137
|
+
|
|
138
|
+
constructor(loggedInUser?: CometChat.User) {
|
|
139
|
+
super();
|
|
140
|
+
this.loggedInUser = loggedInUser;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
setStyle = (style: Partial<RichTextStyle>): void => {
|
|
144
|
+
this.style = { ...defaultRichTextStyle, ...style };
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
getStyle = (): RichTextStyle => {
|
|
148
|
+
return this.style;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
getFormattedText(inputText: string | null | JSX.Element): string | null | JSX.Element {
|
|
152
|
+
if (!inputText) return null;
|
|
153
|
+
if (typeof inputText === "string") {
|
|
154
|
+
if (!this.hasMarkdown(inputText)) return inputText;
|
|
155
|
+
return this.renderMarkdown(inputText);
|
|
156
|
+
} else if (React.isValidElement(inputText)) {
|
|
157
|
+
const element = inputText as React.ReactElement<any>;
|
|
158
|
+
if (element.props?.children && typeof element.props.children === "string") {
|
|
159
|
+
if (!this.hasMarkdown(element.props.children)) return inputText;
|
|
160
|
+
return React.cloneElement(element, {
|
|
161
|
+
...element.props,
|
|
162
|
+
children: this.renderMarkdown(element.props.children),
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
return inputText;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return inputText;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
private hasMarkdown(text: string): boolean {
|
|
172
|
+
if (!text) return false;
|
|
173
|
+
// Strip mention patterns before checking — mention UIDs can contain
|
|
174
|
+
// underscores, brackets, and "> " sequences that trigger false positives.
|
|
175
|
+
const cleaned = text.replace(MENTION_PATTERN_REGEX, '');
|
|
176
|
+
if (cleaned.indexOf("**") >= 0) return true;
|
|
177
|
+
if (cleaned.indexOf("__") >= 0) return true;
|
|
178
|
+
if (cleaned.indexOf("<u>") >= 0) return true;
|
|
179
|
+
if (cleaned.indexOf("~~") >= 0) return true;
|
|
180
|
+
if (cleaned.indexOf("`") >= 0) return true;
|
|
181
|
+
if (cleaned.indexOf("_") >= 0) return true;
|
|
182
|
+
if (cleaned.indexOf("[") >= 0) return true;
|
|
183
|
+
if (cleaned.indexOf("- ") >= 0) return true;
|
|
184
|
+
if (cleaned.indexOf("> ") >= 0) return true;
|
|
185
|
+
if (cleaned.indexOf("▎ ") >= 0) return true;
|
|
186
|
+
const lines = cleaned.split("\n");
|
|
187
|
+
for (let i = 0; i < lines.length; i++) {
|
|
188
|
+
if (ORDERED_LIST_DETECT_REGEX.test(lines[i].trim())) return true;
|
|
189
|
+
}
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
private renderMarkdown(text: string): JSX.Element {
|
|
194
|
+
const lines = text.split("\n");
|
|
195
|
+
const elements: JSX.Element[] = [];
|
|
196
|
+
let lineIndex = 0;
|
|
197
|
+
let hasViewChildren = false;
|
|
198
|
+
// Running counter for ordered lists — continues across bullet list interruptions (Slack behavior)
|
|
199
|
+
let orderedListCounter = 0;
|
|
200
|
+
|
|
201
|
+
while (lineIndex < lines.length) {
|
|
202
|
+
const line = lines[lineIndex];
|
|
203
|
+
const trimmedLine = line.trim();
|
|
204
|
+
|
|
205
|
+
// Code blocks (```)
|
|
206
|
+
if (trimmedLine.startsWith("```")) {
|
|
207
|
+
// Check for single-line ```content``` (opening and closing on same line)
|
|
208
|
+
const afterOpen = trimmedLine.substring(3);
|
|
209
|
+
const firstClose = afterOpen.indexOf("```");
|
|
210
|
+
if (firstClose > 0) {
|
|
211
|
+
const afterClose = afterOpen.substring(firstClose + 3).trim();
|
|
212
|
+
if (afterClose.length === 0) {
|
|
213
|
+
// Standalone ```content``` — render as block-level code block (same as fenced)
|
|
214
|
+
hasViewChildren = true;
|
|
215
|
+
const content = afterOpen.substring(0, firstClose);
|
|
216
|
+
elements.push(
|
|
217
|
+
<View
|
|
218
|
+
key={`code-${elements.length}`}
|
|
219
|
+
style={[
|
|
220
|
+
{
|
|
221
|
+
backgroundColor: "transparent",
|
|
222
|
+
borderRadius: 4,
|
|
223
|
+
padding: 12,
|
|
224
|
+
},
|
|
225
|
+
this.style.codeBlockContainerStyle,
|
|
226
|
+
]}
|
|
227
|
+
>
|
|
228
|
+
<Text style={[this.style.codeBlockStyle]}>{content}</Text>
|
|
229
|
+
</View>
|
|
230
|
+
);
|
|
231
|
+
lineIndex++;
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
// Mixed content line (text + ```code``` + text) — inline rendering
|
|
235
|
+
elements.push(
|
|
236
|
+
<Text key={`line-${elements.length}`}>
|
|
237
|
+
{this.parseInlineFormats(line)}
|
|
238
|
+
</Text>
|
|
239
|
+
);
|
|
240
|
+
lineIndex++;
|
|
241
|
+
if (lineIndex < lines.length && line.length > 0) {
|
|
242
|
+
elements.push(<Text key={`nl-${elements.length}`}>{"\n"}</Text>);
|
|
243
|
+
}
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// Multi-line fenced code block
|
|
248
|
+
hasViewChildren = true;
|
|
249
|
+
const codeLines: string[] = [];
|
|
250
|
+
lineIndex++;
|
|
251
|
+
while (lineIndex < lines.length && !lines[lineIndex].trim().startsWith("```")) {
|
|
252
|
+
codeLines.push(lines[lineIndex]);
|
|
253
|
+
lineIndex++;
|
|
254
|
+
}
|
|
255
|
+
if (lineIndex < lines.length) {
|
|
256
|
+
lineIndex++; // Skip closing ``` only if it exists
|
|
257
|
+
}
|
|
258
|
+
// Render code block content as plain monospaced text — skip parseInlineFormats
|
|
259
|
+
// and findLink() so URLs inside code blocks remain unformatted (Req 2.1)
|
|
260
|
+
elements.push(
|
|
261
|
+
<View
|
|
262
|
+
key={`code-${elements.length}`}
|
|
263
|
+
style={[
|
|
264
|
+
{
|
|
265
|
+
backgroundColor: "transparent",
|
|
266
|
+
borderRadius: 4,
|
|
267
|
+
padding: 12,
|
|
268
|
+
},
|
|
269
|
+
this.style.codeBlockContainerStyle,
|
|
270
|
+
]}
|
|
271
|
+
>
|
|
272
|
+
<Text
|
|
273
|
+
style={[
|
|
274
|
+
this.style.codeBlockStyle,
|
|
275
|
+
]}
|
|
276
|
+
>
|
|
277
|
+
{codeLines.join("\n")}
|
|
278
|
+
</Text>
|
|
279
|
+
</View>
|
|
280
|
+
);
|
|
281
|
+
if (lineIndex < lines.length) {
|
|
282
|
+
elements.push(<Text key={`nl-${elements.length}`}>{"\n"}</Text>);
|
|
283
|
+
}
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// Blockquotes (> or ▎ ) — Slack-style with vertical bar on left
|
|
288
|
+
if (trimmedLine.startsWith("> ") || trimmedLine.startsWith("▎ ")) {
|
|
289
|
+
hasViewChildren = true;
|
|
290
|
+
// Collect consecutive blockquote lines into one block
|
|
291
|
+
const quoteLines: string[] = [];
|
|
292
|
+
while (lineIndex < lines.length && (lines[lineIndex].trim().startsWith("> ") || lines[lineIndex].trim().startsWith("▎ "))) {
|
|
293
|
+
const ql = lines[lineIndex].trim();
|
|
294
|
+
quoteLines.push(ql.startsWith("> ") ? ql.substring(2) : ql.substring(2));
|
|
295
|
+
lineIndex++;
|
|
296
|
+
}
|
|
297
|
+
// Render blockquote content — detect list items (ENG-31998)
|
|
298
|
+
const quoteContent: JSX.Element[] = [];
|
|
299
|
+
let quoteOrderedCounter = 0;
|
|
300
|
+
for (let i = 0; i < quoteLines.length; i++) {
|
|
301
|
+
const ql = quoteLines[i];
|
|
302
|
+
const bulletMatch = ql.match(QUOTE_BULLET_REGEX);
|
|
303
|
+
const orderedMatch = ql.match(QUOTE_ORDERED_REGEX);
|
|
304
|
+
if (bulletMatch) {
|
|
305
|
+
// Bullet items inside blockquote: render with marker + flex row
|
|
306
|
+
// Don't reset quoteOrderedCounter — numbering continues across bullet interruptions (Slack behavior)
|
|
307
|
+
quoteContent.push(
|
|
308
|
+
<View key={`ql-${i}`} style={LIST_ROW_STYLE}>
|
|
309
|
+
<Text style={BULLET_MARKER_STYLE}>{"‧ "}</Text>
|
|
310
|
+
<Text style={LIST_CONTENT_STYLE}>
|
|
311
|
+
{bulletMatch[1].trim() === '' ? ' ' : this.parseInlineFormats(bulletMatch[1])}
|
|
312
|
+
</Text>
|
|
313
|
+
</View>
|
|
314
|
+
);
|
|
315
|
+
} else if (orderedMatch) {
|
|
316
|
+
// Numbered item inside blockquote: render with counter + flex row
|
|
317
|
+
quoteOrderedCounter++;
|
|
318
|
+
quoteContent.push(
|
|
319
|
+
<View key={`ql-${i}`} style={LIST_ROW_STYLE}>
|
|
320
|
+
<Text style={ORDERED_MARKER_STYLE}>{`${quoteOrderedCounter}. `}</Text>
|
|
321
|
+
<Text style={LIST_CONTENT_STYLE}>
|
|
322
|
+
{orderedMatch[2].trim() === '' ? ' ' : this.parseInlineFormats(orderedMatch[2])}
|
|
323
|
+
</Text>
|
|
324
|
+
</View>
|
|
325
|
+
);
|
|
326
|
+
} else {
|
|
327
|
+
// Plain blockquote text — inline formats supported (Req 15.3)
|
|
328
|
+
// Wrap in View with flex:1 so long text wraps within blockquote bounds
|
|
329
|
+
quoteOrderedCounter = 0;
|
|
330
|
+
quoteContent.push(
|
|
331
|
+
<View key={`ql-${i}`} style={BQ_TEXT_ROW_STYLE}>
|
|
332
|
+
<Text style={LIST_CONTENT_STYLE}>
|
|
333
|
+
{this.parseInlineFormats(ql)}
|
|
334
|
+
</Text>
|
|
335
|
+
</View>
|
|
336
|
+
);
|
|
337
|
+
// No \n separator — View elements stack naturally; \n caused large
|
|
338
|
+
// vertical gaps between plain text lines inside blockquotes.
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
// Blockquote container with left bar — Figma spec (node 14736:1573987)
|
|
342
|
+
// Uses style config properties for theme-aware customization (OCP)
|
|
343
|
+
elements.push(
|
|
344
|
+
<View
|
|
345
|
+
key={`quote-${elements.length}`}
|
|
346
|
+
style={[
|
|
347
|
+
BQ_CONTAINER_STYLE,
|
|
348
|
+
this.style.blockquoteContainerStyle,
|
|
349
|
+
]}
|
|
350
|
+
>
|
|
351
|
+
<View style={[BQ_BAR_STYLE, this.style.blockquoteBarStyle]} />
|
|
352
|
+
<View style={BQ_CONTENT_STYLE}>
|
|
353
|
+
{quoteContent}
|
|
354
|
+
</View>
|
|
355
|
+
</View>
|
|
356
|
+
);
|
|
357
|
+
// No \n separator after blockquote — same reason as bullet/ordered lists:
|
|
358
|
+
// View elements stack naturally, and the whitespace-only filter in
|
|
359
|
+
// flushTextGroup handles any stray newline Text nodes.
|
|
360
|
+
continue;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// Bullet lists (- ) — also match empty items where trailing space is trimmed (Req 8.2)
|
|
364
|
+
if (isBulletLine(line)) {
|
|
365
|
+
hasViewChildren = true;
|
|
366
|
+
const listItems: string[] = [];
|
|
367
|
+
while (lineIndex < lines.length && isBulletLine(lines[lineIndex])) {
|
|
368
|
+
const raw = lines[lineIndex];
|
|
369
|
+
// Extract content after "- " prefix; handle trimmed empty items
|
|
370
|
+
const trimmed = raw.trim();
|
|
371
|
+
const itemText = trimmed.startsWith("- ") ? trimmed.substring(2) : "";
|
|
372
|
+
listItems.push(itemText);
|
|
373
|
+
lineIndex++;
|
|
374
|
+
}
|
|
375
|
+
for (let i = 0; i < listItems.length; i++) {
|
|
376
|
+
elements.push(
|
|
377
|
+
<View key={`bullet-${elements.length}`} style={LIST_ROW_STYLE}>
|
|
378
|
+
<Text style={BULLET_MARKER_STYLE}>{"‧ "}</Text>
|
|
379
|
+
<Text style={LIST_CONTENT_STYLE}>
|
|
380
|
+
{listItems[i].trim() === '' ? ' ' : this.parseInlineFormats(listItems[i])}
|
|
381
|
+
</Text>
|
|
382
|
+
</View>
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
// No \n separator — View elements stack naturally; \n caused blank lines
|
|
386
|
+
// between mixed ordered/bullet list groups in the bubble renderer.
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// Ordered lists (1. ) — regex handles empty items where content is trimmed away (Req 8.2)
|
|
391
|
+
const orderedMatch = trimmedLine.match(ORDERED_LIST_REGEX);
|
|
392
|
+
if (orderedMatch) {
|
|
393
|
+
hasViewChildren = true;
|
|
394
|
+
const listItems: string[] = [];
|
|
395
|
+
while (lineIndex < lines.length) {
|
|
396
|
+
const itemMatch = lines[lineIndex].trim().match(ORDERED_LIST_REGEX);
|
|
397
|
+
if (itemMatch) {
|
|
398
|
+
listItems.push(itemMatch[2] ?? '');
|
|
399
|
+
lineIndex++;
|
|
400
|
+
} else {
|
|
401
|
+
break;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
for (let i = 0; i < listItems.length; i++) {
|
|
405
|
+
orderedListCounter++;
|
|
406
|
+
elements.push(
|
|
407
|
+
<View key={`ordered-${elements.length}`} style={LIST_ROW_STYLE}>
|
|
408
|
+
<Text style={ORDERED_MARKER_STYLE}>{`${orderedListCounter}. `}</Text>
|
|
409
|
+
<Text style={LIST_CONTENT_STYLE}>
|
|
410
|
+
{listItems[i].trim() === '' ? ' ' : this.parseInlineFormats(listItems[i])}
|
|
411
|
+
</Text>
|
|
412
|
+
</View>
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
// No \n separator — same reason as bullet lists above.
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// Regular line
|
|
420
|
+
if (line.length > 0) {
|
|
421
|
+
elements.push(
|
|
422
|
+
<Text key={`line-${elements.length}`}>
|
|
423
|
+
{this.parseInlineFormats(line)}
|
|
424
|
+
</Text>
|
|
425
|
+
);
|
|
426
|
+
}
|
|
427
|
+
lineIndex++;
|
|
428
|
+
if (lineIndex < lines.length && line.length > 0) {
|
|
429
|
+
elements.push(<Text key={`nl-${elements.length}`}>{"\n"}</Text>);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
if (elements.length === 0) return <Text key="empty">{text}</Text>;
|
|
434
|
+
|
|
435
|
+
// If View children are present (blockquotes or inline code containers),
|
|
436
|
+
// we must use a View root because View children cannot be nested inside Text.
|
|
437
|
+
if (hasViewChildren) {
|
|
438
|
+
// Group consecutive Text elements together, keep View elements separate
|
|
439
|
+
const grouped: JSX.Element[] = [];
|
|
440
|
+
let textGroup: JSX.Element[] = [];
|
|
441
|
+
|
|
442
|
+
const flushTextGroup = () => {
|
|
443
|
+
if (textGroup.length > 0) {
|
|
444
|
+
// Skip groups that are only newline/whitespace Text nodes — these appear
|
|
445
|
+
// between list blocks and would render as blank lines in the bubble.
|
|
446
|
+
const isOnlyWhitespace = textGroup.every(el => {
|
|
447
|
+
if (el.type !== Text) return false;
|
|
448
|
+
const child = el.props?.children;
|
|
449
|
+
return typeof child === 'string' && child.trim() === '';
|
|
450
|
+
});
|
|
451
|
+
if (!isOnlyWhitespace) {
|
|
452
|
+
grouped.push(
|
|
453
|
+
<Text key={`tg-${grouped.length}`}>{textGroup}</Text>
|
|
454
|
+
);
|
|
455
|
+
}
|
|
456
|
+
textGroup = [];
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
for (const el of elements) {
|
|
461
|
+
if (el.type === View) {
|
|
462
|
+
flushTextGroup();
|
|
463
|
+
grouped.push(el);
|
|
464
|
+
} else {
|
|
465
|
+
textGroup.push(el);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
flushTextGroup();
|
|
469
|
+
|
|
470
|
+
return <View key="root" style={{ flexDirection: 'column', flexShrink: 1 }}>{grouped}</View>;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
if (elements.length === 1) return elements[0];
|
|
474
|
+
return <Text key="root">{elements}</Text>;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
private parseInlineFormats(text: string): JSX.Element | string {
|
|
478
|
+
if (!text) return "";
|
|
479
|
+
// Strip mention patterns before checking for markdown markers — mention UIDs
|
|
480
|
+
// can contain underscores/brackets that would trigger false-positive parsing.
|
|
481
|
+
const textWithoutMentions = text.replace(MENTION_PATTERN_REGEX, '');
|
|
482
|
+
if (textWithoutMentions.indexOf("**") < 0 && textWithoutMentions.indexOf("__") < 0 && textWithoutMentions.indexOf("<u>") < 0 &&
|
|
483
|
+
textWithoutMentions.indexOf("~~") < 0 && textWithoutMentions.indexOf("`") < 0 && textWithoutMentions.indexOf("_") < 0 &&
|
|
484
|
+
textWithoutMentions.indexOf("[") < 0) {
|
|
485
|
+
return text;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// Replace mention patterns with null-byte placeholders before parsing so
|
|
489
|
+
// findItalic/findNextFormat never see underscores or brackets inside UIDs.
|
|
490
|
+
// After parsing, restore the original mention strings in the output.
|
|
491
|
+
const mentionSlots: string[] = [];
|
|
492
|
+
const sanitized = text.replace(MENTION_PATTERN_REGEX, (match) => {
|
|
493
|
+
const idx = mentionSlots.length;
|
|
494
|
+
mentionSlots.push(match);
|
|
495
|
+
return `\x00M${idx}\x00`;
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
// Restore mention placeholders in a string or JSX tree
|
|
499
|
+
const restoreMentions = (node: JSX.Element | string): JSX.Element | string => {
|
|
500
|
+
if (typeof node === 'string') {
|
|
501
|
+
if (mentionSlots.length === 0 || node.indexOf('\x00') < 0) return node;
|
|
502
|
+
return node.replace(/\x00M(\d+)\x00/g, (_, idx) => mentionSlots[Number(idx)] ?? _);
|
|
503
|
+
}
|
|
504
|
+
if (!React.isValidElement(node)) return node;
|
|
505
|
+
const el = node as React.ReactElement<any>;
|
|
506
|
+
const children = el.props.children;
|
|
507
|
+
if (!children) return node;
|
|
508
|
+
const restored = React.Children.map(children, (child: any) => {
|
|
509
|
+
if (typeof child === 'string') return restoreMentions(child);
|
|
510
|
+
if (React.isValidElement(child)) return restoreMentions(child as JSX.Element);
|
|
511
|
+
return child;
|
|
512
|
+
});
|
|
513
|
+
return React.cloneElement(el, {}, ...(restored || []));
|
|
514
|
+
};
|
|
515
|
+
|
|
516
|
+
const elements: (JSX.Element | string)[] = [];
|
|
517
|
+
let remaining = sanitized;
|
|
518
|
+
let keyCounter = 0;
|
|
519
|
+
let iterations = 0;
|
|
520
|
+
const maxIterations = 500;
|
|
521
|
+
|
|
522
|
+
while (remaining.length > 0 && iterations < maxIterations) {
|
|
523
|
+
iterations++;
|
|
524
|
+
const match = this.findNextFormat(remaining);
|
|
525
|
+
if (match) {
|
|
526
|
+
if (match.startIndex > 0) {
|
|
527
|
+
elements.push(restoreMentions(remaining.substring(0, match.startIndex)) as string);
|
|
528
|
+
}
|
|
529
|
+
// Restore mentions in matched content before recursive parsing
|
|
530
|
+
const restoredContent = (typeof match.content === 'string' && match.content.indexOf('\x00') >= 0)
|
|
531
|
+
? restoreMentions(match.content) as string
|
|
532
|
+
: match.content;
|
|
533
|
+
if (match.type === "link" && match.url) {
|
|
534
|
+
// Render link as tappable blue underlined text (same as CometChatUrlsFormatter)
|
|
535
|
+
const innerContent = this.parseInlineFormats(restoredContent);
|
|
536
|
+
const linkUrl = match.url;
|
|
537
|
+
elements.push(
|
|
538
|
+
<Text
|
|
539
|
+
key={`fmt-${keyCounter++}`}
|
|
540
|
+
style={this.style.linkStyle || { color: "#1a73e8", textDecorationLine: "underline" }}
|
|
541
|
+
onPress={() => {
|
|
542
|
+
let finalUrl = linkUrl;
|
|
543
|
+
if (!URL_PROTOCOL_REGEX.test(linkUrl)) {
|
|
544
|
+
finalUrl = `http://${linkUrl}`;
|
|
545
|
+
}
|
|
546
|
+
Linking.openURL(finalUrl).catch((err) => {
|
|
547
|
+
console.log("Error opening URL:", err);
|
|
548
|
+
});
|
|
549
|
+
}}
|
|
550
|
+
>{innerContent}</Text>
|
|
551
|
+
);
|
|
552
|
+
} else if (match.type === "inlineCode") {
|
|
553
|
+
const innerContent = this.parseInlineFormats(restoredContent);
|
|
554
|
+
// Use a single Text element (not View) so inline code stays on the
|
|
555
|
+
// same text baseline as surrounding content (mentions, plain text).
|
|
556
|
+
// Text supports backgroundColor, borderRadius, and padding in RN.
|
|
557
|
+
elements.push(
|
|
558
|
+
<Text key={`fmt-${keyCounter++}`} style={[this.style.inlineCodeContainerStyle, this.style.inlineCodeStyle]}>{innerContent}</Text>
|
|
559
|
+
);
|
|
560
|
+
} else if (match.type === "codeBlock") {
|
|
561
|
+
// Inline ```text``` — render identically to single-backtick inline code
|
|
562
|
+
// (compact pill with background, no block-level padding).
|
|
563
|
+
// Block-level code block rendering with View container is handled in renderMarkdown.
|
|
564
|
+
elements.push(
|
|
565
|
+
<Text
|
|
566
|
+
key={`fmt-${keyCounter++}`}
|
|
567
|
+
style={[this.style.inlineCodeContainerStyle, this.style.inlineCodeStyle]}
|
|
568
|
+
>{restoredContent}</Text>
|
|
569
|
+
);
|
|
570
|
+
} else {
|
|
571
|
+
const style = this.getStyleForFormat(match.type);
|
|
572
|
+
const innerContent = this.parseInlineFormats(restoredContent);
|
|
573
|
+
// Merge textDecorationLine with child elements so underline
|
|
574
|
+
// and strikethrough can coexist (React Native child overrides parent).
|
|
575
|
+
const mergedInner = this.mergeTextDecoration(innerContent, style);
|
|
576
|
+
elements.push(
|
|
577
|
+
<Text key={`fmt-${keyCounter++}`} style={style}>{mergedInner}</Text>
|
|
578
|
+
);
|
|
579
|
+
}
|
|
580
|
+
remaining = remaining.substring(match.endIndex);
|
|
581
|
+
} else {
|
|
582
|
+
elements.push(restoreMentions(remaining) as string);
|
|
583
|
+
remaining = "";
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
if (elements.length === 0) return text;
|
|
588
|
+
if (elements.length === 1 && typeof elements[0] === "string") return elements[0];
|
|
589
|
+
return <Text key={`inline-${keyCounter}`}>{elements}</Text>;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
private findNextFormat(text: string): { type: string; content: string; startIndex: number; endIndex: number; url?: string } | null {
|
|
593
|
+
const matches: Array<{ type: string; content: string; startIndex: number; endIndex: number; url?: string }> = [];
|
|
594
|
+
|
|
595
|
+
const codeBlockMatch = this.findPair(text, "```", "```");
|
|
596
|
+
if (codeBlockMatch) matches.push({ ...codeBlockMatch, type: "codeBlock" });
|
|
597
|
+
|
|
598
|
+
const inlineCodeMatch = this.findPair(text, "`", "`");
|
|
599
|
+
if (inlineCodeMatch) {
|
|
600
|
+
const isPartOfCodeBlock = codeBlockMatch &&
|
|
601
|
+
inlineCodeMatch.startIndex >= codeBlockMatch.startIndex &&
|
|
602
|
+
inlineCodeMatch.startIndex < codeBlockMatch.endIndex;
|
|
603
|
+
if (!isPartOfCodeBlock) matches.push({ ...inlineCodeMatch, type: "inlineCode" });
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
const boldMatch = this.findPair(text, "**", "**");
|
|
607
|
+
if (boldMatch) matches.push({ ...boldMatch, type: "bold" });
|
|
608
|
+
|
|
609
|
+
const underlineMatch = this.findPair(text, "__", "__");
|
|
610
|
+
if (underlineMatch) matches.push({ ...underlineMatch, type: "underline" });
|
|
611
|
+
|
|
612
|
+
// HTML underline tag: <u>text</u>
|
|
613
|
+
const htmlUnderlineMatch = this.findHtmlUnderline(text);
|
|
614
|
+
if (htmlUnderlineMatch) matches.push({ ...htmlUnderlineMatch, type: "underline" });
|
|
615
|
+
|
|
616
|
+
const strikeMatch = this.findPair(text, "~~", "~~");
|
|
617
|
+
if (strikeMatch) matches.push({ ...strikeMatch, type: "strikethrough" });
|
|
618
|
+
|
|
619
|
+
const italicMatch = this.findItalic(text);
|
|
620
|
+
if (italicMatch) matches.push({ ...italicMatch, type: "italic" });
|
|
621
|
+
|
|
622
|
+
const linkMatch = this.findLink(text);
|
|
623
|
+
if (linkMatch) matches.push(linkMatch);
|
|
624
|
+
|
|
625
|
+
if (matches.length === 0) return null;
|
|
626
|
+
let earliest = matches[0];
|
|
627
|
+
for (let i = 1; i < matches.length; i++) {
|
|
628
|
+
if (matches[i].startIndex < earliest.startIndex) earliest = matches[i];
|
|
629
|
+
}
|
|
630
|
+
return earliest;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
private findPair(text: string, openMarker: string, closeMarker: string): { content: string; startIndex: number; endIndex: number } | null {
|
|
634
|
+
const openIndex = text.indexOf(openMarker);
|
|
635
|
+
if (openIndex < 0) return null;
|
|
636
|
+
const contentStart = openIndex + openMarker.length;
|
|
637
|
+
if (contentStart >= text.length) return null;
|
|
638
|
+
|
|
639
|
+
// Handle triple underscore: ___content___ should be parsed as __( _content_ )__
|
|
640
|
+
// When looking for __ pairs and we see ___ (triple), skip the extra _ so the
|
|
641
|
+
// inner _ is preserved as italic content for recursive parsing.
|
|
642
|
+
if (openMarker === "__" && text.charAt(contentStart) === "_") {
|
|
643
|
+
// We have ___..., look for closing ___ (triple)
|
|
644
|
+
const tripleCloseIndex = text.indexOf("___", contentStart + 1);
|
|
645
|
+
if (tripleCloseIndex > contentStart) {
|
|
646
|
+
// Content between the outer __ markers is _innerContent_
|
|
647
|
+
// which will be recursively parsed as italic
|
|
648
|
+
const content = text.substring(contentStart, tripleCloseIndex + 1); // includes the inner _ on both sides
|
|
649
|
+
return { content, startIndex: openIndex, endIndex: tripleCloseIndex + 3 }; // +3 for ___
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
const closeIndex = text.indexOf(closeMarker, contentStart);
|
|
654
|
+
if (closeIndex < 0 || closeIndex <= contentStart) return null;
|
|
655
|
+
const content = text.substring(contentStart, closeIndex);
|
|
656
|
+
if (content.length === 0) return null;
|
|
657
|
+
return { content, startIndex: openIndex, endIndex: closeIndex + closeMarker.length };
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
private findItalic(text: string): { content: string; startIndex: number; endIndex: number } | null {
|
|
661
|
+
const doublePositions = new Set<number>();
|
|
662
|
+
let searchPos = 0;
|
|
663
|
+
while (searchPos < text.length - 1) {
|
|
664
|
+
const idx = text.indexOf("__", searchPos);
|
|
665
|
+
if (idx < 0) break;
|
|
666
|
+
doublePositions.add(idx);
|
|
667
|
+
doublePositions.add(idx + 1);
|
|
668
|
+
searchPos = idx + 2;
|
|
669
|
+
}
|
|
670
|
+
for (let i = 0; i < text.length; i++) {
|
|
671
|
+
if (text.charAt(i) === "_" && !doublePositions.has(i)) {
|
|
672
|
+
for (let j = i + 1; j < text.length; j++) {
|
|
673
|
+
if (text.charAt(j) === "_" && !doublePositions.has(j)) {
|
|
674
|
+
const content = text.substring(i + 1, j);
|
|
675
|
+
if (content.length > 0) return { content, startIndex: i, endIndex: j + 1 };
|
|
676
|
+
break;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
return null;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
private findLink(text: string): { type: string; content: string; startIndex: number; endIndex: number; url?: string } | null {
|
|
685
|
+
const match = LINK_REGEX.exec(text);
|
|
686
|
+
if (!match) return null;
|
|
687
|
+
return {
|
|
688
|
+
type: "link",
|
|
689
|
+
content: match[1],
|
|
690
|
+
url: match[2],
|
|
691
|
+
startIndex: match.index,
|
|
692
|
+
endIndex: match.index + match[0].length,
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
/** Detect <u>text</u> HTML underline tags (case-insensitive) */
|
|
697
|
+
private findHtmlUnderline(text: string): { content: string; startIndex: number; endIndex: number } | null {
|
|
698
|
+
const lower = text.toLowerCase();
|
|
699
|
+
const openIdx = lower.indexOf("<u>");
|
|
700
|
+
if (openIdx < 0) return null;
|
|
701
|
+
const contentStart = openIdx + 3;
|
|
702
|
+
const closeIdx = lower.indexOf("</u>", contentStart);
|
|
703
|
+
if (closeIdx < 0) return null;
|
|
704
|
+
const content = text.substring(contentStart, closeIdx);
|
|
705
|
+
if (content.length === 0) return null;
|
|
706
|
+
return { content, startIndex: openIdx, endIndex: closeIdx + 4 };
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
/**
|
|
710
|
+
* When a parent Text has textDecorationLine (e.g. "underline") and a child
|
|
711
|
+
* also has textDecorationLine (e.g. "line-through"), React Native's child
|
|
712
|
+
* value overrides the parent instead of merging. This helper walks the
|
|
713
|
+
* immediate children and combines the parent's decoration into any child
|
|
714
|
+
* that also declares textDecorationLine, so both render correctly.
|
|
715
|
+
*/
|
|
716
|
+
private mergeTextDecoration(
|
|
717
|
+
inner: JSX.Element | string,
|
|
718
|
+
parentStyle: TextStyle
|
|
719
|
+
): JSX.Element | string {
|
|
720
|
+
const parentDeco = parentStyle.textDecorationLine;
|
|
721
|
+
if (!parentDeco || typeof inner === "string") return inner;
|
|
722
|
+
if (!React.isValidElement(inner)) return inner;
|
|
723
|
+
|
|
724
|
+
const el = inner as React.ReactElement<any>;
|
|
725
|
+
const children = React.Children.map(el.props.children, (child) => {
|
|
726
|
+
if (!React.isValidElement(child)) return child;
|
|
727
|
+
const childEl = child as React.ReactElement<any>;
|
|
728
|
+
const childStyle = childEl.props.style;
|
|
729
|
+
if (!childStyle) return child;
|
|
730
|
+
|
|
731
|
+
// Flatten style to find textDecorationLine
|
|
732
|
+
const flat = Array.isArray(childStyle)
|
|
733
|
+
? Object.assign({}, ...childStyle.filter(Boolean))
|
|
734
|
+
: childStyle;
|
|
735
|
+
const childDeco = flat.textDecorationLine as string | undefined;
|
|
736
|
+
if (!childDeco || childDeco === parentDeco) return child;
|
|
737
|
+
|
|
738
|
+
// Combine: e.g. "underline" + "line-through" → "underline line-through"
|
|
739
|
+
const parts = new Set([...parentDeco.split(" "), ...childDeco.split(" ")]);
|
|
740
|
+
parts.delete("none");
|
|
741
|
+
const combined = parts.size > 0 ? Array.from(parts).join(" ") : "none";
|
|
742
|
+
|
|
743
|
+
return React.cloneElement(childEl, {
|
|
744
|
+
style: Array.isArray(childStyle)
|
|
745
|
+
? [...childStyle, { textDecorationLine: combined }]
|
|
746
|
+
: { ...flat, textDecorationLine: combined },
|
|
747
|
+
});
|
|
748
|
+
});
|
|
749
|
+
|
|
750
|
+
if (!children) return inner;
|
|
751
|
+
return React.cloneElement(el, {}, ...children);
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
private getStyleForFormat(type: string): TextStyle {
|
|
755
|
+
switch (type) {
|
|
756
|
+
case "bold": return this.style.boldStyle || {};
|
|
757
|
+
case "italic": return this.style.italicStyle || {};
|
|
758
|
+
case "underline": return this.style.underlineStyle || {};
|
|
759
|
+
case "strikethrough": return this.style.strikethroughStyle || {};
|
|
760
|
+
case "inlineCode": return this.style.inlineCodeStyle || {};
|
|
761
|
+
case "codeBlock": return this.style.codeBlockStyle || {};
|
|
762
|
+
default: return {};
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
getMessage() { return this.messageObject; }
|
|
767
|
+
setMessage(messageObject: CometChat.BaseMessage) { this.messageObject = messageObject; }
|
|
768
|
+
}
|