@expensify/react-native-live-markdown 0.1.13 → 0.1.15

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.
@@ -250,7 +250,7 @@ const MarkdownTextInput = React.forwardRef<TextInput, MarkdownTextInputProps>(
250
250
  const text = normalizeValue(divRef.current.innerText || '');
251
251
  if (typeof e.target !== 'number') {
252
252
  // TODO: change the logic here so every event have value property
253
- (e.target as HTMLInputElement).value = text;
253
+ (e.target as unknown as HTMLInputElement).value = text;
254
254
  }
255
255
  e.nativeEvent.text = text;
256
256
  }
@@ -549,6 +549,7 @@ const styles = StyleSheet.create({
549
549
  borderWidth: 1,
550
550
  borderStyle: 'solid',
551
551
  fontFamily: 'sans-serif',
552
+ // @ts-expect-error it works on web
552
553
  boxSizing: 'border-box',
553
554
  whiteSpace: 'pre-wrap',
554
555
  overflowY: 'scroll',
@@ -78,6 +78,20 @@ function addSubstringAsTextNode(root: HTMLElement, text: string, startIndex: num
78
78
  }
79
79
  }
80
80
 
81
+ function ungroupRanges(ranges: MarkdownRange[]): MarkdownRange[] {
82
+ const ungroupedRanges: MarkdownRange[] = [];
83
+ ranges.forEach((range) => {
84
+ if (!range.depth) {
85
+ ungroupedRanges.push(range);
86
+ }
87
+ const {depth, ...rangeWithoutDepth} = range;
88
+ Array.from({length: depth!}).forEach(() => {
89
+ ungroupedRanges.push(rangeWithoutDepth);
90
+ });
91
+ });
92
+ return ungroupedRanges;
93
+ }
94
+
81
95
  function parseRangesToHTMLNodes(text: string, ranges: MarkdownRange[], markdownStyle: PartialMarkdownStyle = {}, disableInlineStyles = false): HTMLElement {
82
96
  const root: HTMLElement = document.createElement('span');
83
97
  root.className = 'root';
@@ -87,7 +101,7 @@ function parseRangesToHTMLNodes(text: string, ranges: MarkdownRange[], markdownS
87
101
  return root;
88
102
  }
89
103
 
90
- const stack = [...ranges];
104
+ const stack = ungroupRanges(ranges);
91
105
  const nestedStack: NestedNode[] = [{node: root, endIndex: textLength}];
92
106
  let lastRangeEndIndex = 0;
93
107
  while (stack.length > 0) {