@expensify/react-native-live-markdown 0.1.315 → 0.1.317

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 (44) hide show
  1. package/README.md +5 -5
  2. package/RNLiveMarkdown.podspec +7 -20
  3. package/android/build.gradle +4 -16
  4. package/android/src/main/cpp/CMakeLists.txt +5 -23
  5. package/android/src/main/java/com/expensify/livemarkdown/MarkdownFormatter.java +3 -3
  6. package/android/src/main/java/com/expensify/livemarkdown/MarkdownStyle.java +23 -0
  7. package/android/src/main/java/com/expensify/livemarkdown/spans/MarkdownBackgroundSpan.java +94 -0
  8. package/apple/MarkdownFormatter.h +2 -0
  9. package/apple/MarkdownFormatter.mm +36 -6
  10. package/apple/MarkdownParser.mm +0 -4
  11. package/apple/MarkdownTextInputDecoratorComponentView.mm +17 -2
  12. package/apple/{BlockquoteTextLayoutFragment.h → MarkdownTextLayoutFragment.h} +4 -1
  13. package/apple/MarkdownTextLayoutFragment.mm +160 -0
  14. package/apple/MarkdownTextLayoutManagerDelegate.mm +22 -4
  15. package/apple/RCTMarkdownStyle.h +3 -0
  16. package/apple/RCTMarkdownStyle.mm +3 -0
  17. package/apple/RCTMarkdownTextBackground.h +9 -0
  18. package/apple/RCTMarkdownTextBackground.mm +4 -0
  19. package/apple/RCTMarkdownTextBackgroundWithRange.h +10 -0
  20. package/apple/RCTMarkdownTextBackgroundWithRange.mm +5 -0
  21. package/cpp/MarkdownGlobal.h +0 -4
  22. package/cpp/RuntimeDecorator.cpp +1 -6
  23. package/lib/commonjs/MarkdownTextInput.js +6 -4
  24. package/lib/commonjs/MarkdownTextInput.js.map +1 -1
  25. package/lib/commonjs/parseExpensiMark.js.map +1 -1
  26. package/lib/commonjs/styleUtils.js +6 -3
  27. package/lib/commonjs/styleUtils.js.map +1 -1
  28. package/lib/module/MarkdownTextInput.js +6 -4
  29. package/lib/module/MarkdownTextInput.js.map +1 -1
  30. package/lib/module/parseExpensiMark.js.map +1 -1
  31. package/lib/module/styleUtils.js +6 -3
  32. package/lib/module/styleUtils.js.map +1 -1
  33. package/lib/typescript/src/MarkdownTextInput.d.ts +3 -2
  34. package/lib/typescript/src/MarkdownTextInput.d.ts.map +1 -1
  35. package/lib/typescript/src/commonTypes.d.ts +1 -55
  36. package/lib/typescript/src/commonTypes.d.ts.map +1 -1
  37. package/lib/typescript/src/parseExpensiMark.d.ts.map +1 -1
  38. package/lib/typescript/src/styleUtils.d.ts.map +1 -1
  39. package/package.json +1 -8
  40. package/src/MarkdownTextInput.tsx +7 -6
  41. package/src/commonTypes.ts +1 -75
  42. package/src/parseExpensiMark.ts +2 -1
  43. package/src/styleUtils.ts +3 -0
  44. package/apple/BlockquoteTextLayoutFragment.mm +0 -51
@@ -1,19 +1,20 @@
1
1
  import {StyleSheet, TextInput, processColor} from 'react-native';
2
2
  import React from 'react';
3
3
  import type {TextInputProps} from 'react-native';
4
- import {createWorkletRuntime, makeShareableCloneRecursive} from 'react-native-reanimated';
4
+ import {createSerializable, createWorkletRuntime} from 'react-native-worklets';
5
+ import type {SerializableRef, WorkletFunction, WorkletRuntime} from 'react-native-worklets';
5
6
  import MarkdownTextInputDecoratorViewNativeComponent from './MarkdownTextInputDecoratorViewNativeComponent';
6
7
  import type {MarkdownStyle} from './MarkdownTextInputDecoratorViewNativeComponent';
7
8
  import NativeLiveMarkdownModule from './NativeLiveMarkdownModule';
8
9
  import {mergeMarkdownStyleWithDefault} from './styleUtils';
9
10
  import type {PartialMarkdownStyle} from './styleUtils';
10
- import type {InlineImagesInputProps, MarkdownRange, ShareableRef, WorkletFunction, WorkletRuntime} from './commonTypes';
11
+ import type {InlineImagesInputProps, MarkdownRange} from './commonTypes';
11
12
 
