@expensify/react-native-live-markdown 0.1.116 → 0.1.118

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 (90) hide show
  1. package/lib/commonjs/MarkdownTextInput.js +2 -4
  2. package/lib/commonjs/MarkdownTextInput.js.map +1 -1
  3. package/lib/commonjs/MarkdownTextInput.web.js +105 -149
  4. package/lib/commonjs/MarkdownTextInput.web.js.map +1 -1
  5. package/lib/commonjs/styleUtils.js.map +1 -1
  6. package/lib/commonjs/web/utils/blockUtils.js +77 -0
  7. package/lib/commonjs/web/utils/blockUtils.js.map +1 -0
  8. package/lib/commonjs/web/utils/browserUtils.js +18 -0
  9. package/lib/commonjs/web/utils/browserUtils.js.map +1 -0
  10. package/lib/commonjs/web/utils/cursorUtils.js +111 -0
  11. package/lib/commonjs/web/utils/cursorUtils.js.map +1 -0
  12. package/lib/commonjs/web/utils/inputUtils.js +108 -0
  13. package/lib/commonjs/web/utils/inputUtils.js.map +1 -0
  14. package/lib/commonjs/web/utils/parserUtils.js +266 -0
  15. package/lib/commonjs/web/utils/parserUtils.js.map +1 -0
  16. package/lib/commonjs/web/utils/treeUtils.js +85 -0
  17. package/lib/commonjs/web/utils/treeUtils.js.map +1 -0
  18. package/lib/commonjs/web/utils/webStyleUtils.js +51 -0
  19. package/lib/commonjs/web/utils/webStyleUtils.js.map +1 -0
  20. package/lib/module/MarkdownTextInput.js +2 -2
  21. package/lib/module/MarkdownTextInput.js.map +1 -1
  22. package/lib/module/MarkdownTextInput.web.js +101 -145
  23. package/lib/module/MarkdownTextInput.web.js.map +1 -1
  24. package/lib/module/styleUtils.js.map +1 -1
  25. package/lib/module/web/utils/blockUtils.js +72 -0
  26. package/lib/module/web/utils/blockUtils.js.map +1 -0
  27. package/lib/module/web/utils/browserUtils.js +12 -0
  28. package/lib/module/web/utils/browserUtils.js.map +1 -0
  29. package/lib/module/web/utils/cursorUtils.js +102 -0
  30. package/lib/module/web/utils/cursorUtils.js.map +1 -0
  31. package/lib/module/web/utils/inputUtils.js +99 -0
  32. package/lib/module/web/utils/inputUtils.js.map +1 -0
  33. package/lib/module/web/utils/parserUtils.js +260 -0
  34. package/lib/module/web/utils/parserUtils.js.map +1 -0
  35. package/lib/module/web/utils/treeUtils.js +78 -0
  36. package/lib/module/web/utils/treeUtils.js.map +1 -0
  37. package/lib/module/web/utils/webStyleUtils.js +45 -0
  38. package/lib/module/web/utils/webStyleUtils.js.map +1 -0
  39. package/lib/typescript/src/MarkdownTextInput.d.ts +1 -2
  40. package/lib/typescript/src/MarkdownTextInput.d.ts.map +1 -1
  41. package/lib/typescript/src/MarkdownTextInput.web.d.ts +9 -3
  42. package/lib/typescript/src/MarkdownTextInput.web.d.ts.map +1 -1
  43. package/lib/typescript/src/styleUtils.d.ts +1 -2
  44. package/lib/typescript/src/styleUtils.d.ts.map +1 -1
  45. package/lib/typescript/src/web/utils/blockUtils.d.ts +5 -0
  46. package/lib/typescript/src/web/utils/blockUtils.d.ts.map +1 -0
  47. package/lib/typescript/src/web/utils/browserUtils.d.ts +12 -0
  48. package/lib/typescript/src/web/utils/browserUtils.d.ts.map +1 -0
  49. package/lib/typescript/src/web/utils/cursorUtils.d.ts +12 -0
  50. package/lib/typescript/src/web/utils/cursorUtils.d.ts.map +1 -0
  51. package/lib/typescript/src/web/utils/inputUtils.d.ts +9 -0
  52. package/lib/typescript/src/web/utils/inputUtils.d.ts.map +1 -0
  53. package/lib/typescript/src/web/utils/parserUtils.d.ts +22 -0
  54. package/lib/typescript/src/web/utils/parserUtils.d.ts.map +1 -0
  55. package/lib/typescript/src/web/utils/treeUtils.d.ts +17 -0
  56. package/lib/typescript/src/web/utils/treeUtils.d.ts.map +1 -0
  57. package/lib/typescript/src/web/utils/webStyleUtils.d.ts +6 -0
  58. package/lib/typescript/src/web/utils/webStyleUtils.d.ts.map +1 -0
  59. package/package.json +5 -2
  60. package/src/MarkdownTextInput.tsx +4 -7
  61. package/src/MarkdownTextInput.web.tsx +142 -171
  62. package/src/styleUtils.ts +1 -3
  63. package/src/web/utils/blockUtils.ts +72 -0
  64. package/src/web/utils/browserUtils.ts +13 -0
  65. package/src/web/utils/cursorUtils.ts +116 -0
  66. package/src/web/utils/inputUtils.ts +106 -0
  67. package/src/web/utils/parserUtils.ts +302 -0
  68. package/src/web/utils/treeUtils.ts +103 -0
  69. package/src/web/utils/webStyleUtils.ts +54 -0
  70. package/lib/commonjs/web/browserUtils.js +0 -16
  71. package/lib/commonjs/web/browserUtils.js.map +0 -1
  72. package/lib/commonjs/web/cursorUtils.js +0 -167
  73. package/lib/commonjs/web/cursorUtils.js.map +0 -1
  74. package/lib/commonjs/web/parserUtils.js +0 -214
  75. package/lib/commonjs/web/parserUtils.js.map +0 -1
  76. package/lib/module/web/browserUtils.js +0 -11
  77. package/lib/module/web/browserUtils.js.map +0 -1
  78. package/lib/module/web/cursorUtils.js +0 -154
  79. package/lib/module/web/cursorUtils.js.map +0 -1
  80. package/lib/module/web/parserUtils.js +0 -206
  81. package/lib/module/web/parserUtils.js.map +0 -1
  82. package/lib/typescript/src/web/browserUtils.d.ts +0 -10
  83. package/lib/typescript/src/web/browserUtils.d.ts.map +0 -1
  84. package/lib/typescript/src/web/cursorUtils.d.ts +0 -12
  85. package/lib/typescript/src/web/cursorUtils.d.ts.map +0 -1
  86. package/lib/typescript/src/web/parserUtils.d.ts +0 -17
  87. package/lib/typescript/src/web/parserUtils.d.ts.map +0 -1
  88. package/src/web/browserUtils.ts +0 -11
  89. package/src/web/cursorUtils.ts +0 -177
  90. package/src/web/parserUtils.ts +0 -228
