@expensify/react-native-live-markdown 0.1.132 → 0.1.134

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.
@@ -45,10 +45,6 @@ function setCursorPosition(target: MarkdownTextInputElement, startIndex: number,
45
45
  selection.setBaseAndExtent(range.startContainer, range.startOffset, range.endContainer, range.endOffset);
46
46
  }
47
47
 
48
- // Update the focused elements zIndex to make sure they are on top and the cursor is beeing set correctly
49
- startTreeNode.element.style.zIndex = '1';
50
- endTreeNode.element.style.zIndex = '1';
51
-
52
48
  scrollIntoView(startTreeNode);
53
49
  }
54
50
 
@@ -1,5 +1,5 @@
1
1
  import type {HTMLMarkdownElement, MarkdownTextInputElement} from '../../MarkdownTextInput.web';
2
- import {addNodeToTree} from './treeUtils';
2
+ import {addNodeToTree, updateTreeElementRefs} from './treeUtils';
3
3
  import type {NodeType, TreeNode} from './treeUtils';
4
4
  import type {PartialMarkdownStyle} from '../../styleUtils';
5
5
  import {getCurrentCursorPosition, moveCursorToEnd, setCursorPosition} from './cursorUtils';
@@ -246,6 +246,7 @@ function moveCursor(isFocused: boolean, alwaysMoveCursorToTheEnd: boolean, curso
246
246
  setCursorPosition(target, cursorPosition);
247
247
  }
248
248
  }
249
+
249
250
  function updateInputStructure(
250
251
  target: MarkdownTextInputElement,
251
252
  text: string,
@@ -276,12 +277,12 @@ function updateInputStructure(
276
277
  if (shouldForceDOMUpdate || targetElement.innerHTML !== dom.innerHTML) {
277
278
  targetElement.innerHTML = '';
278
279
  targetElement.innerText = '';
279
- Array.from(dom.children).forEach((child) => {
280
- targetElement.appendChild(child);
281
- });
280
+ targetElement.innerHTML = dom.innerHTML;
282
281
  }
283
282
 
283
+ updateTreeElementRefs(tree, targetElement);
284
284
  targetElement.tree = tree;
285
+
285
286
  moveCursor(isFocused, alwaysMoveCursorToTheEnd, cursorPosition, targetElement);
286
287
  }
287
288
 
@@ -41,6 +41,23 @@ function addNodeToTree(element: HTMLMarkdownElement, parentTreeNode: TreeNode, t
41
41
  return item;
42
42
  }
43
43
 
44
+ function updateTreeElementRefs(treeRoot: TreeNode, element: HTMLMarkdownElement) {
45
+ const stack: TreeNode[] = [treeRoot];
46
+ while (stack.length > 0) {
47
+ const node = stack.pop() as TreeNode;
48
+ stack.push(...node.childNodes);
49
+
50
+ const currentElement = element.querySelector(`[data-id="${node.orderIndex}"]`) as HTMLMarkdownElement;
51
+ node.element = currentElement;
52
+
53
+ node.childNodes.forEach((child) => {
54
+ stack.push(child);
55
+ });
56
+ }
57
+
58
+ return treeRoot;
59
+ }
60
+
44
61
  function findHTMLElementInTree(treeRoot: TreeNode, element: HTMLElement): TreeNode | null {
45
62
  if (element.hasAttribute?.('contenteditable')) {
46
63
  return treeRoot;
@@ -98,6 +115,6 @@ function getTreeNodeByIndex(treeRoot: TreeNode, index: number): TreeNode | null
98
115
  return null;
99
116
  }
100
117
 
101
- export {addNodeToTree, findHTMLElementInTree, getTreeNodeByIndex};
118
+ export {addNodeToTree, findHTMLElementInTree, getTreeNodeByIndex, updateTreeElementRefs};
102
119
 
103
120
  export type {TreeNode, NodeType};