12
13
  declare global {
13
14
  // eslint-disable-next-line no-var
14
15
  var jsi_setMarkdownRuntime: (runtime: WorkletRuntime) => void;
15
16
  // eslint-disable-next-line no-var
16
- var jsi_registerMarkdownWorklet: (shareableWorklet: ShareableRef<WorkletFunction<[string], MarkdownRange[]>>) => number;
17
+ var jsi_registerMarkdownWorklet: (shareableWorklet: SerializableRef<WorkletFunction<[string], MarkdownRange[]>>) => number;
17
18
  // eslint-disable-next-line no-var
18
19
  var jsi_unregisterMarkdownWorklet: (parserId: number) => void;
19
20
  }
@@ -40,15 +41,15 @@ function initializeLiveMarkdownIfNeeded() {
40
41
  if (!global.jsi_setMarkdownRuntime) {
41
42
  throw new Error('[react-native-live-markdown] global.jsi_setMarkdownRuntime is not available');
42
43
  }
43
- workletRuntime = createWorkletRuntime('LiveMarkdownRuntime');
44
+ workletRuntime = createWorkletRuntime({name: 'LiveMarkdownRuntime'});
44
45
  global.jsi_setMarkdownRuntime(workletRuntime);
45
46
  initialized = true;
46
47
  }
47
48
 
48
49
  function registerParser(parser: (input: string) => MarkdownRange[]): number {
49
50
  initializeLiveMarkdownIfNeeded();
50
- const shareableWorklet = makeShareableCloneRecursive(parser) as unknown as ShareableRef<WorkletFunction<[string], MarkdownRange[]>>;
51
- const parserId = global.jsi_registerMarkdownWorklet(shareableWorklet);
51
+ const serializableWorklet = createSerializable(parser as WorkletFunction<[string], MarkdownRange[]>);
52
+ const parserId = global.jsi_registerMarkdownWorklet(serializableWorklet);
52
53
  return parserId;
53
54
  }
54
55
 
@@ -29,78 +29,4 @@ type InlineImagesInputProps = {
29
29
  imagePreviewAuthRequiredURLs?: string[];
30
30
  };
31
31
 
32
- // Temporary types from `react-native-reanimated` and `react-native-worklets`
33
- // TODO: remove once `react-native-reanimated` dependency is removed
34
-
35
- type WorkletStackDetails = [error: Error, lineOffset: number, columnOffset: number];
36
-
37
- type WorkletClosure = Record<string, unknown>;
38
-
39
- interface WorkletInitData {
40
- code: string;
41
- /** Only in dev builds. */
42
- location?: string;
43
- /** Only in dev builds. */
44
- sourceMap?: string;
45
- }
46
-
47
- interface WorkletProps {
48
- __closure: WorkletClosure;
49
- __workletHash: number;
50
- /** Only in Legacy Bundling. */
51
- __initData?: WorkletInitData;
52
- /** Only for Handles. */
53
- __init?: () => unknown;
54
- /** `__stackDetails` is removed after parsing. */
55
- __stackDetails?: WorkletStackDetails;
56
- /** Only in dev builds. */
57
- __pluginVersion?: string;
58
- }
59
-
60
- type WorkletFunctionWorklets<TArgs extends unknown[] = unknown[], TReturn = unknown> = ((...args: TArgs) => TReturn) & WorkletProps;
61
-
62
- interface WorkletInitDataCommon {
63
- code: string;
64
- }
65
-
66
- type WorkletInitDataRelease = WorkletInitDataCommon;
67
-
68
- interface WorkletInitDataDev extends WorkletInitDataCommon {
69
- location: string;
70
- sourceMap: string;
71
- version: string;
72
- }
73
-
74
- interface WorkletBaseCommon {
75
- __closure: WorkletClosure;
76
- __workletHash: number;
77
- }
78
-
79
- interface WorkletBaseRelease extends WorkletBaseCommon {
80
- __initData: WorkletInitDataRelease;
81
- }
82
-
83
- interface WorkletBaseDev extends WorkletBaseCommon {
84
- __initData: WorkletInitDataDev;
85
- /** `__stackDetails` is removed after parsing. */
86
- __stackDetails?: WorkletStackDetails;
87
- }
88
-
89
- type WorkletFunctionDev<Args extends unknown[] = unknown[], ReturnValue = unknown> = ((...args: Args) => ReturnValue) & WorkletBaseDev;
90
-
91
- type WorkletFunctionRelease<Args extends unknown[] = unknown[], ReturnValue = unknown> = ((...args: Args) => ReturnValue) & WorkletBaseRelease;
92
-
93
- type WorkletFunctionReanimated<Args extends unknown[] = unknown[], ReturnValue = unknown> = WorkletFunctionDev<Args, ReturnValue> | WorkletFunctionRelease<Args, ReturnValue>;
94
-
95
- type WorkletFunction<T extends unknown[], U> = WorkletFunctionWorklets<T, U> | WorkletFunctionReanimated<T, U>;
96
-
97
- type ShareableRef<T = unknown> = {
98
- __hostObjectShareableJSRef: T;
99
- };
100
-
101
- type WorkletRuntime = {
102
- __hostObjectWorkletRuntime: never;
103
- readonly name: string;
104
- };
105
-
106
- export type {MarkdownType, MarkdownRange, InlineImagesInputProps, WorkletFunction, ShareableRef, WorkletRuntime};
32
+ export type {MarkdownType, MarkdownRange, InlineImagesInputProps};
@@ -4,8 +4,9 @@ import {Platform} from 'react-native';
4
4
  import {ExpensiMark} from 'expensify-common';
