@expensify/react-native-live-markdown 0.1.203 → 0.1.204

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.
@@ -198,7 +198,7 @@ RootShadowNode::Unshared MarkdownCommitHook::shadowTreeWillCommit(
198
198
 
199
199
  // apply markdown
200
200
  auto newString = [usedUtils parseMarkdown:nsAttributedString
201
- withAttributes:defaultNSTextAttributes];
201
+ withDefaultTextAttributes:defaultNSTextAttributes];
202
202
 
203
203
  // create a clone of the old TextInputState and update the
204
204
  // attributed string box to point to the string with markdown
@@ -247,7 +247,7 @@ RootShadowNode::Unshared MarkdownCommitHook::shadowTreeWillCommit(
247
247
 
248
248
  // apply markdown
249
249
  auto newString = [usedUtils parseMarkdown:nsAttributedString
250
- withAttributes:defaultNSTextAttributes];
250
+ withDefaultTextAttributes:defaultNSTextAttributes];
251
251
 
252
252
  // create a clone of the old TextInputState and update the
253
253
  // attributed string box to point to the string with markdown
@@ -9,7 +9,7 @@ const NSAttributedStringKey RCTLiveMarkdownBlockquoteDepthAttributeName = @"RCTL
9
9
  @interface MarkdownFormatter : NSObject
10
10
 
11
11
  - (nonnull NSAttributedString *)format:(nonnull NSString *)text
12
- withAttributes:(nullable NSDictionary<NSAttributedStringKey, id>*)attributes
12
+ withDefaultTextAttributes:(nonnull NSDictionary<NSAttributedStringKey, id> *)defaultTextAttributes
13
13
  withMarkdownRanges:(nonnull NSArray<MarkdownRange *> *)markdownRanges
14
14
  withMarkdownStyle:(nonnull RCTMarkdownStyle *)markdownStyle;
15
15
 
@@ -4,11 +4,11 @@
4
4
  @implementation MarkdownFormatter
5
5
 
6
6
  - (nonnull NSAttributedString *)format:(nonnull NSString *)text
7
- withAttributes:(nullable NSDictionary<NSAttributedStringKey, id> *)attributes
7
+ withDefaultTextAttributes:(nonnull NSDictionary<NSAttributedStringKey, id> *)defaultTextAttributes
8
8
  withMarkdownRanges:(nonnull NSArray<MarkdownRange *> *)markdownRanges
9
9
  withMarkdownStyle:(nonnull RCTMarkdownStyle *)markdownStyle
10
10
  {
11
- NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text attributes:attributes];
11
+ NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text attributes:defaultTextAttributes];
12
12
 
13
13
  [attributedString beginEditing];
14
14
 
@@ -5,7 +5,8 @@ NS_ASSUME_NONNULL_BEGIN
5
5
 
6
6
  @interface MarkdownParser : NSObject
7
7
 
8
- - (NSArray<MarkdownRange *> *)parse:(NSString *)text withParserId:(NSNumber *)parserId;
8
+ - (NSArray<MarkdownRange *> *)parse:(nonnull NSString *)text
9
+ withParserId:(nonnull NSNumber *)parserId;
9
10
 
10
11
  NS_ASSUME_NONNULL_END
11
12
 
@@ -9,7 +9,9 @@
9
9
  NSArray<MarkdownRange *> *_prevMarkdownRanges;
10
10
  }
11
11
 
