@ethora/chat-component-rn 26.4.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/LICENSE +661 -0
- package/README.md +148 -0
- package/empty-shim.js +15 -0
- package/index.js +13 -0
- package/metro.js +72 -0
- package/package.json +99 -0
- package/src/api.config.ts +34 -0
- package/src/assets/BG.png +0 -0
- package/src/assets/BG.tsx +56 -0
- package/src/assets/File.svg +4 -0
- package/src/assets/ForzaCare.png +0 -0
- package/src/assets/ForzaCare.tsx +27 -0
- package/src/assets/icons.tsx +685 -0
- package/src/assets/images.tsx +41 -0
- package/src/assets/test.xml +243 -0
- package/src/components/AuthForms/Login.tsx +295 -0
- package/src/components/AuthForms/LoginAnonym.tsx +68 -0
- package/src/components/AuthForms/Register.tsx +8 -0
- package/src/components/ContextMenu/ContextMenuComponents.tsx +87 -0
- package/src/components/DropdownMenu/DropdownMenu.tsx +244 -0
- package/src/components/ExampleComponents/CustomMessage.tsx +92 -0
- package/src/components/ExampleComponents/CustomTypingIndicatorExamples.tsx +239 -0
- package/src/components/Header/HeaderRoomList.tsx +104 -0
- package/src/components/InputComponents/AudioInput.tsx +24 -0
- package/src/components/InputComponents/AudioRecorder.tsx +100 -0
- package/src/components/InputComponents/MediaInput.tsx +114 -0
- package/src/components/InputComponents/RecordingIndicator.tsx +77 -0
- package/src/components/InputComponents/Search.tsx +135 -0
- package/src/components/InputComponents/TextInput.tsx +66 -0
- package/src/components/MainComponents/ChatHeader.tsx +163 -0
- package/src/components/MainComponents/ChatRoom.tsx +392 -0
- package/src/components/MainComponents/ChatWrapper.tsx +318 -0
- package/src/components/MainComponents/ChooseChatMessage.tsx +44 -0
- package/src/components/MainComponents/ConnectionBanner.tsx +33 -0
- package/src/components/MainComponents/EditWrapper.tsx +72 -0
- package/src/components/MainComponents/LoginWrapper.tsx +134 -0
- package/src/components/MainComponents/MediaMessage.tsx +55 -0
- package/src/components/MainComponents/MessageContainer.tsx +122 -0
- package/src/components/MainComponents/MessageList.tsx +429 -0
- package/src/components/MainComponents/NoMessagesPlaceholder.tsx +49 -0
- package/src/components/MainComponents/ProfileImagePlaceholder.tsx +143 -0
- package/src/components/MainComponents/RNStyled.tsx +34 -0
- package/src/components/MainComponents/ReduxWrapper.tsx +40 -0
- package/src/components/MainComponents/RoomList.tsx +246 -0
- package/src/components/MainComponents/Select.tsx +165 -0
- package/src/components/MainComponents/Switch.tsx +73 -0
- package/src/components/MainComponents/SystemMessage.tsx +42 -0
- package/src/components/Menu/HeaderRoomListMenu.tsx +169 -0
- package/src/components/MenuRoom/MenuRoom.tsx +46 -0
- package/src/components/MessageBubble/Avatar.tsx +84 -0
- package/src/components/MessageBubble/BottomReplyContainer.tsx +117 -0
- package/src/components/MessageBubble/CustomDivider.tsx +10 -0
- package/src/components/MessageBubble/DeletedMessage.tsx +36 -0
- package/src/components/MessageBubble/Message.tsx +400 -0
- package/src/components/MessageBubble/MessageInteractions.tsx +247 -0
- package/src/components/MessageBubble/MessageReaction.tsx +149 -0
- package/src/components/MessageBubble/MessageReply.tsx +50 -0
- package/src/components/MessageBubble/MessageTranslations.tsx +30 -0
- package/src/components/Modals/AddMembersModal/AddMembersModal.tsx +142 -0
- package/src/components/Modals/ChatProfileModal/ChatProfileModal.tsx +471 -0
- package/src/components/Modals/ChatProfileModal/DeleteChatModal.tsx +91 -0
- package/src/components/Modals/FilePreviewModal/FilePreviewModal.tsx +298 -0
- package/src/components/Modals/Modal/Modal.tsx +52 -0
- package/src/components/Modals/ModalHeaderComponent.tsx +41 -0
- package/src/components/Modals/ModalSelectMedia/ModalSelectMedia.tsx +285 -0
- package/src/components/Modals/ModalWrapper/ModalWrapper.tsx +103 -0
- package/src/components/Modals/NewChatModal/ModalContent.tsx +151 -0
- package/src/components/Modals/NewChatModal/NewChatModal.tsx +391 -0
- package/src/components/Modals/NewChatModal/UpdNewChatModal.tsx +136 -0
- package/src/components/Modals/SelectUsersModal/SelectUsersModal.tsx +134 -0
- package/src/components/Modals/SettingsModals/BlockedUsers/BlockedUsersModal.tsx +63 -0
- package/src/components/Modals/SettingsModals/DocumentShares/DocumentSharesModal.tsx +115 -0
- package/src/components/Modals/SettingsModals/ManageDataModal/ManageDataModal.tsx +121 -0
- package/src/components/Modals/SettingsModals/ManageDataModal/StyledComponents.ts +0 -0
- package/src/components/Modals/SettingsModals/ProfileShares/ProfileShares.tsx +65 -0
- package/src/components/Modals/SettingsModals/Referrals/Referrals.tsx +90 -0
- package/src/components/Modals/SettingsModals/SharedStyledComponents.ts +74 -0
- package/src/components/Modals/SettingsModals/Visibility/RadioInput.tsx +59 -0
- package/src/components/Modals/SettingsModals/Visibility/StyledComponents.ts +32 -0
- package/src/components/Modals/SettingsModals/Visibility/VisibilityModal.tsx +146 -0
- package/src/components/Modals/UserProfileModal/EditUserModal.tsx +163 -0
- package/src/components/Modals/UserProfileModal/UserProfileModal.tsx +410 -0
- package/src/components/Modals/UserSettingsModal/UserSettingsModal.tsx +85 -0
- package/src/components/Modals/styledModalComponents.tsx +181 -0
- package/src/components/OperationalModal/OperationalModal.tsx +78 -0
- package/src/components/RoomComponents/ChatRoomItem.tsx +219 -0
- package/src/components/RoomComponents/LastMessageItem.tsx +47 -0
- package/src/components/RoomComponents/styled/LastAudioMessage.tsx +62 -0
- package/src/components/RoomComponents/styled/LastMessageEmoji.tsx +26 -0
- package/src/components/RoomComponents/styled/LastMessageFile.tsx +54 -0
- package/src/components/RoomComponents/styled/LastMessagePhoto.tsx +54 -0
- package/src/components/RoomComponents/styled/LastMessageVideo.tsx +70 -0
- package/src/components/RoomComponents/styled/LastTextMessage.tsx +65 -0
- package/src/components/RoomComponents/styled/StyledRoomComponents.ts +53 -0
- package/src/components/SortDropDown/index.tsx +76 -0
- package/src/components/Thread/ThreadHeader.tsx +41 -0
- package/src/components/Thread/ThreadWrapper.tsx +270 -0
- package/src/components/Toast/Toast.tsx +128 -0
- package/src/components/Toast/index.ts +13 -0
- package/src/components/UsersList/StyledComponents.ts +30 -0
- package/src/components/UsersList/UsersList.tsx +112 -0
- package/src/components/styled/ActionButton.tsx +40 -0
- package/src/components/styled/AudioMessage.tsx +82 -0
- package/src/components/styled/Button.tsx +107 -0
- package/src/components/styled/ChatWrapperBox.tsx +9 -0
- package/src/components/styled/DateLabel.tsx +77 -0
- package/src/components/styled/Loader.tsx +65 -0
- package/src/components/styled/MediaFilePreview.tsx +42 -0
- package/src/components/styled/MediaModal.tsx +54 -0
- package/src/components/styled/MessageImage.tsx +54 -0
- package/src/components/styled/NewMessageLabel.tsx +50 -0
- package/src/components/styled/RoomListComponents/index.tsx +164 -0
- package/src/components/styled/SendInput.tsx +297 -0
- package/src/components/styled/StyledComponents.ts +320 -0
- package/src/components/styled/StyledInput.tsx +101 -0
- package/src/components/styled/StyledInputComponents/AudioComponents.tsx +1 -0
- package/src/components/styled/StyledInputComponents/Composing.tsx +97 -0
- package/src/components/styled/StyledInputComponents/CustomTypingIndicator.tsx +261 -0
- package/src/components/styled/StyledInputComponents/MediaComponents.tsx +90 -0
- package/src/components/styled/StyledInputComponents/StyledInputComponents.tsx +131 -0
- package/src/components/styled/StyledInputComponents/VideoComponents.tsx +49 -0
- package/src/components/styled/TreadLabel.tsx +50 -0
- package/src/components/styled/UnsupportedType.tsx +95 -0
- package/src/components/styled/VideoMessage.tsx +68 -0
- package/src/context/MessageNotificationContext.tsx +335 -0
- package/src/context/PushNotificationProvider.tsx +78 -0
- package/src/context/ToastContext.tsx +63 -0
- package/src/context/toastProvider.tsx +0 -0
- package/src/context/xmppProvider.tsx +364 -0
- package/src/helpers/block_scroll.ts +95 -0
- package/src/helpers/chatAutoEnterer.ts +46 -0
- package/src/helpers/checkUniqueUsers.tsx +31 -0
- package/src/helpers/constants/CHAT_TYPES.ts +6 -0
- package/src/helpers/constants/LANGUAGE_OPTIONS.ts +14 -0
- package/src/helpers/constants/LOCAL_STORAGE.ts +3 -0
- package/src/helpers/constants/MESSAGE_INTERACTIONS.ts +29 -0
- package/src/helpers/constants/MODAL_TYPES.ts +57 -0
- package/src/helpers/constants/PLATFORM_CONSTANTS.ts +3 -0
- package/src/helpers/createMainMessageForThread.ts +23 -0
- package/src/helpers/createMessageFromXml.ts +118 -0
- package/src/helpers/createRoomFromApi.tsx +27 -0
- package/src/helpers/createUserNameFromSetUser.ts +15 -0
- package/src/helpers/dateComparison.ts +12 -0
- package/src/helpers/debounce.ts +10 -0
- package/src/helpers/ensureScopedChatCache.ts +61 -0
- package/src/helpers/extractUniqueMembersFromRooms.ts +45 -0
- package/src/helpers/formatNumberWithCommas.ts +3 -0
- package/src/helpers/getBooleanFromString.ts +7 -0
- package/src/helpers/getDataFromXml.ts +80 -0
- package/src/helpers/getNumberFromString.ts +5 -0
- package/src/helpers/getRoomsWithRetry.ts +45 -0
- package/src/helpers/getTintedColor.ts +28 -0
- package/src/helpers/getUnnamedUsers.ts +39 -0
- package/src/helpers/handleCopyClick.ts +3 -0
- package/src/helpers/handleXmppError.ts +14 -0
- package/src/helpers/hashcolor.ts +34 -0
- package/src/helpers/historyPreloadScheduler.ts +264 -0
- package/src/helpers/initRoomsPresence.ts +32 -0
- package/src/helpers/initXmppRooms.tsx +71 -0
- package/src/helpers/insertMessageWithDelimiter.ts +96 -0
- package/src/helpers/isChatIdPresentInArray.ts +54 -0
- package/src/helpers/localStorageUser.ts +9 -0
- package/src/helpers/markdownParser.tsx +295 -0
- package/src/helpers/nanoToMs.ts +3 -0
- package/src/helpers/parseMessageBody.tsx +516 -0
- package/src/helpers/parseUrls.tsx +42 -0
- package/src/helpers/resolveInitBeforeLoadUser.ts +240 -0
- package/src/helpers/storeConsole.ts +26 -0
- package/src/helpers/transformTranslatations.ts +16 -0
- package/src/helpers/updateMessagesTillLast.tsx +104 -0
- package/src/helpers/updatedChatLastTimestamps.ts +29 -0
- package/src/helpers/validator.ts +20 -0
- package/src/helpers/walletUsername.ts +12 -0
- package/src/hooks/hooks.ts +6 -0
- package/src/hooks/useChatSettingState.tsx +38 -0
- package/src/hooks/useChatWrapperInit.ts +266 -0
- package/src/hooks/useComposing.tsx +59 -0
- package/src/hooks/useCustomTypingIndicator.tsx +193 -0
- package/src/hooks/useEventHandlers.tsx +81 -0
- package/src/hooks/useGetNewArchRoom.tsx +57 -0
- package/src/hooks/useHeapSender.tsx +88 -0
- package/src/hooks/useLocalStorage.tsx +53 -0
- package/src/hooks/useLogout.tsx +31 -0
- package/src/hooks/useMessageHeapState.tsx +11 -0
- package/src/hooks/useMessageLoaderQueue.tsx +90 -0
- package/src/hooks/useMessageQueue.ts +146 -0
- package/src/hooks/usePendingNotification.ts +49 -0
- package/src/hooks/usePrevious.tsx +15 -0
- package/src/hooks/usePushNotifications.ts +106 -0
- package/src/hooks/useQRCodeChatHandler.ts +58 -0
- package/src/hooks/useRoomInitialization.tsx +160 -0
- package/src/hooks/useRoomState.tsx +47 -0
- package/src/hooks/useRoomUrl.tsx +41 -0
- package/src/hooks/useSendMessage.tsx +306 -0
- package/src/hooks/useUnreadMessagesCounter.ts +55 -0
- package/src/hooks/useXmppInitialization.ts +148 -0
- package/src/main.ts +45 -0
- package/src/networking/api-requests/auth.api.ts +140 -0
- package/src/networking/api-requests/push.api.ts +55 -0
- package/src/networking/api-requests/roomMembers.api.ts +20 -0
- package/src/networking/api-requests/rooms.api.ts +142 -0
- package/src/networking/api-requests/user.api.ts +65 -0
- package/src/networking/apiClient.ts +149 -0
- package/src/networking/helpers/refreshChecker.ts +13 -0
- package/src/networking/stanzaHandlers.ts +418 -0
- package/src/networking/xmpp/actionSetTimestampToPrivateStore.xmpp.ts +37 -0
- package/src/networking/xmpp/allRoomPresences.xmpp.ts +10 -0
- package/src/networking/xmpp/createPrivateRoom.xmpp.ts +26 -0
- package/src/networking/xmpp/createRoom.xmpp.ts +35 -0
- package/src/networking/xmpp/createRoomPresence.xmpp.ts +74 -0
- package/src/networking/xmpp/createTimeoutPromise.xmpp.ts +15 -0
- package/src/networking/xmpp/deleteMessage.xmpp.ts +19 -0
- package/src/networking/xmpp/editMessage.xmpp.ts +46 -0
- package/src/networking/xmpp/getChatsPrivateStoreRequest.xmpp.ts +57 -0
- package/src/networking/xmpp/getHistory.xmpp.ts +140 -0
- package/src/networking/xmpp/getLastMessageArchive.xmpp.ts +24 -0
- package/src/networking/xmpp/getRoomInfo.xmpp.ts +15 -0
- package/src/networking/xmpp/getRoomMembers.xmpp.ts +13 -0
- package/src/networking/xmpp/getRooms.xmpp.ts +43 -0
- package/src/networking/xmpp/getRoomsPaged.xmpp.ts +59 -0
- package/src/networking/xmpp/handlePong.xmpp.ts +7 -0
- package/src/networking/xmpp/handleStanzas.xmpp.ts +55 -0
- package/src/networking/xmpp/inviteRoomRequest.xmpp.ts +25 -0
- package/src/networking/xmpp/leaveTheRoom.xmpp.ts +15 -0
- package/src/networking/xmpp/listenerManager.ts +116 -0
- package/src/networking/xmpp/presenceInRoom.xmpp.ts +57 -0
- package/src/networking/xmpp/roomConfig.xmpp.ts +71 -0
- package/src/networking/xmpp/sendMediaMessage.xmpp.ts +97 -0
- package/src/networking/xmpp/sendMessageReaction.xmpp.ts +41 -0
- package/src/networking/xmpp/sendPing.xmpp.ts +21 -0
- package/src/networking/xmpp/sendTextMessage.xmpp.ts +99 -0
- package/src/networking/xmpp/sendTextMessageWithTranslateTag.xmpp.ts +44 -0
- package/src/networking/xmpp/sendTypingRequest.xmpp.ts +26 -0
- package/src/networking/xmpp/setChatsPrivateStoreRequest.xmpp.ts +48 -0
- package/src/networking/xmpp/setMeAsOwner.xmpp.ts +52 -0
- package/src/networking/xmpp/setRoomImage.xmpp.ts +26 -0
- package/src/networking/xmpp/setVCard.xmpp.ts +19 -0
- package/src/networking/xmpp/subscribeToRoomMessages.xmpp.ts +75 -0
- package/src/networking/xmppClient.ts +603 -0
- package/src/roomStore/Middleware/logoutMiddleware.tsx +24 -0
- package/src/roomStore/Middleware/newMessageMidlleware.tsx +87 -0
- package/src/roomStore/Middleware/reactionsMiddleware.tsx +77 -0
- package/src/roomStore/Middleware/testMiddleware.tsx +20 -0
- package/src/roomStore/Middleware/unreadMidlleware.tsx +58 -0
- package/src/roomStore/chatSettingsSlice.ts +178 -0
- package/src/roomStore/index.ts +68 -0
- package/src/roomStore/persistence.ts +152 -0
- package/src/roomStore/roomHeapSlice.ts +37 -0
- package/src/roomStore/roomsSlice.ts +353 -0
- package/src/services/pushNotifications.ts +170 -0
- package/src/services/pushSubscriptionService.ts +145 -0
- package/src/types/messages.ts +61 -0
- package/src/types/models/action.model.ts +30 -0
- package/src/types/models/config.model.ts +16 -0
- package/src/types/models/customComponents.model.ts +53 -0
- package/src/types/models/language.model.ts +11 -0
- package/src/types/models/media.model.ts +5 -0
- package/src/types/models/message.model.ts +69 -0
- package/src/types/models/modal.model.ts +9 -0
- package/src/types/models/room.model.ts +120 -0
- package/src/types/models/user.model.ts +90 -0
- package/src/types/models/xmpp.model.ts +155 -0
- package/src/types/types.ts +505 -0
- package/src/utils/PriorityQueue.ts +47 -0
- package/src/utils/actionHelpers.ts +40 -0
- package/src/utils/actionLogger.ts +64 -0
- package/src/utils/clientRegistry.ts +80 -0
- package/src/utils/devLogger.ts +197 -0
- package/src/utils/messageNotificationManager.ts +108 -0
- package/src/utils/resendMessage.ts +87 -0
- package/src/utils/toastEmitter.ts +27 -0
- package/src/utils/xmppMemoryMonitor.ts +63 -0
- package/src/version.ts +1 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Text, View, Linking, StyleSheet, TouchableOpacity } from 'react-native';
|
|
3
|
+
|
|
4
|
+
export const MarkDown = (text: string): (string | JSX.Element)[] => {
|
|
5
|
+
if (typeof text !== 'string') {return [text];}
|
|
6
|
+
|
|
7
|
+
let key = 0;
|
|
8
|
+
const elements: (string | JSX.Element)[] = [];
|
|
9
|
+
const lines = text.split('\n');
|
|
10
|
+
|
|
11
|
+
let inCodeBlock = false;
|
|
12
|
+
let codeLanguage = '';
|
|
13
|
+
const codeBuffer: string[] = [];
|
|
14
|
+
|
|
15
|
+
const parseInline = (input: string): (string | JSX.Element)[] => {
|
|
16
|
+
const output: (string | JSX.Element)[] = [];
|
|
17
|
+
|
|
18
|
+
const regex =
|
|
19
|
+
/(\*\*\*[^*]+?\*\*\*|\*\*[^*]+?\*\*|\*[^*]+?\*|~~[^~]+?~~|`[^`]+?`|https:\/\/[\w.-]+(?:\.[\w.-]+)+[\w\-._~:/?#[\]@!$&'()*+,;=]+)/g;
|
|
20
|
+
|
|
21
|
+
let lastIndex = 0;
|
|
22
|
+
let match;
|
|
23
|
+
|
|
24
|
+
while ((match = regex.exec(input)) !== null) {
|
|
25
|
+
if (match.index > lastIndex) {
|
|
26
|
+
output.push(input.slice(lastIndex, match.index));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const token = match[0];
|
|
30
|
+
if (/^\*\*\*.*\*\*\*$/.test(token)) {
|
|
31
|
+
output.push(
|
|
32
|
+
<Text key={`b-${key++}`} style={styles.bold}>
|
|
33
|
+
<Text style={styles.italic}>{token.slice(3, -3)}</Text>
|
|
34
|
+
</Text>
|
|
35
|
+
);
|
|
36
|
+
} else if (/^\*\*.*\*\*$/.test(token)) {
|
|
37
|
+
output.push(<Text key={`b-${key++}`} style={styles.bold}>{token.slice(2, -2)}</Text>);
|
|
38
|
+
} else if (/^\*.*\*$/.test(token)) {
|
|
39
|
+
output.push(<Text key={`i-${key++}`} style={styles.italic}>{token.slice(1, -1)}</Text>);
|
|
40
|
+
} else if (/^~~.*~~$/.test(token)) {
|
|
41
|
+
output.push(<Text key={`s-${key++}`} style={styles.strike}>{token.slice(2, -2)}</Text>);
|
|
42
|
+
} else if (/^`.*`$/.test(token)) {
|
|
43
|
+
output.push(
|
|
44
|
+
<Text
|
|
45
|
+
key={`code-${key++}`}
|
|
46
|
+
style={styles.codeInline}
|
|
47
|
+
>
|
|
48
|
+
{token.slice(1, -1).trim()}
|
|
49
|
+
</Text>
|
|
50
|
+
);
|
|
51
|
+
} else if (/^https:\/\//.test(token)) {
|
|
52
|
+
output.push(
|
|
53
|
+
<Text key={`link-${key++}`}>
|
|
54
|
+
<Text
|
|
55
|
+
onPress={() => Linking.openURL(token)}
|
|
56
|
+
style={styles.link}
|
|
57
|
+
>
|
|
58
|
+
{token}
|
|
59
|
+
</Text>
|
|
60
|
+
</Text>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
lastIndex = match.index + token.length;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (lastIndex < input.length) {
|
|
68
|
+
output.push(input.slice(lastIndex));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return output;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const parseList = (
|
|
75
|
+
startIndex: number
|
|
76
|
+
): { list: JSX.Element; newIndex: number } => {
|
|
77
|
+
const items: JSX.Element[] = [];
|
|
78
|
+
const line = lines[startIndex].trim();
|
|
79
|
+
const match = line.match(/^(\d+)\./);
|
|
80
|
+
const isOrdered = !!match;
|
|
81
|
+
const start = match ? parseInt(match[1], 10) : 1;
|
|
82
|
+
|
|
83
|
+
let i = startIndex;
|
|
84
|
+
while (i < lines.length) {
|
|
85
|
+
const currentLine = lines[i];
|
|
86
|
+
if (/^(\d+\.\s+|\-\s+)/.test(currentLine)) {
|
|
87
|
+
const itemText = currentLine.replace(/^(\d+\.\s+|\-\s+)/, '');
|
|
88
|
+
items.push(
|
|
89
|
+
<View key={`li-${key++}`} style={styles.listItem}>
|
|
90
|
+
<Text style={styles.listMarker}>{isOrdered ? `${start + items.length - 1}.` : '•'}</Text>
|
|
91
|
+
<View style={styles.listItemContent}>
|
|
92
|
+
{parseInline(itemText).map((el, idx) => (
|
|
93
|
+
<React.Fragment key={idx}>{el}</React.Fragment>
|
|
94
|
+
))}
|
|
95
|
+
</View>
|
|
96
|
+
</View>
|
|
97
|
+
);
|
|
98
|
+
} else if (currentLine.trim() === '') {
|
|
99
|
+
break;
|
|
100
|
+
} else {
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
i++;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const ListTag = isOrdered ? 'ol' : 'ul';
|
|
107
|
+
return {
|
|
108
|
+
list: (
|
|
109
|
+
<View key={`list-${key++}`} style={styles.list}>
|
|
110
|
+
{items}
|
|
111
|
+
</View>
|
|
112
|
+
),
|
|
113
|
+
newIndex: i - 1,
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
for (let idx = 0; idx < lines.length; idx++) {
|
|
118
|
+
const line = lines[idx];
|
|
119
|
+
|
|
120
|
+
if (!inCodeBlock && line.trim().startsWith('```')) {
|
|
121
|
+
const match = line.trim().match(/^```(?:\s*(\w+))?/);
|
|
122
|
+
inCodeBlock = true;
|
|
123
|
+
codeLanguage = match?.[1] || '';
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (inCodeBlock && line.trim() === '```') {
|
|
128
|
+
inCodeBlock = false;
|
|
129
|
+
elements.push(
|
|
130
|
+
<View
|
|
131
|
+
key={`pre-${key++}`}
|
|
132
|
+
style={styles.codeBlock}
|
|
133
|
+
>
|
|
134
|
+
<Text style={styles.codeBlockText}>
|
|
135
|
+
{codeBuffer.join('\n')}
|
|
136
|
+
</Text>
|
|
137
|
+
</View>
|
|
138
|
+
);
|
|
139
|
+
codeBuffer.length = 0;
|
|
140
|
+
codeLanguage = '';
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (inCodeBlock) {
|
|
145
|
+
codeBuffer.push(line);
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (/^#{1,6}\s/.test(line)) {
|
|
150
|
+
const level = line.match(/^#+/)![0].length;
|
|
151
|
+
const content = line.replace(/^#{1,6}\s/, '');
|
|
152
|
+
const headingStyle = styles[`h${level}` as keyof typeof styles] || styles.h1;
|
|
153
|
+
elements.push(
|
|
154
|
+
<Text key={`h-${key++}`} style={headingStyle}>
|
|
155
|
+
{parseInline(content).map((el, idx) => (
|
|
156
|
+
<React.Fragment key={idx}>{el}</React.Fragment>
|
|
157
|
+
))}
|
|
158
|
+
</Text>
|
|
159
|
+
);
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (line.startsWith('>')) {
|
|
164
|
+
elements.push(
|
|
165
|
+
<View
|
|
166
|
+
key={`quote-${key++}`}
|
|
167
|
+
style={styles.quote}
|
|
168
|
+
>
|
|
169
|
+
{parseInline(line.replace(/^>\s*/, '')).map((el, idx) => (
|
|
170
|
+
<React.Fragment key={idx}>{el}</React.Fragment>
|
|
171
|
+
))}
|
|
172
|
+
</View>
|
|
173
|
+
);
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (/^(\-|\d+\.)\s+/.test(line)) {
|
|
178
|
+
const { list, newIndex } = parseList(idx);
|
|
179
|
+
elements.push(list);
|
|
180
|
+
idx = newIndex;
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (line.trim() === '') {
|
|
185
|
+
elements.push(<View key={`br-${key++}`} style={styles.break} />);
|
|
186
|
+
} else {
|
|
187
|
+
elements.push(
|
|
188
|
+
<Text key={`p-${key++}`} style={styles.paragraph}>
|
|
189
|
+
{parseInline(line).map((el, idx) => (
|
|
190
|
+
<React.Fragment key={idx}>{el}</React.Fragment>
|
|
191
|
+
))}
|
|
192
|
+
</Text>
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return elements;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
const styles = StyleSheet.create({
|
|
201
|
+
bold: {
|
|
202
|
+
fontWeight: 'bold',
|
|
203
|
+
},
|
|
204
|
+
italic: {
|
|
205
|
+
fontStyle: 'italic',
|
|
206
|
+
},
|
|
207
|
+
strike: {
|
|
208
|
+
textDecorationLine: 'line-through',
|
|
209
|
+
},
|
|
210
|
+
codeInline: {
|
|
211
|
+
backgroundColor: '#eee',
|
|
212
|
+
paddingHorizontal: 4,
|
|
213
|
+
paddingVertical: 1,
|
|
214
|
+
borderRadius: 4,
|
|
215
|
+
fontFamily: 'monospace',
|
|
216
|
+
fontSize: 14,
|
|
217
|
+
},
|
|
218
|
+
link: {
|
|
219
|
+
color: 'blue',
|
|
220
|
+
textDecorationLine: 'underline',
|
|
221
|
+
},
|
|
222
|
+
codeBlock: {
|
|
223
|
+
backgroundColor: '#f0f0f0',
|
|
224
|
+
padding: 10,
|
|
225
|
+
borderRadius: 8,
|
|
226
|
+
marginVertical: 8,
|
|
227
|
+
},
|
|
228
|
+
codeBlockText: {
|
|
229
|
+
fontFamily: 'monospace',
|
|
230
|
+
fontSize: 14,
|
|
231
|
+
},
|
|
232
|
+
h1: {
|
|
233
|
+
fontSize: 32,
|
|
234
|
+
fontWeight: 'bold',
|
|
235
|
+
marginTop: 24,
|
|
236
|
+
marginBottom: 16,
|
|
237
|
+
},
|
|
238
|
+
h2: {
|
|
239
|
+
fontSize: 24,
|
|
240
|
+
fontWeight: 'bold',
|
|
241
|
+
marginTop: 20,
|
|
242
|
+
marginBottom: 14,
|
|
243
|
+
},
|
|
244
|
+
h3: {
|
|
245
|
+
fontSize: 20,
|
|
246
|
+
fontWeight: 'bold',
|
|
247
|
+
marginTop: 16,
|
|
248
|
+
marginBottom: 12,
|
|
249
|
+
},
|
|
250
|
+
h4: {
|
|
251
|
+
fontSize: 18,
|
|
252
|
+
fontWeight: 'bold',
|
|
253
|
+
marginTop: 14,
|
|
254
|
+
marginBottom: 10,
|
|
255
|
+
},
|
|
256
|
+
h5: {
|
|
257
|
+
fontSize: 16,
|
|
258
|
+
fontWeight: 'bold',
|
|
259
|
+
marginTop: 12,
|
|
260
|
+
marginBottom: 8,
|
|
261
|
+
},
|
|
262
|
+
h6: {
|
|
263
|
+
fontSize: 14,
|
|
264
|
+
fontWeight: 'bold',
|
|
265
|
+
marginTop: 12,
|
|
266
|
+
marginBottom: 8,
|
|
267
|
+
},
|
|
268
|
+
quote: {
|
|
269
|
+
borderLeftWidth: 3,
|
|
270
|
+
borderLeftColor: '#ccc',
|
|
271
|
+
paddingLeft: 10,
|
|
272
|
+
marginVertical: 4,
|
|
273
|
+
},
|
|
274
|
+
list: {
|
|
275
|
+
marginVertical: 8,
|
|
276
|
+
paddingLeft: 20,
|
|
277
|
+
},
|
|
278
|
+
listItem: {
|
|
279
|
+
flexDirection: 'row',
|
|
280
|
+
marginBottom: 4,
|
|
281
|
+
},
|
|
282
|
+
listMarker: {
|
|
283
|
+
marginRight: 8,
|
|
284
|
+
minWidth: 20,
|
|
285
|
+
},
|
|
286
|
+
listItemContent: {
|
|
287
|
+
flex: 1,
|
|
288
|
+
},
|
|
289
|
+
paragraph: {
|
|
290
|
+
marginVertical: 4,
|
|
291
|
+
},
|
|
292
|
+
break: {
|
|
293
|
+
height: 8,
|
|
294
|
+
},
|
|
295
|
+
});
|