@expensify/react-native-live-markdown 0.1.61 → 0.1.63

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.
Files changed (38) hide show
  1. package/android/src/main/java/com/expensify/livemarkdown/MarkdownStyle.java +18 -0
  2. package/android/src/main/java/com/expensify/livemarkdown/MarkdownUtils.java +4 -0
  3. package/ios/RCTMarkdownStyle.h +2 -0
  4. package/ios/RCTMarkdownStyle.mm +6 -0
  5. package/ios/RCTMarkdownUtils.mm +3 -0
  6. package/lib/commonjs/MarkdownTextInput.web.js +7 -3
  7. package/lib/commonjs/MarkdownTextInput.web.js.map +1 -1
  8. package/lib/commonjs/MarkdownTextInputDecoratorViewNativeComponent.js.map +1 -1
  9. package/lib/commonjs/styleUtils.js +4 -0
  10. package/lib/commonjs/styleUtils.js.map +1 -1
  11. package/lib/commonjs/web/cursorUtils.js +4 -0
  12. package/lib/commonjs/web/cursorUtils.js.map +1 -1
  13. package/lib/commonjs/web/parserUtils.js +3 -0
  14. package/lib/commonjs/web/parserUtils.js.map +1 -1
  15. package/lib/module/MarkdownTextInput.web.js +7 -3
  16. package/lib/module/MarkdownTextInput.web.js.map +1 -1
  17. package/lib/module/MarkdownTextInputDecoratorViewNativeComponent.js.map +1 -1
  18. package/lib/module/styleUtils.js +4 -0
  19. package/lib/module/styleUtils.js.map +1 -1
  20. package/lib/module/web/cursorUtils.js +4 -0
  21. package/lib/module/web/cursorUtils.js.map +1 -1
  22. package/lib/module/web/parserUtils.js +3 -0
  23. package/lib/module/web/parserUtils.js.map +1 -1
  24. package/lib/parser/react-native-live-markdown-parser.js +17 -17
  25. package/lib/typescript/src/MarkdownTextInput.web.d.ts.map +1 -1
  26. package/lib/typescript/src/MarkdownTextInputDecoratorViewNativeComponent.d.ts +4 -0
  27. package/lib/typescript/src/MarkdownTextInputDecoratorViewNativeComponent.d.ts.map +1 -1
  28. package/lib/typescript/src/styleUtils.d.ts.map +1 -1
  29. package/lib/typescript/src/web/cursorUtils.d.ts.map +1 -1
  30. package/lib/typescript/src/web/parserUtils.d.ts +1 -1
  31. package/lib/typescript/src/web/parserUtils.d.ts.map +1 -1
  32. package/package.json +1 -1
  33. package/parser/react-native-live-markdown-parser.js +17 -17
  34. package/src/MarkdownTextInput.web.tsx +7 -3
  35. package/src/MarkdownTextInputDecoratorViewNativeComponent.ts +4 -0
  36. package/src/styleUtils.ts +4 -0
  37. package/src/web/cursorUtils.ts +5 -0
  38. package/src/web/parserUtils.ts +4 -1
@@ -437,9 +437,13 @@ const MarkdownTextInput = React.forwardRef<TextInput, MarkdownTextInputProps>(
437
437
  currentlyFocusedField.current = hostNode;
438
438
  setEventProps(e);
439
439
  if (divRef.current) {
440
- const valueLength = value ? value.length : 0;
441
- CursorUtils.setCursorPosition(divRef.current, contentSelection.current ? contentSelection.current.end : valueLength);
442
- updateSelection(event);
440
+ if (contentSelection.current) {
441
+ CursorUtils.setCursorPosition(divRef.current, contentSelection.current.start, contentSelection.current.end);
442
+ } else {
443
+ const valueLength = value ? value.length : divRef.current.innerText.length;
444
+ CursorUtils.setCursorPosition(divRef.current, valueLength, null);
445
+ }
446
+ updateSelection(event, contentSelection.current);
443
447
  }
444
448
 
445
449
  if (onFocus) {
@@ -42,6 +42,10 @@ interface MarkdownStyle {
42
42
  color: ColorValue;
43
43
  backgroundColor: ColorValue;
44
44
  };
45
+ mentionReport: {
46
+ color: ColorValue;
47
+ backgroundColor: ColorValue;
48
+ };
45
49
  }
46
50
 
47
51
  interface NativeProps extends ViewProps {
package/src/styleUtils.ts CHANGED
@@ -52,6 +52,10 @@ function makeDefaultMarkdownStyle(): MarkdownStyle {
52
52
  color: 'blue',
53
53
  backgroundColor: 'cyan',
54
54
  },
55
+ mentionReport: {
56
+ color: 'red',
57
+ backgroundColor: 'pink',
58
+ },
55
59
  };
56
60
  }
57
61
 
@@ -28,6 +28,11 @@ function setPrevText(target: HTMLElement) {
28
28
  }
29
29
 
30
30
  function setCursorPosition(target: HTMLElement, start: number, end: number | null = null) {
31
+ // We don't want to move the cursor if the target is not focused
32
+ if (target !== document.activeElement) {
33
+ return;
34
+ }
35
+
31
36
  const range = document.createRange();
32
37
  range.selectNodeContents(target);
33
38
 
@@ -4,7 +4,7 @@ import * as BrowserUtils from './browserUtils';
4
4
 
5
5
  type PartialMarkdownStyle = StyleUtilsTypes.PartialMarkdownStyle;
6
6
 
7
- type MarkdownType = 'bold' | 'italic' | 'strikethrough' | 'emoji' | 'link' | 'code' | 'pre' | 'blockquote' | 'h1' | 'syntax' | 'mention-here' | 'mention-user';
7
+ type MarkdownType = 'bold' | 'italic' | 'strikethrough' | 'emoji' | 'link' | 'code' | 'pre' | 'blockquote' | 'h1' | 'syntax' | 'mention-here' | 'mention-user' | 'mention-report';
8
8
 
9
9
  type MarkdownRange = {
10
10
  type: MarkdownType;
@@ -42,6 +42,9 @@ function addStyling(targetElement: HTMLElement, type: MarkdownType, markdownStyl
42
42
  case 'mention-user':
43
43
  Object.assign(node.style, markdownStyle.mentionUser);
44
44
  break;
45
+ case 'mention-report':
46
+ Object.assign(node.style, markdownStyle.mentionReport);
47
+ break;
45
48
  case 'link':
46
49
  Object.assign(node.style, {
47
50
  ...markdownStyle.link,