12
- - (NSArray<MarkdownRange *> *)parse:(NSString *)text withParserId:(nonnull NSNumber *)parserId {
12
+ - (NSArray<MarkdownRange *> *)parse:(nonnull NSString *)text
13
+ withParserId:(nonnull NSNumber *)parserId
14
+ {
13
15
  @synchronized (self) {
14
16
  if ([text isEqualToString:_prevText] && [parserId isEqualToNumber:_prevParserId]) {
15
17
  return _prevMarkdownRanges;
@@ -19,7 +19,7 @@
19
19
  if (markdownUtils != nil) {
20
20
  RCTUITextField *backedTextInputView = [self valueForKey:@"_backedTextInputView"];
21
21
  UITextRange *range = backedTextInputView.selectedTextRange;
22
- backedTextInputView.attributedText = [markdownUtils parseMarkdown:backedTextInputView.attributedText withAttributes:backedTextInputView.defaultTextAttributes];
22
+ backedTextInputView.attributedText = [markdownUtils parseMarkdown:backedTextInputView.attributedText withDefaultTextAttributes:backedTextInputView.defaultTextAttributes];
23
23
  [backedTextInputView setSelectedTextRange:range notifyDelegate:YES];
24
24
  }
25
25
 
@@ -16,7 +16,7 @@
16
16
  {
17
17
  RCTMarkdownUtils *markdownUtils = [self getMarkdownUtils];
18
18
  if (markdownUtils != nil) {
19
- attributedText = [markdownUtils parseMarkdown:attributedText withAttributes:self.backedTextInputView.defaultTextAttributes];
19
+ attributedText = [markdownUtils parseMarkdown:attributedText withDefaultTextAttributes:self.backedTextInputView.defaultTextAttributes];
20
20
  }
21
21
 
22
22
  // Call the original method
@@ -46,7 +46,7 @@
46
46
  if (markdownUtils != nil) {
47
47
  id<RCTBackedTextInputViewProtocol> backedTextInputView = self.backedTextInputView;
48
48
  NSAttributedString *oldAttributedText = backedTextInputView.attributedText;
49
- NSAttributedString *newAttributedText = [markdownUtils parseMarkdown:oldAttributedText withAttributes:backedTextInputView.defaultTextAttributes];
49
+ NSAttributedString *newAttributedText = [markdownUtils parseMarkdown:oldAttributedText withDefaultTextAttributes:backedTextInputView.defaultTextAttributes];
50
50
  UITextRange *range = backedTextInputView.selectedTextRange;
51
51
 
52
52
  // update attributed text without emitting onSelectionChange event
@@ -8,7 +8,8 @@ NS_ASSUME_NONNULL_BEGIN
8
8
  @property (nonatomic) RCTMarkdownStyle *markdownStyle;
9
9
  @property (nonatomic) NSNumber *parserId;
10
10
 
11
- - (NSAttributedString *)parseMarkdown:(nullable NSAttributedString *)input withAttributes:(nullable NSDictionary<NSAttributedStringKey, id>*)attributes;
11
+ - (NSAttributedString *)parseMarkdown:(nullable NSAttributedString *)input
12
+ withDefaultTextAttributes:(nonnull NSDictionary<NSAttributedStringKey, id> *)defaultTextAttributes;
12
13
 
13
14
  @end
14
15
 
@@ -7,7 +7,7 @@
7
7
  MarkdownFormatter *_markdownFormatter;
8
8
  NSString *_prevInputString;
9
9
  NSAttributedString *_prevAttributedString;
10
- NSDictionary<NSAttributedStringKey, id> *_prevTextAttributes;
10
+ NSDictionary<NSAttributedStringKey, id> *_prevDefaultTextAttributes;
11
11
  __weak RCTMarkdownStyle *_prevMarkdownStyle;
12
12
  __weak NSNumber *_prevParserId;
13
13
  }
@@ -22,7 +22,8 @@
22
22
  return self;
23
23
  }
24
24
 
25
- - (NSAttributedString *)parseMarkdown:(nullable NSAttributedString *)input withAttributes:(nullable NSDictionary<NSAttributedStringKey,id> *)attributes
25
+ - (NSAttributedString *)parseMarkdown:(nullable NSAttributedString *)input
26
+ withDefaultTextAttributes:(nonnull NSDictionary<NSAttributedStringKey, id> *)defaultTextAttributes
26
27
  {
27
28
  @synchronized (self) {
28
29
  if (input == nil) {
@@ -30,19 +31,19 @@
30
31
  }
31
32
 
32
33
  NSString *inputString = [input string];
33
- if ([inputString isEqualToString:_prevInputString] && [attributes isEqualToDictionary:_prevTextAttributes] && [_markdownStyle isEqual:_prevMarkdownStyle] && [_parserId isEqualToNumber:_prevParserId]) {
34
+ if ([inputString isEqualToString:_prevInputString] && [defaultTextAttributes isEqualToDictionary:_prevDefaultTextAttributes] && [_markdownStyle isEqual:_prevMarkdownStyle] && [_parserId isEqualToNumber:_prevParserId]) {
34
35
  return _prevAttributedString;
35
36
  }
36
37
 
37
38
  NSArray<MarkdownRange *> *markdownRanges = [_markdownParser parse:inputString withParserId:_parserId];
38
39
 
39
40
  NSAttributedString *attributedString = [_markdownFormatter format:inputString
40
- withAttributes:attributes
41
+ withDefaultTextAttributes:defaultTextAttributes
41
42
  withMarkdownRanges:markdownRanges
42
43
  withMarkdownStyle:_markdownStyle];
43
44
  _prevInputString = inputString;
44
45
  _prevAttributedString = attributedString;
45
- _prevTextAttributes = attributes;
46
+ _prevDefaultTextAttributes = defaultTextAttributes;
46
47
  _prevMarkdownStyle = _markdownStyle;
47
48
  _prevParserId = _parserId;
48
49
 
@@ -18,7 +18,7 @@ using namespace expensify::livemarkdown;
18
18
  if (markdownUtils != nil) {
19
19
  // force Markdown formatting on first render because `_setAttributedText` is called before `setMarkdownUtils`
20
20
  RCTUITextField *backedTextInputView = [self getBackedTextInputView];
21
- backedTextInputView.attributedText = [markdownUtils parseMarkdown:backedTextInputView.attributedText withAttributes:backedTextInputView.defaultTextAttributes];
21
+ backedTextInputView.attributedText = [markdownUtils parseMarkdown:backedTextInputView.attributedText withDefaultTextAttributes:backedTextInputView.defaultTextAttributes];
22
22
  }
23
23
  }
24
24
 
@@ -36,7 +36,7 @@ using namespace expensify::livemarkdown;
36
36
  RCTMarkdownUtils *markdownUtils = [self getMarkdownUtils];
37
37
  RCTUITextField *backedTextInputView = [self getBackedTextInputView];
38
38
  if (markdownUtils != nil && backedTextInputView != nil) {
39
- attributedString = [markdownUtils parseMarkdown:attributedString withAttributes:backedTextInputView.defaultTextAttributes];
39
+ attributedString = [markdownUtils parseMarkdown:attributedString withDefaultTextAttributes:backedTextInputView.defaultTextAttributes];
40
40
  } else {
41
41
  // If markdownUtils is undefined, the text input hasn't been mounted yet. It will
42
42
  // update its state with the unformatted attributed string, we want to prevent displaying
@@ -17,7 +17,7 @@
17
17
  RCTMarkdownUtils *markdownUtils = [self getMarkdownUtils];
18
18
  if (markdownUtils != nil) {
19
19
  UITextRange *range = self.selectedTextRange;
20
- super.attributedText = [markdownUtils parseMarkdown:self.attributedText withAttributes:self.defaultTextAttributes];
20
+ super.attributedText = [markdownUtils parseMarkdown:self.attributedText withDefaultTextAttributes:self.defaultTextAttributes];
21
21
  [super setSelectedTextRange:range]; // prevents cursor from jumping at the end when typing in the middle of the text
22
22
  self.typingAttributes = self.defaultTextAttributes; // removes indent in new line when typing after blockquote
23
23
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expensify/react-native-live-markdown",
3
- "version": "0.1.203",
3
+ "version": "0.1.204",
4
4
  "description": "Drop-in replacement for React Native's TextInput component with Markdown formatting.",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",