5
5
  import {unescapeText} from 'expensify-common/dist/utils';
6
6
  import {decode} from 'html-entities';
7
- import type {MarkdownType, MarkdownRange, WorkletFunction} from './commonTypes';
7
+ import type {WorkletFunction} from 'react-native-worklets';
8
8
  import {groupRanges, sortRanges, excludeRangeTypesFromFormatting, getRangesToExcludeFormatting} from './rangeUtils';
9
+ import type {MarkdownRange, MarkdownType} from './commonTypes';
9
10
 
10
11
  function isWeb() {
11
12
  return Platform.OS === 'web';
package/src/styleUtils.ts CHANGED
@@ -62,14 +62,17 @@ function makeDefaultMarkdownStyle(): MarkdownStyle {
62
62
  mentionHere: {
63
63
  color: 'green',
64
64
  backgroundColor: 'lime',
65
+ borderRadius: 5,
65
66
  },
66
67
  mentionUser: {
67
68
  color: 'blue',
68
69
  backgroundColor: 'cyan',
70
+ borderRadius: 5,
69
71
  },
70
72
  mentionReport: {
71
73
  color: 'red',
72
74
  backgroundColor: 'pink',
75
+ borderRadius: 5,
73
76
  },
74
77
  inlineImage: {
75
78
  minWidth: 50,
@@ -1,51 +0,0 @@
1
- #import <RNLiveMarkdown/BlockquoteTextLayoutFragment.h>
2
-
3
- @implementation BlockquoteTextLayoutFragment
4
-
5
- - (CGRect)boundingRect {
6
- CGRect fragmentTextBounds = CGRectNull;
7
- for (NSTextLineFragment *lineFragment in self.textLineFragments) {
8
- if (lineFragment.characterRange.length == 0) {
9
- continue;
10
- }
11
- CGRect lineFragmentBounds = lineFragment.typographicBounds;
12
- if (CGRectIsNull(fragmentTextBounds)) {
13
- fragmentTextBounds = lineFragmentBounds;
14
- } else {
15
- fragmentTextBounds = CGRectUnion(fragmentTextBounds, lineFragmentBounds);
16
- }
17
- }
18
-
19
- CGFloat marginLeft = _markdownUtils.markdownStyle.blockquoteMarginLeft;
20
- CGFloat borderWidth = _markdownUtils.markdownStyle.blockquoteBorderWidth;
21
- CGFloat paddingLeft = _markdownUtils.markdownStyle.blockquotePaddingLeft;
22
- CGFloat shift = marginLeft + borderWidth + paddingLeft;
23
-
24
- fragmentTextBounds.origin.x -= (paddingLeft + borderWidth) + shift * (_depth - 1);
25
- fragmentTextBounds.size.width = borderWidth + shift * (_depth - 1);
26
-
27
- return fragmentTextBounds;
28
- }
29
-
30
- - (void)drawAtPoint:(CGPoint)point inContext:(CGContextRef)ctx {
31
- CGFloat marginLeft = _markdownUtils.markdownStyle.blockquoteMarginLeft;
32
- CGFloat borderWidth = _markdownUtils.markdownStyle.blockquoteBorderWidth;
33
- CGFloat paddingLeft = _markdownUtils.markdownStyle.blockquotePaddingLeft;
34
- CGFloat shift = marginLeft + borderWidth + paddingLeft;
35
-
36
- [_markdownUtils.markdownStyle.blockquoteBorderColor setFill];
37
-
38
- CGRect boundingRect = self.boundingRect;
39
- for (NSUInteger i = 0; i < _depth; ++i) {
40
- CGRect ribbonRect = CGRectMake(boundingRect.origin.x + i * shift, boundingRect.origin.y, borderWidth, boundingRect.size.height);
41
- UIRectFill(ribbonRect);
42
- }
43
-
44
- [super drawAtPoint:point inContext:ctx];
45
- }
46
-
47
- - (CGRect)renderingSurfaceBounds {
48
- return CGRectUnion(self.boundingRect, [super renderingSurfaceBounds]);
49
- }
50
-
51
- @end