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

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 +1 -1
  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
@@ -1,206 +0,0 @@
1
- import * as CursorUtils from './cursorUtils';
2
- import * as BrowserUtils from './browserUtils';
3
- function addStyling(targetElement, type, markdownStyle) {
4
- const node = targetElement;
5
- switch (type) {
6
- case 'syntax':
7
- Object.assign(node.style, markdownStyle.syntax);
8
- break;
9
- case 'bold':
10
- node.style.fontWeight = 'bold';
11
- break;
12
- case 'italic':
13
- node.style.fontStyle = 'italic';
14
- break;
15
- case 'strikethrough':
16
- node.style.textDecoration = 'line-through';
17
- break;
18
- case 'emoji':
19
- Object.assign(node.style, {
20
- ...markdownStyle.emoji,
21
- verticalAlign: 'middle'
22
- });
23
- break;
24
- case 'mention-here':
25
- Object.assign(node.style, markdownStyle.mentionHere);
26
- break;
27
- case 'mention-user':
28
- Object.assign(node.style, markdownStyle.mentionUser);
29
- break;
30
- case 'mention-report':
31
- Object.assign(node.style, markdownStyle.mentionReport);
32
- break;
33
- case 'link':
34
- Object.assign(node.style, {
35
- ...markdownStyle.link,
36
- textDecoration: 'underline'
37
- });
38
- break;
39
- case 'code':
40
- Object.assign(node.style, markdownStyle.code);
41
- break;
42
- case 'pre':
43
- Object.assign(node.style, markdownStyle.pre);
44
- break;
45
- case 'blockquote':
46
- Object.assign(node.style, {
47
- ...markdownStyle.blockquote,
48
- borderLeftStyle: 'solid',
49
- display: 'inline-block',
50
- maxWidth: '100%',
51
- boxSizing: 'border-box'
52
- });
53
- break;
54
- case 'h1':
55
- Object.assign(node.style, {
56
- ...markdownStyle.h1,
57
- fontWeight: 'bold'
58
- });
59
- break;
60
- default:
61
- break;
62
- }
63
- }
64
- function addSubstringAsTextNode(root, text, startIndex, endIndex) {
65
- const substring = text.substring(startIndex, endIndex);
66
- if (substring.length > 0) {
67
- root.appendChild(document.createTextNode(substring));
68
- }
69
- }
70
- function ungroupRanges(ranges) {
71
- const ungroupedRanges = [];
72
- ranges.forEach(range => {
73
- if (!range.depth) {
74
- ungroupedRanges.push(range);
75
- }
76
- const {
77
- depth,
78
- ...rangeWithoutDepth
79
- } = range;
80
- Array.from({
81
- length: depth
82
- }).forEach(() => {
83
- ungroupedRanges.push(rangeWithoutDepth);
84
- });
85
- });
86
- return ungroupedRanges;
87
- }
88
- function parseRangesToHTMLNodes(text, ranges, markdownStyle = {}, disableInlineStyles = false) {
89
- const root = document.createElement('span');
90
- root.className = 'root';
91
- const textLength = text.length;
92
- if (ranges.length === 0) {
93
- addSubstringAsTextNode(root, text, 0, textLength);
94
- return root;
95
- }
96
- const stack = ungroupRanges(ranges);
97
- const nestedStack = [{
98
- node: root,
99
- endIndex: textLength
100
- }];
101
- let lastRangeEndIndex = 0;
102
- while (stack.length > 0) {
103
- const range = stack.shift();
104
- if (!range) {
105
- break;
106
- }
107
- let currentRoot = nestedStack[nestedStack.length - 1];
108
- if (!currentRoot) {
109
- break;
110
- }
111
- const endOfCurrentRange = range.start + range.length;
112
- const nextRangeStartIndex = stack.length > 0 && !!stack[0] ? stack[0].start || 0 : textLength;
113
- addSubstringAsTextNode(currentRoot.node, text, lastRangeEndIndex, range.start); // add text with newlines before current range
114
-
115
- const span = document.createElement('span');
116
- if (disableInlineStyles) {
117
- span.className = range.type;
118
- } else {
119
- addStyling(span, range.type, markdownStyle);
120
- }
121
- if (stack.length > 0 && nextRangeStartIndex < endOfCurrentRange && range.type !== 'syntax') {
122
- // tag nesting
123
- currentRoot.node.appendChild(span);
124
- nestedStack.push({
125
- node: span,
126
- endIndex: endOfCurrentRange
127
- });
128
- lastRangeEndIndex = range.start;
129
- } else {
130
- addSubstringAsTextNode(span, text, range.start, endOfCurrentRange);
131
- currentRoot.node.appendChild(span);
132
- lastRangeEndIndex = endOfCurrentRange;
133
-
134
- // end of tag nesting
135
- while (nestedStack.length - 1 > 0 && nextRangeStartIndex >= currentRoot.endIndex) {
136
- addSubstringAsTextNode(currentRoot.node, text, lastRangeEndIndex, currentRoot.endIndex);
137
- const prevRoot = nestedStack.pop();
138
- if (!prevRoot) {
139
- break;
140
- }
141
- lastRangeEndIndex = prevRoot.endIndex;
142
- currentRoot = nestedStack[nestedStack.length - 1] || currentRoot;
143
- }
144
- }
145
- }
146
- if (nestedStack.length > 1) {
147
- const lastNestedNode = nestedStack[nestedStack.length - 1];
148
- if (lastNestedNode) {
149
- root.appendChild(lastNestedNode.node);
150
- }
151
- }
152
- addSubstringAsTextNode(root, text, lastRangeEndIndex, textLength);
153
- return root;
154
- }
155
- function moveCursor(isFocused, alwaysMoveCursorToTheEnd, cursorPosition, target) {
156
- if (!isFocused) {
157
- return;
158
- }
159
- if (alwaysMoveCursorToTheEnd || cursorPosition === null) {
160
- CursorUtils.moveCursorToEnd(target);
161
- } else if (cursorPosition !== null) {
162
- CursorUtils.setCursorPosition(target, cursorPosition);
163
- }
164
- }
165
- function parseText(target, text, cursorPositionIndex, markdownStyle = {}, alwaysMoveCursorToTheEnd = false) {
166
- const targetElement = target;
167
-
168
- // in case the cursorPositionIndex is larger than text length, cursorPosition will be null, i.e: move the caret to the end
169
- let cursorPosition = cursorPositionIndex && cursorPositionIndex <= text.length ? cursorPositionIndex : null;
170
- const isFocused = document.activeElement === target;
171
- if (isFocused && cursorPositionIndex === null) {
172
- const selection = CursorUtils.getCurrentCursorPosition(target);
173
- cursorPosition = selection ? selection.end : null;
174
- }
175
- const ranges = global.parseExpensiMarkToRanges(text);
176
- const markdownRanges = ranges;
177
- const rootSpan = targetElement.firstChild;
178
- if (!text || targetElement.innerHTML === '<br>' || rootSpan && rootSpan.innerHTML === '\n') {
179
- targetElement.innerHTML = '';
180
- targetElement.innerText = '';
181
- }
182
-
183
- // We don't want to parse text with single '\n', because contentEditable represents it as invisible <br />
184
- if (text) {
185
- var _rootSpan$classList;
186
- const dom = parseRangesToHTMLNodes(text, markdownRanges, markdownStyle);
187
- if (!rootSpan || !(rootSpan !== null && rootSpan !== void 0 && (_rootSpan$classList = rootSpan.classList) !== null && _rootSpan$classList !== void 0 && _rootSpan$classList.contains('root')) || rootSpan.innerHTML !== dom.innerHTML) {
188
- targetElement.innerHTML = '';
189
- targetElement.innerText = '';
190
- target.appendChild(dom);
191
- if (BrowserUtils.isChromium) {
192
- moveCursor(isFocused, alwaysMoveCursorToTheEnd, cursorPosition, target);
193
- }
194
- }
195
- if (!BrowserUtils.isChromium) {
196
- moveCursor(isFocused, alwaysMoveCursorToTheEnd, cursorPosition, target);
197
- }
198
- }
199
- CursorUtils.setPrevText(target);
200
- return {
201
- text: target.innerText,
202
- cursorPosition: cursorPosition || 0
203
- };
204
- }
205
- export { parseText, parseRangesToHTMLNodes };
206
- //# sourceMappingURL=parserUtils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["CursorUtils","BrowserUtils","addStyling","targetElement","type","markdownStyle","node","Object","assign","style","syntax","fontWeight","fontStyle","textDecoration","emoji","verticalAlign","mentionHere","mentionUser","mentionReport","link","code","pre","blockquote","borderLeftStyle","display","maxWidth","boxSizing","h1","addSubstringAsTextNode","root","text","startIndex","endIndex","substring","length","appendChild","document","createTextNode","ungroupRanges","ranges","ungroupedRanges","forEach","range","depth","push","rangeWithoutDepth","Array","from","parseRangesToHTMLNodes","disableInlineStyles","createElement","className","textLength","stack","nestedStack","lastRangeEndIndex","shift","currentRoot","endOfCurrentRange","start","nextRangeStartIndex","span","prevRoot","pop","lastNestedNode","moveCursor","isFocused","alwaysMoveCursorToTheEnd","cursorPosition","target","moveCursorToEnd","setCursorPosition","parseText","cursorPositionIndex","activeElement","selection","getCurrentCursorPosition","end","global","parseExpensiMarkToRanges","markdownRanges","rootSpan","firstChild","innerHTML","innerText","_rootSpan$classList","dom","classList","contains","isChromium","setPrevText"],"sourceRoot":"../../../src","sources":["web/parserUtils.ts"],"mappings":"AAAA,OAAO,KAAKA,WAAW,MAAM,eAAe;AAE5C,OAAO,KAAKC,YAAY,MAAM,gBAAgB;AAkB9C,SAASC,UAAUA,CAACC,aAA0B,EAAEC,IAAkB,EAAEC,aAAmC,EAAE;EACvG,MAAMC,IAAI,GAAGH,aAAa;EAC1B,QAAQC,IAAI;IACV,KAAK,QAAQ;MACXG,MAAM,CAACC,MAAM,CAACF,IAAI,CAACG,KAAK,EAAEJ,aAAa,CAACK,MAAM,CAAC;MAC/C;IACF,KAAK,MAAM;MACTJ,IAAI,CAACG,KAAK,CAACE,UAAU,GAAG,MAAM;MAC9B;IACF,KAAK,QAAQ;MACXL,IAAI,CAACG,KAAK,CAACG,SAAS,GAAG,QAAQ;MAC/B;IACF,KAAK,eA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AAAuD,mBAAA;IACR,MAAMC,GAAG,GAAGtC,sBAAsB,CAAClB,IAAI,EAAEkD,cAAc,EAAE3E,aAAa,CAAC;IAEvE,IAAI,CAAC4E,QAAQ,IAAI,EAACA,QAAQ,aAARA,QAAQ,gBAAAI,mBAAA,GAARJ,QAAQ,CAAEM,SAAS,cAAAF,mBAAA,eAAnBA,mBAAA,CAAqBG,QAAQ,CAAC,MAAM,CAAC,KAAIP,QAAQ,CAACE,SAAS,KAAKG,GAAG,CAACH,SAAS,EAAE;MAC/FhF,aAAa,CAACgF,SAAS,GAAG,EAAE;MAC5BhF,aAAa,CAACiF,SAAS,GAAG,EAAE;MAC5Bf,MAAM,CAAClC,WAAW,CAACmD,GAAG,CAAC;MAEvB,IAAIrF,YAAY,CAACwF,UAAU,EAAE;QAC3BxB,UAAU,CAACC,SAAS,EAAEC,wBAAwB,EAAEC,cAAc,EAAEC,MAAM,CAAC;MACzE;IACF;IAEA,IAAI,CAACpE,YAAY,CAACwF,UAAU,EAAE;MAC5BxB,UAAU,CAACC,SAAS,EAAEC,wBAAwB,EAAEC,cAAc,EAAEC,MAAM,CAAC;IACzE;EACF;EAEArE,WAAW,CAAC0F,WAAW,CAACrB,MAAM,CAAC;EAE/B,OAAO;IAACvC,IAAI,EAAEuC,MAAM,CAACe,SAAS;IAAEhB,cAAc,EAAEA,cAAc,IAAI;EAAC,CAAC;AACtE;AAEA,SAAQI,SAAS,EAAExB,sBAAsB"}
@@ -1,10 +0,0 @@
1
- declare const isFirefox: boolean;
2
- declare const isChromium: boolean;
3
- /**
4
- * Whether the platform is a mobile browser.
5
- * Copied from Expensify App https://github.com/Expensify/App/blob/90dee7accae79c49debf30354c160cab6c52c423/src/libs/Browser/index.website.ts#L41
6
- *
7
- */
8
- declare const isMobile: boolean;
9
- export { isFirefox, isChromium, isMobile };
10
- //# sourceMappingURL=browserUtils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"browserUtils.d.ts","sourceRoot":"","sources":["../../../../src/web/browserUtils.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,SAAS,SAAwD,CAAC;AACxE,QAAA,MAAM,UAAU,SAAqB,CAAC;AAEtC;;;;GAIG;AACH,QAAA,MAAM,QAAQ,SAA4H,CAAC;AAE3I,OAAO,EAAC,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAC,CAAC"}
@@ -1,12 +0,0 @@
1
- declare function getPrevTextLength(): number | undefined;
2
- declare function setPrevText(target: HTMLElement): void;
3
- declare function setCursorPosition(target: HTMLElement, start: number, end?: number | null): void;
4
- declare function moveCursorToEnd(target: HTMLElement): void;
5
- declare function getCurrentCursorPosition(target: HTMLElement): {
6
- start: number;
7
- end: number;
8
- } | null;
9
- declare function removeSelection(): void;
10
- declare function scrollCursorIntoView(target: HTMLInputElement): void;
11
- export { getCurrentCursorPosition, moveCursorToEnd, setCursorPosition, setPrevText, removeSelection, scrollCursorIntoView, getPrevTextLength };
12
- //# sourceMappingURL=cursorUtils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cursorUtils.d.ts","sourceRoot":"","sources":["../../../../src/web/cursorUtils.ts"],"names":[],"mappings":"AAIA,iBAAS,iBAAiB,uBAEzB;AAeD,iBAAS,WAAW,CAAC,MAAM,EAAE,WAAW,QAUvC;AAED,iBAAS,iBAAiB,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,GAAE,MAAM,GAAG,IAAW,QAuEvF;AAED,iBAAS,eAAe,CAAC,MAAM,EAAE,WAAW,QAQ3C;AAED,iBAAS,wBAAwB,CAAC,MAAM,EAAE,WAAW;;;SAYpD;AAED,iBAAS,eAAe,SAKvB;AAED,iBAAS,oBAAoB,CAAC,MAAM,EAAE,gBAAgB,QAqCrD;AAED,OAAO,EAAC,wBAAwB,EAAE,eAAe,EAAE,iBAAiB,EAAE,WAAW,EAAE,eAAe,EAAE,oBAAoB,EAAE,iBAAiB,EAAC,CAAC"}
@@ -1,17 +0,0 @@
1
- import type * as StyleUtilsTypes from '../styleUtils';
2
- type PartialMarkdownStyle = StyleUtilsTypes.PartialMarkdownStyle;
3
- type MarkdownType = 'bold' | 'italic' | 'strikethrough' | 'emoji' | 'link' | 'code' | 'pre' | 'blockquote' | 'h1' | 'syntax' | 'mention-here' | 'mention-user' | 'mention-report';
4
- type MarkdownRange = {
5
- type: MarkdownType;
6
- start: number;
7
- length: number;
8
- depth?: number;
9
- };
10
- declare function parseRangesToHTMLNodes(text: string, ranges: MarkdownRange[], markdownStyle?: PartialMarkdownStyle, disableInlineStyles?: boolean): HTMLElement;
11
- declare function parseText(target: HTMLElement, text: string, cursorPositionIndex: number | null, markdownStyle?: PartialMarkdownStyle, alwaysMoveCursorToTheEnd?: boolean): {
12
- text: string;
13
- cursorPosition: number;
14
- };
15
- export { parseText, parseRangesToHTMLNodes };
16
- export type { MarkdownRange, MarkdownType };
17
- //# sourceMappingURL=parserUtils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parserUtils.d.ts","sourceRoot":"","sources":["../../../../src/web/parserUtils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,eAAe,MAAM,eAAe,CAAC;AAGtD,KAAK,oBAAoB,GAAG,eAAe,CAAC,oBAAoB,CAAC;AAEjE,KAAK,YAAY,GAAG,MAAM,GAAG,QAAQ,GAAG,eAAe,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,YAAY,GAAG,IAAI,GAAG,QAAQ,GAAG,cAAc,GAAG,cAAc,GAAG,gBAAgB,CAAC;AAElL,KAAK,aAAa,GAAG;IACnB,IAAI,EAAE,YAAY,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAwFF,iBAAS,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,EAAE,aAAa,GAAE,oBAAyB,EAAE,mBAAmB,UAAQ,GAAG,WAAW,CAkEzJ;AAcD,iBAAS,SAAS,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,GAAG,IAAI,EAAE,aAAa,GAAE,oBAAyB,EAAE,wBAAwB,UAAQ;;;EA0CnK;AAED,OAAO,EAAC,SAAS,EAAE,sBAAsB,EAAC,CAAC;AAE3C,YAAY,EAAC,aAAa,EAAE,YAAY,EAAC,CAAC"}
@@ -1,11 +0,0 @@
1
- const isFirefox = navigator.userAgent.toLowerCase().includes('firefox');
2
- const isChromium = 'chrome' in window;
3
-
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
- const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|BB|PlayBook|IEMobile|Windows Phone|Silk|Opera Mini/i.test(navigator.userAgent);
10
-
11
- export {isFirefox, isChromium, isMobile};
@@ -1,177 +0,0 @@
1
- import * as BrowserUtils from './browserUtils';
2
-
3
- let prevTextLength: number | undefined;
4
-
5
- function getPrevTextLength() {
6
- return prevTextLength;
7
- }
8
-
9
- function findTextNodes(textNodes: Text[], node: ChildNode) {
10
- if (node.nodeType === Node.TEXT_NODE) {
11
- textNodes.push(node as Text);
12
- } else {
13
- for (let i = 0, length = node.childNodes.length; i < length; ++i) {
14
- const childNode = node.childNodes[i];
15
- if (childNode) {
16
- findTextNodes(textNodes, childNode);
17
- }
18
- }
19
- }
20
- }
21
-
22
- function setPrevText(target: HTMLElement) {
23
- let text = [];
24
- const textNodes: Text[] = [];
25
- findTextNodes(textNodes, target);
26
- text = textNodes
27
- .map((e) => e.nodeValue ?? '')
28
- ?.join('')
29
- ?.split('');
30
-
31
- prevTextLength = text.length;
32
- }
33
-
34
- function setCursorPosition(target: HTMLElement, start: number, end: number | null = null) {
35
- // We don't want to move the cursor if the target is not focused
36
- if (target !== document.activeElement) {
37
- return;
38
- }
39
-
40
- const range = document.createRange();
41
- range.selectNodeContents(target);
42
-
43
- const textNodes: Text[] = [];
44
- findTextNodes(textNodes, target);
45
-
46
- // These are utilities for handling the boundary cases (especially onEnter)
47
- // prevChar & nextChar are characters before & after the target cursor position
48
- const textCharacters = textNodes
49
- .map((e) => e.nodeValue ?? '')
50
- ?.join('')
51
- ?.split('');
52
- const prevChar = textCharacters?.[start - 1] ?? '';
53
- const nextChar = textCharacters?.[start] ?? '';
54
-
55
- let charCount = 0;
56
- let startNode: Text | null = null;
57
- let endNode: Text | null = null;
58
- const n = textNodes.length;
59
- for (let i = 0; i < n; ++i) {
60
- const textNode = textNodes[i];
61
- if (textNode) {
62
- const nextCharCount = charCount + textNode.length;
63
-
64
- if (!startNode && start >= charCount && (start <= nextCharCount || (start === nextCharCount && i < n - 1))) {
65
- startNode = textNode;
66
-
67
- // There are 4 cases to consider here:
68
- // 1. Caret in front of a character, when pressing enter
69
- // 2. Caret at the end of a line (not last one)
70
- // 3. Caret at the end of whole input, when pressing enter
71
- // 4. All other placements
72
- if (prevChar === '\n' && prevTextLength !== undefined && prevTextLength < textCharacters.length) {
73
- if (nextChar && nextChar !== '\n' && i !== n - 1) {
74
- range.setStart(textNodes[i + 1] as Node, 0);
75
- } else if (i !== textNodes.length - 1) {
76
- range.setStart(textNodes[i] as Node, 1);
77
- } else {
78
- range.setStart(textNode, start - charCount);
79
- }
80
- } else {
81
- range.setStart(textNode, start - charCount);
82
- }
83
- if (!end) {
84
- break;
85
- }
86
- }
87
- if (end && !endNode && end >= charCount && (end <= nextCharCount || (end === nextCharCount && i < n - 1))) {
88
- endNode = textNode;
89
- range.setEnd(textNode, end - charCount);
90
- }
91
- charCount = nextCharCount;
92
- }
93
- }
94
-
95
- if (!end) {
96
- range.collapse(true);
97
- }
98
-
99
- const selection = window.getSelection();
100
- if (selection) {
101
- selection.setBaseAndExtent(range.startContainer, range.startOffset, range.endContainer, range.endOffset);
102
- }
103
-
104
- scrollCursorIntoView(target as HTMLInputElement);
105
- }
106
-
107
- function moveCursorToEnd(target: HTMLElement) {
108
- const range = document.createRange();
109
- const selection = window.getSelection();
110
- if (selection) {
111
- range.setStart(target, target.childNodes.length);
112
- range.collapse(true);
113
- selection.setBaseAndExtent(range.startContainer, range.startOffset, range.endContainer, range.endOffset);
114
- }
115
- }
116
-
117
- function getCurrentCursorPosition(target: HTMLElement) {
118
- const selection = window.getSelection();
119
- if (!selection || (selection && selection.rangeCount === 0)) {
120
- return null;
121
- }
122
- const range = selection.getRangeAt(0);
123
- const preSelectionRange = range.cloneRange();
124
- preSelectionRange.selectNodeContents(target);
125
- preSelectionRange.setEnd(range.startContainer, range.startOffset);
126
- const start = preSelectionRange.toString().length;
127
- const end = start + range.toString().length;
128
- return {start, end};
129
- }
130
-
131
- function removeSelection() {
132
- const selection = window.getSelection();
133
- if (selection) {
134
- selection.removeAllRanges();
135
- }
136
- }
137
-
138
- function scrollCursorIntoView(target: HTMLInputElement) {
139
- if (target.selectionStart === null || !target.value || BrowserUtils.isFirefox) {
140
- return;
141
- }
142
-
143
- const selection = window.getSelection();
144
- if (!selection || (selection && selection.rangeCount === 0)) {
145
- return;
146
- }
147
-
148
- const caretRects = selection.getRangeAt(0).getClientRects();
149
-
150
- // we'll find the caretRect from the DOMRectList above with the largest bottom value
151
- let currentCaretRect = caretRects[0];
152
- if (currentCaretRect) {
153
- for (let i = 1; i < caretRects.length; i++) {
154
- const caretRect = caretRects[i];
155
- if (caretRect && caretRect.bottom > currentCaretRect.bottom) {
156
- currentCaretRect = caretRect;
157
- }
158
- }
159
- }
160
-
161
- const editableRect = target.getBoundingClientRect();
162
-
163
- // Adjust for padding and border
164
- const paddingTop = parseFloat(window.getComputedStyle(target).paddingTop);
165
- const borderTop = parseFloat(window.getComputedStyle(target).borderTopWidth);
166
-
167
- if (currentCaretRect && !(currentCaretRect.top >= editableRect.top + paddingTop + borderTop && currentCaretRect.bottom <= editableRect.bottom - 2 * (paddingTop - borderTop))) {
168
- const topToCaret = currentCaretRect.top - editableRect.top;
169
- const inputHeight = editableRect.height;
170
- // Chrome Rects don't include padding & border, so we're adding them manually
171
- const inputOffset = currentCaretRect.height - inputHeight + paddingTop + borderTop + (BrowserUtils.isChromium ? 0 : 4 * (paddingTop + borderTop));
172
-
173
- target.scrollTo(0, topToCaret + target.scrollTop + inputOffset);
174
- }
175
- }
176
-
177
- export {getCurrentCursorPosition, moveCursorToEnd, setCursorPosition, setPrevText, removeSelection, scrollCursorIntoView, getPrevTextLength};