@@ -0,0 +1 @@
1
+ {"version":3,"names":["addStyleToBlock","targetElement","type","markdownStyle","node","Object","assign","style","display","margin","padding","syntax","fontWeight","fontStyle","textDecoration","emoji","verticalAlign","mentionHere","mentionUser","mentionReport","link","code","pre","blockquote","borderLeftStyle","maxWidth","boxSizing","h1"],"sourceRoot":"../../../../src","sources":["web/utils/blockUtils.ts"],"mappings":"AAGA,SAASA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T,MAAM,CAACC,MAAM,CAACF,IAAI,CAACG,KAAK,EAAEJ,aAAa,CAACkB,IAAI,CAAC;MAC7C;IACF,KAAK,KAAK;MACRhB,MAAM,CAACC,MAAM,CAACF,IAAI,CAACG,KAAK,EAAEJ,aAAa,CAACmB,GAAG,CAAC;MAC5C;IAEF,KAAK,YAAY;MACfjB,MAAM,CAACC,MAAM,CAACF,IAAI,CAACG,KAAK,EAAE;QACxB,GAAGJ,aAAa,CAACoB,UAAU;QAC3BC,eAAe,EAAE,OAAO;QACxBhB,OAAO,EAAE,cAAc;QACvBiB,QAAQ,EAAE,MAAM;QAChBC,SAAS,EAAE;MACb,CAAC,CAAC;MACF;IACF,KAAK,IAAI;MACPrB,MAAM,CAACC,MAAM,CAACF,IAAI,CAACG,KAAK,EAAE;QACxB,GAAGJ,aAAa,CAACwB,EAAE;QACnBf,UAAU,EAAE;MACd,CAAC,CAAC;MACF;IACF;MACE;EACJ;AACF;;AAEA;AACA,SAAQZ,eAAe"}
@@ -0,0 +1,12 @@
1
+ const BrowserUtils = {
2
+ isFirefox: navigator.userAgent.toLowerCase().includes('firefox'),
3
+ isChromium: 'chrome' in window,
4
+ /**
5
+ * Whether the platform is a mobile browser.
6
+ * Copied from Expensify App https://github.com/Expensify/App/blob/90dee7accae79c49debf30354c160cab6c52c423/src/libs/Browser/index.website.ts#L41
7
+ *
8
+ */
9
+ isMobile: /Android|webOS|iPhone|iPad|iPod|BlackBerry|BB|PlayBook|IEMobile|Windows Phone|Silk|Opera Mini/i.test(navigator.userAgent)
10
+ };
11
+ export default BrowserUtils;
12
+ //# sourceMappingURL=browserUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["BrowserUtils","isFirefox","navigator","userAgent","toLowerCase","includes","isChromium","window","isMobile","test"],"sourceRoot":"../../../../src","sources":["web/utils/browserUtils.ts"],"mappings":"AAAA,MAAMA,YAAY,GAAG;EACnBC,SAAS,EAAEC,SAAS,CAACC,SAAS,CAACC,WAAW,CAAC,CAAC,CAACC,QAAQ,CAAC,SAAS,CAAC;EAChEC,UAAU,EAAE,QAAQ,IAAIC,MAAM;EAE9B;AACF;AACA;AACA;AACA;EACEC,QAAQ,EAAE,+FAA+F,CAACC,IAAI,CAACP,SAAS,CAACC,SAAS;AACpI,CAAC;AAED,eAAeH,YAAY"}
@@ -0,0 +1,102 @@
1
+ import { findHTMLElementInTree, getTreeNodeByIndex } from './treeUtils';
2
+ function setCursorPosition(target, startIndex, endIndex = null) {
3
+ // We don't want to move the cursor if the target is not focused
4
+ if (!target.tree || target !== document.activeElement) {
5
+ return;
6
+ }
7
+ const start = Math.max(0, Math.min(startIndex, target.tree.length));
8
+ const end = endIndex ? Math.max(0, Math.min(endIndex, target.tree.length)) : null;
9
+ if (end && end < start) {
10
+ return;
11
+ }
12
+ const range = document.createRange();
13
+ range.selectNodeContents(target);
14
+ const startTreeNode = getTreeNodeByIndex(target.tree, start);
15
+ const endTreeNode = end && startTreeNode && (end < startTreeNode.start || end >= startTreeNode.start + startTreeNode.length) ? getTreeNodeByIndex(target.tree, end) : startTreeNode;
16
+ if (!startTreeNode || !endTreeNode) {
17
+ console.error('Invalid start or end tree node');
18
+ return;
19
+ }
20
+ if (startTreeNode.type === 'br') {
21
+ range.setStartBefore(startTreeNode.element);
22
+ } else {
23
+ range.setStart(startTreeNode.element.childNodes[0], start - startTreeNode.start);
24
+ }
25
+ if (endTreeNode.type === 'br') {
26
+ range.setEndBefore(endTreeNode.element);
27
+ } else {
28
+ range.setEnd(endTreeNode.element.childNodes[0], (end || start) - endTreeNode.start);
29
+ }
30
+ if (!end) {
31
+ range.collapse(true);
32
+ }
33
+ const selection = window.getSelection();
34
+ if (selection) {
35
+ selection.setBaseAndExtent(range.startContainer, range.startOffset, range.endContainer, range.endOffset);
36
+ }
37
+ scrollIntoView(startTreeNode);
38
+ }
39
+ function scrollIntoView(node) {
40
+ var _node$parentNode;
41
+ if (node.type === 'br' && ((_node$parentNode = node.parentNode) === null || _node$parentNode === void 0 || (_node$parentNode = _node$parentNode.parentNode) === null || _node$parentNode === void 0 ? void 0 : _node$parentNode.type) === 'line') {
42
+ // If the node is a line break, scroll to the parent paragraph, because Safari doesn't support scrollIntoView on br elements
43
+ node.parentNode.parentNode.element.scrollIntoView({
44
+ block: 'nearest'
45
+ });
46
+ } else {
47
+ node.element.scrollIntoView({
48
+ block: 'nearest'
49
+ });
50
+ }
51
+ }
52
+ function moveCursorToEnd(target) {
53
+ const range = document.createRange();
54
+ const selection = window.getSelection();
55
+ if (selection) {
56
+ range.setStart(target, target.childNodes.length);
57
+ range.collapse(true);
58
+ selection.setBaseAndExtent(range.startContainer, range.startOffset, range.endContainer, range.endOffset);
59
+ }
60
+ }
61
+ function getCurrentCursorPosition(target) {
62
+ function getHTMLElement(node) {
63
+ let element = node;
64
+ if (element instanceof Text) {
65
+ element = node.parentElement;
66
+ }
67
+ return element;
68
+ }
69
+ const selection = window.getSelection();
70
+ if (!selection || selection && selection.rangeCount === 0) {
71
+ return null;
72
+ }
73
+ const range = selection.getRangeAt(0);
74
+ const startElement = getHTMLElement(range.startContainer);
75
+ const endElement = range.startContainer === range.endContainer ? startElement : getHTMLElement(range.endContainer);
76
+ const startTreeNode = findHTMLElementInTree(target.tree, startElement);
77
+ const endTreeNode = findHTMLElementInTree(target.tree, endElement);
78
+ let start = -1;
79
+ let end = -1;
80
+ if (startTreeNode && endTreeNode) {
81
+ start = startTreeNode.start + range.startOffset;
82
+
83
+ // If the end node is a root node, we need to set the end to the end of the text (FireFox fix)
84
+ if ((endTreeNode === null || endTreeNode === void 0 ? void 0 : endTreeNode.parentNode) === null) {
85
+ end = target.value.length;
86
+ } else {
87
+ end = endTreeNode.start + range.endOffset;
88
+ }
89
+ }
90
+ return {
91
+ start,
92
+ end
93
+ };
94
+ }
95
+ function removeSelection() {
96
+ const selection = window.getSelection();
97
+ if (selection) {
98
+ selection.removeAllRanges();
99
+ }
100
+ }
101
+ export { getCurrentCursorPosition, moveCursorToEnd, setCursorPosition, removeSelection, scrollIntoView };
102
+ //# sourceMappingURL=cursorUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["findHTMLElementInTree","getTreeNodeByIndex","setCursorPosition","target","startIndex","endIndex","tree","document","activeElement","start","Math","max","min","length","end","range","createRange","selectNodeContents","startTreeNode","endTreeNode","console","error","type","setStartBefore","element","setStart","childNodes","setEndBefore","setEnd","collapse","selection","window","getSelection","setBaseAndExtent","startContainer","startOffset","endContainer","endOffset","scrollIntoView","node","_node$parentNode","parentNode","block","moveCursorToEnd","getCurrentCursorPosition","getHTMLElement","Text","parentElement","rangeCount","getRangeAt","startElement","endElement","value","removeSelection","removeAllRanges"],"sourceRoot":"../../../../src","sources":["web/utils/cursorUtils.ts"],"mappings":"AACA,SAAQA,qBAAqB,EAAEC,kBAAkB,QAAO,aAAa;AAGrE,SAASC,iBAAiBA,CAACC,MAAgC,EAAEC,UAAkB,EAAEC,QAAuB,GAAG,IAAI,EAAE;EAC/G;EACA,IAAI,CAACF,MAAM,CAACG,IAAI,IAAIH,MAAM,KAAKI,QAAQ,CAACC,aAAa,EAAE;IACrD;EACF;EAEA,MAAMC,KAAK,GAAGC,IAAI,CAACC,GAAG,CAAC,CAAC,EAAED,IAAI,CAACE,GAAG,CAACR,UAAU,EAAED,MAAM,CAACG,IAAI,CAACO,MAAM,CAAC,CAAC;EACnE,MAAMC,GAAG,GAAGT,QAAQ,GAAGK,IAAI,CAACC,GAAG,CAAC,CAAC,EAAED,IAAI,CAACE,GAAG,CAACP,QAAQ,EAAEF,MAAM,CAACG,IAAI,CAACO,MAAM,CAAC,CAAC,GAAG,IAAI;EACjF,IAAIC,GAAG,IAAIA,GAAG,GAAGL,KAAK,EAAE;IACtB;EACF;EAEA,MAAMM,KAAK,GAAGR,QAAQ,CAACS,WAAW,CAAC,CAAC;EACpCD,KAAK,CAACE,kBAAkB,CAACd,MAAM,CAAC;EAEhC,MAAMe,aAAa,GAAGjB,kBAAkB,CAACE,MAAM,CAACG,IAAI,EAAE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D,eAAe,EAAEf,cAAc"}
@@ -0,0 +1,99 @@
1
+ const ZERO_WIDTH_SPACE = '\u200B';
2
+
3
+ // If an Input Method Editor is processing key input, the 'keyCode' is 229.
4
+ // https://www.w3.org/TR/uievents/#determine-keydown-keyup-keyCode
5
+ function isEventComposing(nativeEvent) {
6
+ return nativeEvent.isComposing || nativeEvent.keyCode === 229;
7
+ }
8
+ function getPlaceholderValue(placeholder) {
9
+ if (!placeholder) {
10
+ return ZERO_WIDTH_SPACE;
11
+ }
12
+ return placeholder.length ? placeholder : ZERO_WIDTH_SPACE;
13
+ }
14
+ function getElementHeight(node, styles, numberOfLines) {
15
+ if (numberOfLines) {
16
+ const tempElement = document.createElement('div');
17
+ tempElement.setAttribute('contenteditable', 'true');
18
+ Object.assign(tempElement.style, styles);
19
+ tempElement.textContent = Array(numberOfLines).fill('A').join('\n');
20
+ if (node.parentElement) {
21
+ node.parentElement.appendChild(tempElement);
22
+ const height = tempElement.clientHeight;
23
+ node.parentElement.removeChild(tempElement);
24
+ return height ? `${height}px` : 'auto';
25
+ }
26
+ }
27
+ return styles.height ? `${styles.height}px` : 'auto';
28
+ }
29
+ function normalizeValue(value) {
30
+ return value.replaceAll('\r\n', '\n');
31
+ }
32
+
33
+ // Parses the HTML structure of a MarkdownTextInputElement to a plain text string. Used for getting the correct value of the input element.
34
+ function parseInnerHTMLToText(target) {
35
+ // Returns the parent of a given node that is higher in the hierarchy and is of a different type than 'text', 'br' or 'line'
36
+ function getTopParentNode(node) {
37
+ let currentParentNode = node.parentNode;
38
+ while (currentParentNode && ['text', 'br', 'line'].includes(((_currentParentNode$pa = currentParentNode.parentElement) === null || _currentParentNode$pa === void 0 ? void 0 : _currentParentNode$pa.getAttribute('data-type')) || '')) {
39
+ var _currentParentNode$pa, _currentParentNode;
40
+ currentParentNode = ((_currentParentNode = currentParentNode) === null || _currentParentNode === void 0 ? void 0 : _currentParentNode.parentNode) || null;
41
+ }
42
+ return currentParentNode;
43
+ }
44
+ const stack = [target];
45
+ let text = '';
46
+ let shouldAddNewline = false;
47
+ const lastNode = target.childNodes[target.childNodes.length - 1];
48
+ // Remove the last <br> element if it's the last child of the target element. Fixes the issue with adding extra newline when pasting into the empty input.
49
+ if ((lastNode === null || lastNode === void 0 ? void 0 : lastNode.nodeName) === 'DIV' && (lastNode === null || lastNode === void 0 ? void 0 : lastNode.innerHTML) === '<br>') {
50
+ target.removeChild(lastNode);
51
+ }
52
+ while (stack.length > 0) {
53
+ var _node$parentElement;
54
+ const node = stack.pop();
55
+ if (!node) {
56
+ break;
57
+ }
58
+
59
+ // If we are operating on the nodes that are children of the MarkdownTextInputElement, we need to add a newline after each
60
+ const isTopComponent = ((_node$parentElement = node.parentElement) === null || _node$parentElement === void 0 ? void 0 : _node$parentElement.contentEditable) === 'true';
61
+ if (isTopComponent) {
62
+ // Replaced text is beeing added as text node, so we need to not add the newline before and after it
63
+ if (node.nodeType === Node.TEXT_NODE) {
64
+ shouldAddNewline = false;
65
+ } else {
66
+ if (shouldAddNewline) {
67
+ text += '\n';
68
+ shouldAddNewline = false;
69
+ }
70
+ shouldAddNewline = true;
71
+ }
72
+ }
73
+ if (node.nodeType === Node.TEXT_NODE) {
74
+ // Parse text nodes into text
75
+ text += node.textContent;
76
+ } else if (node.nodeName === 'BR') {
77
+ var _parentNode$parentEle;
78
+ const parentNode = getTopParentNode(node);
79
+ if (parentNode && ((_parentNode$parentEle = parentNode.parentElement) === null || _parentNode$parentEle === void 0 ? void 0 : _parentNode$parentEle.contentEditable) !== 'true') {
80
+ // Parse br elements into newlines only if their parent is not a child of the MarkdownTextInputElement (a paragraph when writing or a div when pasting).
81
+ // It prevents adding extra newlines when entering text
82
+ text += '\n';
83
+ }
84
+ } else {
85
+ let i = node.childNodes.length - 1;
86
+ while (i > -1) {
87
+ const child = node.childNodes[i];
88
+ if (!child) {
89
+ break;
90
+ }
91
+ stack.push(child);
92
+ i--;
93
+ }
94
+ }
95
+ }
96
+ return text.replaceAll('\r\n', '\n');
97
+ }
98
+ export { isEventComposing, getPlaceholderValue, getElementHeight, parseInnerHTMLToText, normalizeValue };
99
+ //# sourceMappingURL=inputUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ZERO_WIDTH_SPACE","isEventComposing","nativeEvent","isComposing","keyCode","getPlaceholderValue","placeholder","length","getElementHeight","node","styles","numberOfLines","tempElement","document","createElement","setAttribute","Object","assign","style","textContent","Array","fill","join","parentElement","appendChild","height","clientHeight","removeChild","normalizeValue","value","replaceAll","parseInnerHTMLToText","target","getTopParentNode","currentParentNode","parentNode","includes","_currentParentNode$pa","getAttribute","_currentParentNode","stack","text","shouldAddNewline","lastNode","childNodes","nodeName","innerHTML","_node$parentElement","pop","isTopComponent","contentEditable","nodeType","Node","TEXT_NODE","_parentNode$parentEle","i","child","push"],"sourceRoot":"../../../../src","sources":["web/utils/inputUtils.ts"],"mappings":"AAGA,MAAMA,gBAAgB,GAAG,QAAQ;;AAEjC;AACA;AACA,SAASC,gBAAgBA,CAACC,WAAqC,EAAE;EAC/D,OAAOA,WAAW,CAACC,WAAW,IAAID,WAAW,CAACE,OAAO,KAAK,GAAG;AAC/D;AAEA,SAASC,mBAAmBA,CAACC,WAA+B,EAAE;EAC5D,IAAI,CAACA,WAAW,EAAE;IAChB,OAAON,gBAAgB;EACzB;EACA,OAAOM,WAAW,CAACC,MAAM,GAAGD,WAAW,GAAGN,gBAAgB;AAC5D;AAEA,SAASQ,gBAAgBA,CAACC,IAAoB,EAAEC,MAAqB,EAAEC,aAAiC,EAAE;EACxG,IAAIA,aAAa,EAAE;IACjB,MAAMC,WAAW,GAAGC,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC;IACjDF,WAAW,CAACG,YAAY,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnDC,MAAM,CAACC,MAAM,CAACL,WAAW,CAACM,KAAK,EAAER,MAAM,CAAC;IACxCE,WAAW,CAACO,WAAW,GAAGC,KAAK,CAACT,aAAa,CAAC,CAACU,IAAI,CAAC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IAAI;MACd;IACF,CAAC,MAAM;MACL,IAAIc,CAAC,GAAG9C,IAAI,CAACmC,UAAU,CAACrC,MAAM,GAAG,CAAC;MAClC,OAAOgD,CAAC,GAAG,CAAC,CAAC,EAAE;QACb,MAAMC,KAAK,GAAG/C,IAAI,CAACmC,UAAU,CAACW,CAAC,CAAC;QAChC,IAAI,CAACC,KAAK,EAAE;UACV;QACF;QACAhB,KAAK,CAACiB,IAAI,CAACD,KAAK,CAAC;QACjBD,CAAC,EAAE;MACL;IACF;EACF;EAEA,OAAOd,IAAI,CAACX,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC;AACtC;AAEA,SAAQ7B,gBAAgB,EAAEI,mBAAmB,EAAEG,gBAAgB,EAAEuB,oBAAoB,EAAEH,cAAc"}
@@ -0,0 +1,260 @@
1
+ import { addNodeToTree } from './treeUtils';
2
+ import { getCurrentCursorPosition, moveCursorToEnd, setCursorPosition } from './cursorUtils';
3
+ import { addStyleToBlock } from './blockUtils';
4
+ function ungroupRanges(ranges) {
5
+ const ungroupedRanges = [];
6
+ ranges.forEach(range => {
7
+ if (!range.depth) {
8
+ ungroupedRanges.push(range);
9
+ }
10
+ const {
11
+ depth,
12
+ ...rangeWithoutDepth
13
+ } = range;
14
+ Array.from({
15
+ length: depth
16
+ }).forEach(() => {
17
+ ungroupedRanges.push(rangeWithoutDepth);
18
+ });
19
+ });
20
+ return ungroupedRanges;
21
+ }
22
+ function splitTextIntoLines(text) {
23
+ let lineStartIndex = 0;
24
+ const lines = text.split('\n').map(line => {
25
+ const lineObject = {
26
+ text: line,
27
+ start: lineStartIndex,
28
+ length: line.length,
29
+ markdownRanges: []
30
+ };
31
+ lineStartIndex += line.length + 1; // Adding 1 for the newline character
32
+ return lineObject;
33
+ });
34
+ return lines;
35
+ }
36
+
37
+ /** Merges lines that contain multiline markdown tags into one line */
38
+ function mergeLinesWithMultilineTags(lines, ranges) {
39
+ let mergedLines = [...lines];
40
+ const lineIndexes = mergedLines.map((_line, index) => index);
41
+ ranges.forEach(range => {
42
+ const beginLineIndex = mergedLines.findLastIndex(line => line.start <= range.start);
43
+ const endLineIndex = mergedLines.findIndex(line => line.start + line.length >= range.start + range.length);
44
+ const correspondingLineIndexes = lineIndexes.slice(beginLineIndex, endLineIndex + 1);
45
+ if (correspondingLineIndexes.length > 0) {
46
+ const mainLineIndex = correspondingLineIndexes[0];
47
+ const mainLine = mergedLines[mainLineIndex];
48
+ mainLine.markdownRanges.push(range);
49
+ const otherLineIndexes = correspondingLineIndexes.slice(1);
50
+ otherLineIndexes.forEach(lineIndex => {
51
+ const otherLine = mergedLines[lineIndex];
52
+ mainLine.text += `\n${otherLine.text}`;
53
+ mainLine.length += otherLine.length + 1;
54
+ mainLine.markdownRanges.push(...otherLine.markdownRanges);
55
+ });
56
+ if (otherLineIndexes.length > 0) {
57
+ mergedLines = mergedLines.filter((_line, index) => !otherLineIndexes.includes(index));
58
+ }
59
+ }
60
+ });
61
+ return mergedLines;
62
+ }
63
+
64
+ /** Adds a value prop to the element and appends the value to the parent node element */
65
+ function appendValueToElement(element, parentTreeNode, value) {
66
+ const targetElement = element;
67
+ const parentNode = parentTreeNode;
68
+ targetElement.value = value;
69
+ parentNode.element.value = (parentNode.element.value || '') + value;
70
+ }
71
+ function appendNode(element, parentTreeNode, type, length) {
72
+ const node = addNodeToTree(element, parentTreeNode, type, length);
73
+ parentTreeNode.element.appendChild(element);
74
+ return node;
75
+ }
76
+ function addBrElement(node) {
77
+ const span = document.createElement('span');
78
+ span.setAttribute('data-type', 'br');
79
+ appendValueToElement(span, node, '\n');
80
+ const spanNode = appendNode(span, node, 'br', 1);
81
+ appendNode(document.createElement('br'), spanNode, 'br', 1);
82
+ return spanNode;
83
+ }
84
+ function addTextToElement(node, text) {
85
+ const lines = text.split('\n');
86
+ lines.forEach((line, index) => {
87
+ if (line !== '') {
88
+ const span = document.createElement('span');
89
+ appendValueToElement(span, node, line);
90
+ span.setAttribute('data-type', 'text');
91
+ span.appendChild(document.createTextNode(line));
92
+ appendNode(span, node, 'text', line.length);
93
+ }
94
+ if (index < lines.length - 1 || index === 0 && line === '') {
95
+ addBrElement(node);
96
+ }
97
+ });
98
+ }
99
+ function addParagraph(node, text = null, length, disableInlineStyles = false) {
100
+ const p = document.createElement('p');
101
+ p.setAttribute('data-type', 'line');
102
+ if (!disableInlineStyles) {
103
+ addStyleToBlock(p, 'line', {});
104
+ }
105
+ const pNode = appendNode(p, node, 'line', length);
106
+ if (text === '') {
107
+ // If the line is empty, we still need to add a br element to keep the line height
108
+ addBrElement(pNode);
109
+ } else if (text) {
110
+ addTextToElement(pNode, text);
111
+ }
112
+ return pNode;
113
+ }
114
+
115
+ /** Builds HTML DOM structure based on passed text and markdown ranges */
116
+ function parseRangesToHTMLNodes(text, ranges, markdownStyle = {}, disableInlineStyles = false) {
117
+ const rootElement = document.createElement('span');
118
+ const textLength = text.replace(/\n/g, '\\n').length;
119
+ const rootNode = {
120
+ element: rootElement,
121
+ start: 0,
122
+ length: textLength,
123
+ parentNode: null,
124
+ childNodes: [],
125
+ type: 'root',
126
+ orderIndex: '',
127
+ isGeneratingNewline: false
128
+ };
129
+ let currentParentNode = rootNode;
130
+ let lines = splitTextIntoLines(text);
131
+ if (ranges.length === 0) {
132
+ lines.forEach(line => {
133
+ addParagraph(rootNode, line.text, line.length, disableInlineStyles);
134
+ });
135
+ return {
136
+ dom: rootElement,
137
+ tree: rootNode
138
+ };
139
+ }
140
+ const markdownRanges = ungroupRanges(ranges);
141
+ lines = mergeLinesWithMultilineTags(lines, markdownRanges);
142
+ let lastRangeEndIndex = 0;
143
+ while (lines.length > 0) {
144
+ const line = lines.shift();
145
+ if (!line) {
146
+ break;
147
+ }
148
+
149
+ // preparing line paragraph element for markdown text
150
+ currentParentNode = addParagraph(rootNode, null, line.length, disableInlineStyles);
151
+ rootElement.value = (rootElement.value || '') + line.text;
152
+ if (lines.length > 0) {
153
+ rootElement.value = `${rootElement.value || ''}\n`;
154
+ }
155
+ if (line.markdownRanges.length === 0) {
156
+ addTextToElement(currentParentNode, line.text);
157
+ }
158
+ lastRangeEndIndex = line.start;
159
+ const lineMarkdownRanges = line.markdownRanges;
160
+ // go through all markdown ranges in the line
161
+ while (lineMarkdownRanges.length > 0) {
162
+ const range = lineMarkdownRanges.shift();
163
+ if (!range) {
164
+ break;
165
+ }
166
+ const endOfCurrentRange = range.start + range.length;
167
+ const nextRangeStartIndex = lineMarkdownRanges.length > 0 && !!lineMarkdownRanges[0] ? lineMarkdownRanges[0].start || 0 : textLength;
168
+
169
+ // add text before the markdown range
170
+ const textBeforeRange = line.text.substring(lastRangeEndIndex - line.start, range.start - line.start);
171
+ if (textBeforeRange) {
172
+ addTextToElement(currentParentNode, textBeforeRange);
173
+ }
174
+
175
+ // create markdown span element
176
+ const span = document.createElement('span');
177
+ span.setAttribute('data-type', range.type);
178
+ if (!disableInlineStyles) {
179
+ addStyleToBlock(span, range.type, markdownStyle);
180
+ }
181
+ const spanNode = appendNode(span, currentParentNode, range.type, range.length);
182
+ if (lineMarkdownRanges.length > 0 && nextRangeStartIndex < endOfCurrentRange && range.type !== 'syntax') {
183
+ // tag nesting
184
+ currentParentNode = spanNode;
185
+ lastRangeEndIndex = range.start;
186
+ } else {
187
+ // adding markdown tag
188
+ addTextToElement(spanNode, text.substring(range.start, endOfCurrentRange));
189
+ currentParentNode.element.value = (currentParentNode.element.value || '') + (spanNode.element.value || '');
190
+ lastRangeEndIndex = endOfCurrentRange;
191
+ // tag unnesting and adding text after the tag
192
+ while (currentParentNode.parentNode !== null && nextRangeStartIndex >= currentParentNode.start + currentParentNode.length) {
193
+ const textAfterRange = line.text.substring(lastRangeEndIndex - line.start, currentParentNode.start - line.start + currentParentNode.length);
194
+ if (textAfterRange) {
195
+ addTextToElement(currentParentNode, textAfterRange);
196
+ }
197
+ lastRangeEndIndex = currentParentNode.start + currentParentNode.length;
198
+ if (currentParentNode.parentNode.type !== 'root') {
199
+ currentParentNode.parentNode.element.value = currentParentNode.element.value || '';
200
+ }
201
+ currentParentNode = currentParentNode.parentNode || rootNode;
202
+ }
203
+ }
204
+ }
205
+ }
206
+ return {
207
+ dom: rootElement,
208
+ tree: rootNode
209
+ };
210
+ }
211
+ function moveCursor(isFocused, alwaysMoveCursorToTheEnd, cursorPosition, target) {
212
+ if (!isFocused) {
213
+ return;
214
+ }
215
+ if (alwaysMoveCursorToTheEnd || cursorPosition === null) {
216
+ moveCursorToEnd(target);
217
+ } else if (cursorPosition !== null) {
218
+ setCursorPosition(target, cursorPosition);
219
+ }
220
+ }
221
+ function updateInputStructure(target, text, cursorPositionIndex, markdownStyle = {}, alwaysMoveCursorToTheEnd = false, shouldForceDOMUpdate = false) {
222
+ const targetElement = target;
223
+
224
+ // in case the cursorPositionIndex is larger than text length, cursorPosition will be null, i.e: move the caret to the end
225
+ let cursorPosition = cursorPositionIndex !== null && cursorPositionIndex <= text.length ? cursorPositionIndex : null;
226
+ const isFocused = document.activeElement === target;
227
+ if (isFocused && cursorPositionIndex === null) {
228
+ const selection = getCurrentCursorPosition(target);
229
+ cursorPosition = selection ? selection.start : null;
230
+ }
231
+ const ranges = global.parseExpensiMarkToRanges(text);
232
+ const markdownRanges = ranges;
233
+ if (!text || targetElement.innerHTML === '<br>' || targetElement && targetElement.innerHTML === '\n') {
234
+ targetElement.innerHTML = '';
235
+ targetElement.innerText = '';
236
+ }
237
+
238
+ // We don't want to parse text with single '\n', because contentEditable represents it as invisible <br />
239
+ if (text) {
240
+ const {
241
+ dom,
242
+ tree
243
+ } = parseRangesToHTMLNodes(text, markdownRanges, markdownStyle);
244
+ if (shouldForceDOMUpdate || targetElement.innerHTML !== dom.innerHTML) {
245
+ targetElement.innerHTML = '';
246
+ targetElement.innerText = '';
247
+ Array.from(dom.children).forEach(child => {
248
+ targetElement.appendChild(child);
249
+ });
250
+ }
251
+ targetElement.tree = tree;
252
+ moveCursor(isFocused, alwaysMoveCursorToTheEnd, cursorPosition, targetElement);
253
+ }
254
+ return {
255
+ text,
256
+ cursorPosition: cursorPosition || 0
257
+ };
258
+ }
259
+ export { updateInputStructure, parseRangesToHTMLNodes };
260
+ //# sourceMappingURL=parserUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["addNodeToTree","getCurrentCursorPosition","moveCursorToEnd","setCursorPosition","addStyleToBlock","ungroupRanges","ranges","ungroupedRanges","forEach","range","depth","push","rangeWithoutDepth","Array","from","length","splitTextIntoLines","text","lineStartIndex","lines","split","map","line","lineObject","start","markdownRanges","mergeLinesWithMultilineTags","mergedLines","lineIndexes","_line","index","beginLineIndex","findLastIndex","endLineIndex","findIndex","correspondingLineIndexes","slice","mainLineIndex","mainLine","otherLineIndexes","lineIndex","otherLine","filter","includes","appendValueToElement","element","parentTreeNode","value","targetElement","parentNode","appendNode","type","node","appendChild","addBrElement","span","document","createElement","setAttribute","spanNode","addTextToElement","createTextNode","addParagraph","disableInlineStyles","p","pNode","parseRangesToHTMLNodes","markdownStyle","rootElement","textLength","replace","rootNode","childNodes","orderIndex","isGeneratingNewline","currentParentNode","dom","tree","lastRangeEndIndex","shift","lineMarkdownRanges","endOfCurrentRange","nextRangeStartIndex","textBeforeRange","substring","textAfterRange","moveCursor","isFocused","alwaysMoveCursorToTheEnd","cursorPosition","target","updateInputStructure","cursorPositionIndex","shouldForceDOMUpdate","activeElement","selection","global","parseExpensiMarkToRanges","innerHTML","innerText","children","child"],"sourceRoot":"../../../../src","sources":["web/utils/parserUtils.ts"],"mappings":"AACA,SAAQA,aAAa,QAAO,aAAa;AAGzC,SAAQC,wBAAwB,EAAEC,eAAe,EAAEC,iBAAiB,QAAO,eAAe;AAC1F,SAAQC,eAAe,QAAO,cAAc;AAkB5C,SAASC,aAAaA,CAACC,MAAuB,EAAmB;EAC/D,MAAMC,eAAgC,GAAG,EAAE;EAC3CD,MAAM,CAACE,OAAO,CAAEC,KAAK,IAAK;IACxB,IAAI,CAACA,KAAK,CAACC,KAAK,EAAE;MAChBH,eAAe,CAACI,IAAI,CAACF,KAAK,CAAC;IAC7B;IAC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AK,EAAE;IACtGlD,aAAa,CAACkD,SAAS,GAAG,EAAE;IAC5BlD,aAAa,CAACmD,SAAS,GAAG,EAAE;EAC9B;;EAEA;EACA,IAAIlF,IAAI,EAAE;IACR,MAAM;MAAC2D,GAAG;MAAEC;IAAI,CAAC,GAAGX,sBAAsB,CAACjD,IAAI,EAAEQ,cAAc,EAAE0C,aAAa,CAAC;IAE/E,IAAI0B,oBAAoB,IAAI7C,aAAa,CAACkD,SAAS,KAAKtB,GAAG,CAACsB,SAAS,EAAE;MACrElD,aAAa,CAACkD,SAAS,GAAG,EAAE;MAC5BlD,aAAa,CAACmD,SAAS,GAAG,EAAE;MAC5BtF,KAAK,CAACC,IAAI,CAAC8D,GAAG,CAACwB,QAAQ,CAAC,CAAC5F,OAAO,CAAE6F,KAAK,IAAK;QAC1CrD,aAAa,CAACK,WAAW,CAACgD,KAAK,CAAC;MAClC,CAAC,CAAC;IACJ;IAEArD,aAAa,CAAC6B,IAAI,GAAGA,IAAI;IACzBS,UAAU,CAACC,SAAS,EAAEC,wBAAwB,EAAEC,cAAc,EAAEzC,aAAa,CAAC;EAChF;EAEA,OAAO;IAAC/B,IAAI;IAAEwE,cAAc,EAAEA,cAAc,IAAI;EAAC,CAAC;AACpD;AAEA,SAAQE,oBAAoB,EAAEzB,sBAAsB"}
@@ -0,0 +1,78 @@
1
+ function addNodeToTree(element, parentTreeNode, type, length = null) {
2
+ var _element$value, _element$childNodes$, _element$childNodes$$;
3
+ const contentLength = length || (element.nodeName === 'BR' || type === 'br' ? 1 : (_element$value = element.value) === null || _element$value === void 0 ? void 0 : _element$value.length) || 0;
4
+ const isGeneratingNewline = type === 'line' && !(element.childNodes.length === 1 && ((_element$childNodes$ = element.childNodes[0]) === null || _element$childNodes$ === void 0 || (_element$childNodes$$ = _element$childNodes$.getAttribute) === null || _element$childNodes$$ === void 0 ? void 0 : _element$childNodes$$.call(_element$childNodes$, 'data-type')) === 'br');
5
+ const parentChildrenCount = (parentTreeNode === null || parentTreeNode === void 0 ? void 0 : parentTreeNode.childNodes.length) || 0;
6
+ let startIndex = parentTreeNode.start;
7
+ if (parentChildrenCount > 0) {
8
+ const lastParentChild = parentTreeNode.childNodes[parentChildrenCount - 1];
9
+ if (lastParentChild) {
10
+ startIndex = lastParentChild.start + lastParentChild.length;
11
+ startIndex += lastParentChild.isGeneratingNewline || element.style.display === 'block' ? 1 : 0;
12
+ }
13
+ }
14
+ const item = {
15
+ element,
16
+ parentNode: parentTreeNode,
17
+ childNodes: [],
18
+ start: startIndex,
19
+ length: contentLength,
20
+ type,
21
+ orderIndex: parentTreeNode.parentNode === null ? `${parentChildrenCount}` : `${parentTreeNode.orderIndex},${parentChildrenCount}`,
22
+ isGeneratingNewline
23
+ };
24
+ element.setAttribute('data-id', item.orderIndex);
25
+ parentTreeNode.childNodes.push(item);
26
+ return item;
27
+ }
28
+ function findHTMLElementInTree(treeRoot, element) {
29
+ var _element$hasAttribute, _element$hasAttribute2, _element$getAttribute;
30
+ if ((_element$hasAttribute = element.hasAttribute) !== null && _element$hasAttribute !== void 0 && _element$hasAttribute.call(element, 'contenteditable')) {
31
+ return treeRoot;
32
+ }
33
+ if (!element || !((_element$hasAttribute2 = element.hasAttribute) !== null && _element$hasAttribute2 !== void 0 && _element$hasAttribute2.call(element, 'data-id'))) {
34
+ return null;
35
+ }
36
+ const indexes = (_element$getAttribute = element.getAttribute('data-id')) === null || _element$getAttribute === void 0 ? void 0 : _element$getAttribute.split(',');
37
+ let el = treeRoot;
38
+ while (el && indexes && indexes.length > 0) {
39
+ const index = Number(indexes.shift() || -1);
40
+ if (index < 0) {
41
+ break;
42
+ }
43
+ if (el) {
44
+ el = el.childNodes[index] || null;
45
+ }
46
+ }
47
+ return el;
48
+ }
49
+ function getTreeNodeByIndex(treeRoot, index) {
50
+ let el = treeRoot;
51
+ let i = 0;
52
+ let newLineGenerated = false;
53
+ while (el && el.childNodes.length > 0 && i < el.childNodes.length) {
54
+ const child = el.childNodes[i];
55
+ if (!child) {
56
+ break;
57
+ }
58
+ if (index >= child.start && index < child.start + child.length) {
59
+ if (child.childNodes.length === 0) {
60
+ return child;
61
+ }
62
+ el = child;
63
+ i = 0;
64
+ } else if ((child.isGeneratingNewline || newLineGenerated || i === el.childNodes.length - 1) && index === child.start + child.length) {
65
+ newLineGenerated = true;
66
+ if (child.childNodes.length === 0) {
67
+ return child;
68
+ }
69
+ el = child;
70
+ i = 0;
71
+ } else {
72
+ i++;
73
+ }
74
+ }
75
+ return null;
76
+ }
77
+ export { addNodeToTree, findHTMLElementInTree, getTreeNodeByIndex };
78
+ //# sourceMappingURL=treeUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["addNodeToTree","element","parentTreeNode","type","length","_element$value","_element$childNodes$","_element$childNodes$$","contentLength","nodeName","value","isGeneratingNewline","childNodes","getAttribute","call","parentChildrenCount","startIndex","start","lastParentChild","style","display","item","parentNode","orderIndex","setAttribute","push","findHTMLElementInTree","treeRoot","_element$hasAttribute","_element$hasAttribute2","_element$getAttribute","hasAttribute","indexes","split","el","index","Number","shift","getTreeNodeByIndex","i","newLineGenerated","child"],"sourceRoot":"../../../../src","sources":["web/utils/treeUtils.ts"],"mappings":"AAcA,SAASA,aAAaA,CAACC,OAA4B,EAAEC,cAAwB,EAAEC,IAAc,EAAEC,MAAqB,GAAG,IAAI,EAAE;EAAA,IAAAC,cAAA,EAAAC,oBAAA,EAAAC,qBAAA;EAC3H,MAAMC,aAAa,GAAGJ,MAAM,KAAKH,OAAO,CAACQ,QAAQ,KAAK,IAAI,IAAIN,IAAI,KAAK,IAAI,GAAG,CAAC,IAAAE,cAAA,GAAGJ,OAAO,CAACS,KAAK,cAAAL,cAAA,uBAAbA,cAAA,CAAeD,MAAM,CAAC,IAAI,CAAC;EAC7G,MAAMO,mBAAmB,GAAGR,IAAI,KAAK,MAAM,IAAI,EAAEF,OAAO,CAACW,UAAU,CAACR,MAAM,KAAK,CAAC,IAAI,EAAAE,oBAAA,GAACL,OAAO,CAACW,UAA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