@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.
- package/android/src/main/java/com/reactnativecometchatuikit/CometChatClipboardModule.kt +34 -0
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +562 -5
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorViewManager.kt +28 -1
- package/ios/CometChatClipboardModule.m +5 -0
- package/ios/CometChatClipboardModule.swift +22 -0
- package/ios/RichTextEditorView.swift +636 -31
- package/ios/RichTextEditorViewManager.m +3 -0
- package/ios/RichTextEditorViewManager.swift +24 -0
- package/package.json +5 -2
- package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +283 -64
- package/src/CometChatCompactMessageComposer/index.ts +2 -0
- package/src/CometChatConversations/CometChatConversations.tsx +299 -15
- package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +2 -2
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +15 -3
- package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +181 -12
- package/src/CometChatMessageInformation/CometChatMessageInformation.tsx +10 -1
- package/src/CometChatMessageList/CometChatMessageList.tsx +572 -16
- package/src/CometChatMessageList/components/MessageModals.tsx +30 -0
- package/src/CometChatMessageList/components/MessageOptionsSheet.tsx +21 -9
- package/src/CometChatMessageList/components/MessageQuickActions.tsx +162 -0
- package/src/CometChatPinnedMessages/CometChatPinnedMessages.tsx +964 -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 +31 -1
- package/src/CometChatRichTextEditor/types.ts +21 -1
- package/src/CometChatSavedMessages/CometChatSavedMessages.tsx +871 -0
- package/src/CometChatSavedMessages/index.ts +5 -0
- package/src/CometChatSavedMessages/style.ts +159 -0
- package/src/CometChatSearch/CometChatSearch.tsx +71 -341
- package/src/CometChatThreadHeader/CometChatThreadHeader.tsx +22 -2
- package/src/index.ts +60 -0
- package/src/shared/CometChatUiKit/CometChatUIKit.ts +18 -1
- package/src/shared/base/Types.ts +5 -0
- package/src/shared/constants/UIKitConstants.ts +16 -17
- package/src/shared/constants/textPatterns.ts +27 -0
- package/src/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.ts +25 -225
- 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 +123 -25
- package/src/shared/formatters/CometChatTextFormatter.ts +22 -0
- package/src/shared/formatters/applyRawFormatters.ts +31 -0
- package/src/shared/formatters/index.ts +14 -0
- package/src/shared/formatters/richTextWireFormat.ts +165 -0
- package/src/shared/framework/MessageDataSource.tsx +309 -10
- 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/CometChatI18nProvider.tsx +15 -30
- package/src/shared/resources/CometChatLocalizeNew/CometChatLocalizationHelper.ts +138 -19
- package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +74 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +54 -1
- package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +11 -0
- package/src/shared/utils/MarkdownUtils.ts +57 -6
- 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/PinnedMessagesHelper.ts +65 -0
- package/src/shared/utils/SavedMessagesHelper.ts +267 -0
- package/src/shared/utils/ThreadSubscriptionHelper.ts +427 -0
- package/src/shared/utils/__testUtils__/messagesRequestBuilderMock.ts +37 -0
- package/src/shared/utils/cloneRequestBuilder.ts +25 -0
- package/src/shared/utils/conversationUtils.ts +8 -1
- package/src/shared/utils/stripRichText.ts +7 -0
- package/src/shared/views/ClipboardPasteHandler/ClipboardPasteHandler.ts +32 -0
- package/src/shared/views/ClipboardPasteHandler/NativeCometChatClipboardModule.ts +6 -0
- package/src/shared/views/CometChatActionSheet/CometChatActionSheet.tsx +4 -0
- package/src/shared/views/CometChatAudiosBubble/CometChatAudiosBubble.tsx +5 -0
- package/src/shared/views/CometChatAvatar/CometChatAvatar.tsx +17 -5
- package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +5 -1
- package/src/shared/views/CometChatCaptionText/CometChatCaptionText.tsx +8 -1
- package/src/shared/views/CometChatConfirmDialog/CometChatConfirmDialog.tsx +2 -0
- package/src/shared/views/CometChatConversationStarter/CometChatConversationStarter.tsx +91 -20
- package/src/shared/views/CometChatFilesBubble/CometChatFilesBubble.tsx +5 -0
- package/src/shared/views/CometChatImagesBubble/CometChatImagesBubble.tsx +5 -0
- package/src/shared/views/CometChatList/CometChatList.tsx +6 -1
- package/src/shared/views/CometChatList/Header.tsx +8 -2
- 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/CometChatVideosBubble/CometChatVideosBubble.tsx +5 -0
- package/src/shared/views/CometChatVoiceNoteBubble/CometChatVoiceNoteBubble.tsx +5 -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
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { CometChatPinnedMessages } from "./CometChatPinnedMessages";
|
|
2
|
+
export type { CometChatPinnedMessagesInterface } from "./CometChatPinnedMessages";
|
|
3
|
+
|
|
4
|
+
export { getPinnedMessagesStyleLight, getPinnedMessagesStyleDark } from "./style";
|
|
5
|
+
export type { PinnedMessagesStyle } from "./style";
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { ImageSourcePropType, ImageStyle, TextStyle, ViewStyle } from "react-native";
|
|
2
|
+
import { JSX } from "react";
|
|
3
|
+
import { CometChatTheme } from "../theme/type";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Style type for the CometChatPinnedMessages component (design doc §6.7).
|
|
7
|
+
*
|
|
8
|
+
* Every value maps to a SEMANTIC theme token rather than a literal, so light and
|
|
9
|
+
* dark are two calls to the same builder and an integrator retheming the kit gets
|
|
10
|
+
* this surface for free.
|
|
11
|
+
*/
|
|
12
|
+
export type PinnedMessagesStyle = {
|
|
13
|
+
/** Root container. */
|
|
14
|
+
containerStyle: ViewStyle;
|
|
15
|
+
|
|
16
|
+
/** Header: title on the left, close affordance on the right. */
|
|
17
|
+
headerContainerStyle: ViewStyle;
|
|
18
|
+
titleStyle: TextStyle;
|
|
19
|
+
closeButtonIconStyle: ImageStyle;
|
|
20
|
+
closeButtonIcon?: ImageSourcePropType | JSX.Element;
|
|
21
|
+
|
|
22
|
+
/** One pinned message row: the sender line above, the bubble below. */
|
|
23
|
+
itemStyle: {
|
|
24
|
+
containerStyle: ViewStyle;
|
|
25
|
+
/** Avatar + name + date row that sits above the bubble. */
|
|
26
|
+
headerContainerStyle: ViewStyle;
|
|
27
|
+
avatarStyle: CometChatTheme["avatarStyle"];
|
|
28
|
+
senderNameStyle: TextStyle;
|
|
29
|
+
separatorStyle: TextStyle;
|
|
30
|
+
dateStyle: Partial<CometChatTheme["dateStyles"]>;
|
|
31
|
+
/** Bookmark shown when a pinned message is ALSO saved by this viewer. */
|
|
32
|
+
savedIndicatorStyle: ImageStyle;
|
|
33
|
+
savedIndicatorContainerStyle: ViewStyle;
|
|
34
|
+
/** Left inset that lines the bubble up under the sender name. */
|
|
35
|
+
bubbleContainerStyle: ViewStyle;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/** Empty and error states. */
|
|
39
|
+
emptyStateStyle: {
|
|
40
|
+
/** Centres the whole block in the space the list would have filled. */
|
|
41
|
+
containerStyle: ViewStyle;
|
|
42
|
+
titleStyle: TextStyle;
|
|
43
|
+
subTitleStyle: TextStyle;
|
|
44
|
+
iconStyle: ImageStyle;
|
|
45
|
+
};
|
|
46
|
+
errorStateStyle: {
|
|
47
|
+
containerStyle: ViewStyle;
|
|
48
|
+
titleStyle: TextStyle;
|
|
49
|
+
subTitleStyle: TextStyle;
|
|
50
|
+
iconStyle: ImageStyle;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const getPinnedMessagesStyleLight = (
|
|
55
|
+
color: CometChatTheme["color"],
|
|
56
|
+
spacing: CometChatTheme["spacing"],
|
|
57
|
+
typography: CometChatTheme["typography"]
|
|
58
|
+
): PinnedMessagesStyle => ({
|
|
59
|
+
containerStyle: {
|
|
60
|
+
flex: 1,
|
|
61
|
+
backgroundColor: color.background1,
|
|
62
|
+
},
|
|
63
|
+
// Mirrors the Group Info / User Info header: a leading back arrow, then the title. Those
|
|
64
|
+
// screens are the reference for every full-screen view in the app, so the paddings and the
|
|
65
|
+
// heading1.bold title are copied rather than re-invented.
|
|
66
|
+
headerContainerStyle: {
|
|
67
|
+
flexDirection: "row",
|
|
68
|
+
alignItems: "center",
|
|
69
|
+
paddingTop: spacing.padding.p4,
|
|
70
|
+
paddingLeft: spacing.padding.p2,
|
|
71
|
+
paddingBottom: spacing.padding.p2,
|
|
72
|
+
},
|
|
73
|
+
titleStyle: {
|
|
74
|
+
...typography.heading1.bold,
|
|
75
|
+
color: color.textPrimary,
|
|
76
|
+
paddingLeft: spacing.padding.p1,
|
|
77
|
+
},
|
|
78
|
+
closeButtonIconStyle: {
|
|
79
|
+
tintColor: color.iconPrimary,
|
|
80
|
+
height: spacing.spacing.s6,
|
|
81
|
+
width: spacing.spacing.s6,
|
|
82
|
+
},
|
|
83
|
+
itemStyle: {
|
|
84
|
+
containerStyle: {
|
|
85
|
+
paddingHorizontal: spacing.padding.p4,
|
|
86
|
+
paddingVertical: spacing.padding.p3,
|
|
87
|
+
},
|
|
88
|
+
headerContainerStyle: {
|
|
89
|
+
flexDirection: "row",
|
|
90
|
+
alignItems: "center",
|
|
91
|
+
marginBottom: spacing.margin.m1,
|
|
92
|
+
},
|
|
93
|
+
avatarStyle: {
|
|
94
|
+
containerStyle: {
|
|
95
|
+
height: spacing.spacing.s8,
|
|
96
|
+
width: spacing.spacing.s8,
|
|
97
|
+
},
|
|
98
|
+
// The font has to come down WITH the circle (ENG-38886).
|
|
99
|
+
//
|
|
100
|
+
// The theme sizes initials at heading2.bold (20px) for its own 48px avatar. This row uses
|
|
101
|
+
// a 32px one, and two capitals at 20px do not fit inside it — which left the whole thing
|
|
102
|
+
// resting on `adjustsFontSizeToFit`. That prop shrinks text differently on iOS than on
|
|
103
|
+
// Android, so the initials came out clipped and mis-centred on iOS only, while Android
|
|
104
|
+
// looked fine and hid the problem.
|
|
105
|
+
//
|
|
106
|
+
// body.bold (14px) keeps roughly the same letter-to-circle ratio the theme uses at 48px,
|
|
107
|
+
// so the text fits on its own and the auto-shrink never has to do anything.
|
|
108
|
+
textStyle: {
|
|
109
|
+
...typography.body.bold,
|
|
110
|
+
// heading2.bold brings a 28px lineHeight with it; left in place it pushes two 14px
|
|
111
|
+
// capitals off-centre inside a 32px circle.
|
|
112
|
+
lineHeight: undefined,
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
senderNameStyle: {
|
|
116
|
+
...typography.body.medium,
|
|
117
|
+
color: color.textHighlight,
|
|
118
|
+
marginLeft: spacing.margin.m2,
|
|
119
|
+
},
|
|
120
|
+
separatorStyle: {
|
|
121
|
+
...typography.caption1.regular,
|
|
122
|
+
color: color.textSecondary,
|
|
123
|
+
marginHorizontal: spacing.margin.m1,
|
|
124
|
+
},
|
|
125
|
+
dateStyle: {
|
|
126
|
+
textStyle: {
|
|
127
|
+
...typography.caption1.regular,
|
|
128
|
+
color: color.textSecondary,
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
savedIndicatorStyle: {
|
|
132
|
+
tintColor: color.iconSecondary,
|
|
133
|
+
height: 14,
|
|
134
|
+
width: 14,
|
|
135
|
+
},
|
|
136
|
+
savedIndicatorContainerStyle: {
|
|
137
|
+
marginLeft: spacing.margin.m1,
|
|
138
|
+
},
|
|
139
|
+
bubbleContainerStyle: {
|
|
140
|
+
// Lines the bubble up under the sender name rather than the avatar.
|
|
141
|
+
marginLeft: spacing.spacing.s10,
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
emptyStateStyle: {
|
|
145
|
+
containerStyle: {
|
|
146
|
+
flex: 1,
|
|
147
|
+
alignItems: "center",
|
|
148
|
+
justifyContent: "center",
|
|
149
|
+
paddingHorizontal: spacing.padding.p8,
|
|
150
|
+
gap: spacing.spacing.s2,
|
|
151
|
+
},
|
|
152
|
+
titleStyle: {
|
|
153
|
+
...typography.heading4.bold,
|
|
154
|
+
color: color.textPrimary,
|
|
155
|
+
textAlign: "center",
|
|
156
|
+
},
|
|
157
|
+
subTitleStyle: {
|
|
158
|
+
...typography.body.regular,
|
|
159
|
+
color: color.textSecondary,
|
|
160
|
+
textAlign: "center",
|
|
161
|
+
},
|
|
162
|
+
iconStyle: {
|
|
163
|
+
tintColor: color.iconSecondary,
|
|
164
|
+
// 120, not a spacing token: these glyphs sit in a 24x24 viewBox but only fill ~54% of its
|
|
165
|
+
// width, so the BOX has to be far larger than the mark you want to see. The design's
|
|
166
|
+
// bookmark measures 66x80 against a 16px title, and 66 / 0.54 ≈ 120. Using s14 (56) drew
|
|
167
|
+
// a 30x37 mark — less than half the intended size.
|
|
168
|
+
height: 120,
|
|
169
|
+
width: 120,
|
|
170
|
+
marginBottom: spacing.margin.m3,
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
// Same layout as the empty state, because it fills the same hole. The icon needs no
|
|
174
|
+
// size compensation: `error-state` is a purpose-built 120x120 illustration that fills
|
|
175
|
+
// its viewBox, unlike the glyphs above. 120 is also what the conversation list asks
|
|
176
|
+
// for (`margin.m15 << 1`), so the two error screens come out identical.
|
|
177
|
+
errorStateStyle: {
|
|
178
|
+
containerStyle: {
|
|
179
|
+
flex: 1,
|
|
180
|
+
alignItems: "center",
|
|
181
|
+
justifyContent: "center",
|
|
182
|
+
paddingHorizontal: spacing.padding.p8,
|
|
183
|
+
},
|
|
184
|
+
titleStyle: {
|
|
185
|
+
...typography.heading4.bold,
|
|
186
|
+
color: color.textPrimary,
|
|
187
|
+
textAlign: "center",
|
|
188
|
+
},
|
|
189
|
+
subTitleStyle: {
|
|
190
|
+
...typography.body.regular,
|
|
191
|
+
color: color.textSecondary,
|
|
192
|
+
textAlign: "center",
|
|
193
|
+
},
|
|
194
|
+
iconStyle: {
|
|
195
|
+
height: 120,
|
|
196
|
+
width: 120,
|
|
197
|
+
marginBottom: spacing.margin.m3,
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Dark delegates to light, deliberately.
|
|
204
|
+
*
|
|
205
|
+
* The kit's convention is `dark = deepMerge(light(...), <dark-only overrides>)`, and
|
|
206
|
+
* those overrides exist only where a value CANNOT come from a token — the skeleton
|
|
207
|
+
* gradient literals in CometChatUsers, for instance. Every value here resolves from
|
|
208
|
+
* a semantic token, and `color` is already the dark palette by the time it arrives,
|
|
209
|
+
* so there is nothing left to override. An empty deepMerge would say the same thing
|
|
210
|
+
* with more ceremony.
|
|
211
|
+
*/
|
|
212
|
+
export const getPinnedMessagesStyleDark = (
|
|
213
|
+
color: CometChatTheme["color"],
|
|
214
|
+
spacing: CometChatTheme["spacing"],
|
|
215
|
+
typography: CometChatTheme["typography"]
|
|
216
|
+
): PinnedMessagesStyle => getPinnedMessagesStyleLight(color, spacing, typography);
|
|
@@ -23,6 +23,8 @@ export type StyleRange = Readonly<{
|
|
|
23
23
|
end: Int32;
|
|
24
24
|
url?: string;
|
|
25
25
|
highlightColor?: string;
|
|
26
|
+
/** `#rrggbb` for a `textColor` range. */
|
|
27
|
+
color?: string;
|
|
26
28
|
}>;
|
|
27
29
|
|
|
28
30
|
export type Block = Readonly<{
|
|
@@ -37,6 +39,9 @@ export type Block = Readonly<{
|
|
|
37
39
|
type ContentChangeEventData = Readonly<{
|
|
38
40
|
text: string;
|
|
39
41
|
blocksJson: string;
|
|
42
|
+
// Mention ranges in clean (ZWS-stripped) coordinates, JSON-encoded. Read back by
|
|
43
|
+
// getMentionRanges() so a consumer formatter can skip mentions.
|
|
44
|
+
mentionRangesJson?: string;
|
|
40
45
|
}>;
|
|
41
46
|
|
|
42
47
|
type SelectionChangeEventData = Readonly<{
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { forwardRef, useImperativeHandle, useRef, useCallback, useState } from 'react';
|
|
2
|
-
import { StyleSheet, UIManager, findNodeHandle } from 'react-native';
|
|
2
|
+
import { StyleSheet, UIManager, findNodeHandle, processColor } from 'react-native';
|
|
3
3
|
import type {
|
|
4
4
|
Block,
|
|
5
5
|
TextAlignment,
|
|
@@ -7,6 +7,7 @@ import type {
|
|
|
7
7
|
SelectionChangeEvent,
|
|
8
8
|
RichTextEditorProps,
|
|
9
9
|
RichTextEditorRef,
|
|
10
|
+
InlineStyleKey,
|
|
10
11
|
} from './types';
|
|
11
12
|
import RichTextEditorViewNative from './RichTextEditorViewNativeComponent';
|
|
12
13
|
|
|
@@ -29,6 +30,7 @@ const COMMANDS = {
|
|
|
29
30
|
setChecklist: 'setChecklist',
|
|
30
31
|
setParagraph: 'setParagraph',
|
|
31
32
|
insertLink: 'insertLink',
|
|
33
|
+
replaceSelection: 'replaceSelection',
|
|
32
34
|
undo: 'undo',
|
|
33
35
|
redo: 'redo',
|
|
34
36
|
clearFormatting: 'clearFormatting',
|
|
@@ -44,6 +46,8 @@ const COMMANDS = {
|
|
|
44
46
|
setMentionRanges: 'setMentionRanges',
|
|
45
47
|
removeLink: 'removeLink',
|
|
46
48
|
updateLink: 'updateLink',
|
|
49
|
+
applyInlineStyle: 'applyInlineStyle',
|
|
50
|
+
removeInlineStyle: 'removeInlineStyle',
|
|
47
51
|
} as const;
|
|
48
52
|
|
|
49
53
|
// Helper to dispatch commands to native view
|
|
@@ -141,6 +145,9 @@ export interface RichTextEditorPropsExtended extends RichTextEditorProps {
|
|
|
141
145
|
const RichTextEditor = forwardRef<RichTextEditorRef, RichTextEditorPropsExtended>((props, ref) => {
|
|
142
146
|
const nativeRef = useRef<React.ElementRef<typeof RichTextEditorViewNative>>(null);
|
|
143
147
|
const [height, setHeight] = useState<number | undefined>(undefined);
|
|
148
|
+
// Latest mention ranges reported by native, in plain-text coordinates. Native owns them
|
|
149
|
+
// because editing shifts them; it re-reports on every content change.
|
|
150
|
+
const mentionRangesRef = useRef<Array<{ start: number; end: number }>>([]);
|
|
144
151
|
|
|
145
152
|
const handleSizeChange = useCallback((event: SizeChangeEvent) => {
|
|
146
153
|
const newHeight = event.nativeEvent?.height;
|
|
@@ -207,6 +214,9 @@ const RichTextEditor = forwardRef<RichTextEditorRef, RichTextEditorPropsExtended
|
|
|
207
214
|
insertLink: (url: string, text: string) => {
|
|
208
215
|
dispatchCommand(nativeRef, COMMANDS.insertLink, [url, text]);
|
|
209
216
|
},
|
|
217
|
+
replaceSelection: (text: string) => {
|
|
218
|
+
dispatchCommand(nativeRef, COMMANDS.replaceSelection, [text]);
|
|
219
|
+
},
|
|
210
220
|
undo: () => {
|
|
211
221
|
dispatchCommand(nativeRef, COMMANDS.undo);
|
|
212
222
|
},
|
|
@@ -253,6 +263,17 @@ const RichTextEditor = forwardRef<RichTextEditorRef, RichTextEditorPropsExtended
|
|
|
253
263
|
updateLink: (location: number, length: number, newUrl: string, newText: string) => {
|
|
254
264
|
dispatchCommand(nativeRef, COMMANDS.updateLink, [location, length, newUrl, newText]);
|
|
255
265
|
},
|
|
266
|
+
applyInlineStyle: (key: InlineStyleKey, value: string) => {
|
|
267
|
+
// Let RN normalise the colour string (hex / named / rgba) into the packed int
|
|
268
|
+
// both platforms already speak, instead of parsing colours natively.
|
|
269
|
+
const color = processColor(value);
|
|
270
|
+
if (typeof color !== 'number') return;
|
|
271
|
+
dispatchCommand(nativeRef, COMMANDS.applyInlineStyle, [key, color]);
|
|
272
|
+
},
|
|
273
|
+
removeInlineStyle: (key: InlineStyleKey) => {
|
|
274
|
+
dispatchCommand(nativeRef, COMMANDS.removeInlineStyle, [key]);
|
|
275
|
+
},
|
|
276
|
+
getMentionRanges: () => mentionRangesRef.current,
|
|
256
277
|
}));
|
|
257
278
|
|
|
258
279
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -271,6 +292,14 @@ const RichTextEditor = forwardRef<RichTextEditorRef, RichTextEditorPropsExtended
|
|
|
271
292
|
blocks = [];
|
|
272
293
|
}
|
|
273
294
|
|
|
295
|
+
try {
|
|
296
|
+
mentionRangesRef.current = event.nativeEvent.mentionRangesJson
|
|
297
|
+
? JSON.parse(event.nativeEvent.mentionRangesJson)
|
|
298
|
+
: [];
|
|
299
|
+
} catch {
|
|
300
|
+
mentionRangesRef.current = [];
|
|
301
|
+
}
|
|
302
|
+
|
|
274
303
|
// Convert native event to our API format
|
|
275
304
|
const contentEvent: ContentChangeEvent = {
|
|
276
305
|
nativeEvent: {
|
|
@@ -406,5 +435,6 @@ export type {
|
|
|
406
435
|
DeltaType,
|
|
407
436
|
Selection,
|
|
408
437
|
TextStyle,
|
|
438
|
+
InlineStyleKey,
|
|
409
439
|
} from './types';
|
|
410
440
|
export { dispatchCommand };
|
|
@@ -13,11 +13,13 @@ export interface TextStyle {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export interface StyleRange {
|
|
16
|
-
style: 'bold' | 'italic' | 'underline' | 'strikethrough' | 'link' | 'code' | 'highlight';
|
|
16
|
+
style: 'bold' | 'italic' | 'underline' | 'strikethrough' | 'link' | 'code' | 'highlight' | 'textColor';
|
|
17
17
|
start: number;
|
|
18
18
|
end: number;
|
|
19
19
|
url?: string;
|
|
20
20
|
highlightColor?: string;
|
|
21
|
+
/** `#rrggbb` for a `textColor` range — the wire format's only value-carrying style. */
|
|
22
|
+
color?: string;
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
export type BlockType = 'paragraph' | 'bullet' | 'numbered' | 'heading' | 'quote' | 'checklist';
|
|
@@ -126,6 +128,9 @@ export interface RichTextEditorProps {
|
|
|
126
128
|
onBlur?: () => void;
|
|
127
129
|
}
|
|
128
130
|
|
|
131
|
+
/** Inline style a consumer formatter can apply to the composer selection. */
|
|
132
|
+
export type InlineStyleKey = 'color' | 'backgroundColor';
|
|
133
|
+
|
|
129
134
|
export interface RichTextEditorRef {
|
|
130
135
|
setContent: (blocks: Block[]) => void;
|
|
131
136
|
getText: () => Promise<string>;
|
|
@@ -147,6 +152,8 @@ export interface RichTextEditorRef {
|
|
|
147
152
|
setChecklist: () => void;
|
|
148
153
|
setParagraph: () => void;
|
|
149
154
|
insertLink: (url: string, text: string) => void;
|
|
155
|
+
/** Replaces the selection with plain text, or inserts at the caret when nothing is selected. */
|
|
156
|
+
replaceSelection: (text: string) => void;
|
|
150
157
|
undo: () => void;
|
|
151
158
|
redo: () => void;
|
|
152
159
|
clearFormatting: () => void;
|
|
@@ -159,4 +166,17 @@ export interface RichTextEditorRef {
|
|
|
159
166
|
setMentionRanges: (ranges: Array<{ start: number; end: number }>) => void;
|
|
160
167
|
removeLink: (location: number, length: number) => void;
|
|
161
168
|
updateLink: (location: number, length: number, newUrl: string, newText: string) => void;
|
|
169
|
+
/**
|
|
170
|
+
* Applies an arbitrary inline style to the current selection, skipping mentions.
|
|
171
|
+
* `value` is any React Native colour string (`'#FF0000'`, `'red'`, `'rgba(…)'`).
|
|
172
|
+
* Styles compose — an existing bold/italic on the range is left alone.
|
|
173
|
+
*/
|
|
174
|
+
applyInlineStyle: (key: InlineStyleKey, value: string) => void;
|
|
175
|
+
/** Removes a style previously applied with `applyInlineStyle` from the current selection. */
|
|
176
|
+
removeInlineStyle: (key: InlineStyleKey) => void;
|
|
177
|
+
/**
|
|
178
|
+
* Mention ranges in the composer's plain-text coordinates, as of the last content change.
|
|
179
|
+
* Use it to leave mentions untouched when computing ranges to format.
|
|
180
|
+
*/
|
|
181
|
+
getMentionRanges: () => Array<{ start: number; end: number }>;
|
|
162
182
|
}
|