* Viewing Files in Edit mode in mobile with ability to delete and save * Added upload attachment to keyboard tracker view * using state instread of use ref * Minor * Added tests * intl extract * new function getFiles ById, batch file deletion and tests * Files fetching in edit options and tests * Removed DeviceEventEmitter and used React context * Added support to check minimum required version to show edit file attachments * resolve forward ref issue * Minor * memotized props for context and observe config with value * Ability to show quick action and add files to edit post * type safety for EditPostContext * Reverted back the post priority props * constant shift * Added test for QuickAction to show slashcomand * Added test for edit_post, upload_item and upload_remove * Added test for Edit_post_input and edit_post index * fix the height issue between attachment and keyboard due to safeArea * Minor: removed debugging border color * Changed the Edited text style in the post from (edited) to icon + Edited * Import fixes * Ability to show quick action and add files to edit post * type safety for EditPostContext * Reverted back the post priority props * constant shift * Added test for QuickAction to show slashcomand * Added test for edit_post, upload_item and upload_remove * Added test for Edit_post_input and edit_post index * fix the height issue between attachment and keyboard due to safeArea * Minor: removed debugging border color * Addressed dev review comments * Import fixes * Address UX comments * Fixed props for UploadItem and remove effective Edit mode * handled save button disabled state when uploading attachments * handled newly added and retry file removal without alert message * Test updated * Added test for input_quick_action index.tsx * Added test for not in edit mode for upload_item index * Added test for upload_remove component when not in edit mode * added tests for file_upload_error hook * Added test for calling callback when in edit mode * Test for edit post input for server version check * linter fixes * Changed font size from 16 to 14px for edited * separated common component and test * Removed the margin styles from the text as it is not been applied. * removed the duplicate code from rebase
113 lines
3.2 KiB
TypeScript
113 lines
3.2 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {Node, Parser} from 'commonmark';
|
|
import Renderer from 'commonmark-react-renderer';
|
|
import React, {type ReactElement, useRef} from 'react';
|
|
import {type StyleProp, StyleSheet, Text, type TextStyle, View} from 'react-native';
|
|
|
|
import EditedIndicator from '@components/EditedIndicator';
|
|
import Emoji from '@components/emoji';
|
|
import {useTheme} from '@context/theme';
|
|
|
|
type JumboEmojiProps = {
|
|
baseTextStyle: StyleProp<TextStyle>;
|
|
isEdited?: boolean;
|
|
value: string;
|
|
}
|
|
|
|
const style = StyleSheet.create({
|
|
block: {
|
|
alignItems: 'flex-start',
|
|
flexDirection: 'row',
|
|
flexWrap: 'wrap',
|
|
},
|
|
jumboEmoji: {
|
|
fontSize: 50,
|
|
lineHeight: 60,
|
|
},
|
|
newLine: {
|
|
lineHeight: 60,
|
|
},
|
|
});
|
|
|
|
const JumboEmoji = ({baseTextStyle, isEdited, value}: JumboEmojiProps) => {
|
|
const theme = useTheme();
|
|
|
|
const renderEmoji = ({emojiName, literal}: {context: string[]; emojiName: string; literal: string}) => {
|
|
return (
|
|
<View>
|
|
<Emoji
|
|
emojiName={emojiName}
|
|
literal={literal}
|
|
testID='markdown_emoji'
|
|
textStyle={[baseTextStyle, style.jumboEmoji]}
|
|
/>
|
|
</View>
|
|
);
|
|
};
|
|
|
|
const renderParagraph = ({children}: {children: ReactElement}) => {
|
|
return (
|
|
<View style={style.block}><Text>{children}</Text></View>
|
|
);
|
|
};
|
|
|
|
const renderText = ({literal}: {literal: string}) => {
|
|
return renderEmoji({emojiName: literal, literal, context: []});
|
|
};
|
|
|
|
const renderNewLine = () => {
|
|
return <Text style={[baseTextStyle, style.newLine]}>{'\n'}</Text>;
|
|
};
|
|
|
|
const renderEditedIndicator = ({context}: {context: string[]}) => {
|
|
return (
|
|
<EditedIndicator
|
|
baseTextStyle={baseTextStyle}
|
|
theme={theme}
|
|
context={context}
|
|
iconSize={14}
|
|
checkHeadings={false}
|
|
testID='edited_indicator'
|
|
/>
|
|
);
|
|
};
|
|
|
|
const createRenderer = () => {
|
|
const renderers: any = {
|
|
editedIndicator: renderEditedIndicator,
|
|
emoji: renderEmoji,
|
|
paragraph: renderParagraph,
|
|
document: renderParagraph,
|
|
text: renderText,
|
|
hardbreak: renderNewLine,
|
|
softBreak: renderNewLine,
|
|
};
|
|
|
|
return new Renderer({
|
|
renderers,
|
|
renderParagraphsInLists: true,
|
|
});
|
|
};
|
|
|
|
const parser = useRef(new Parser()).current;
|
|
const renderer = useRef(createRenderer()).current;
|
|
const ast = parser.parse(value.replace(/\n*$/, ''));
|
|
|
|
if (isEdited) {
|
|
const editIndicatorNode = new Node('edited_indicator');
|
|
if (ast.lastChild && ['heading', 'paragraph'].includes(ast.lastChild.type)) {
|
|
ast.appendChild(editIndicatorNode);
|
|
} else {
|
|
const node = new Node('paragraph');
|
|
node.appendChild(editIndicatorNode);
|
|
|
|
ast.appendChild(node);
|
|
}
|
|
}
|
|
|
|
return renderer.render(ast) as ReactElement;
|
|
};
|
|
|
|
export default JumboEmoji;
|