react-native-marcus 0.1.0

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 (304) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +227 -0
  3. package/RNMarcus.podspec +78 -0
  4. package/android/build.gradle +220 -0
  5. package/android/proguard-rules.pro +1 -0
  6. package/android/src/main/AndroidManifest.xml +3 -0
  7. package/android/src/main/AndroidManifestNew.xml +2 -0
  8. package/android/src/main/cpp/CMakeLists.txt +41 -0
  9. package/android/src/main/cpp/MarkdownParser.cpp +49 -0
  10. package/android/src/main/cpp/MarkdownParser.h +56 -0
  11. package/android/src/main/cpp/OnLoad.cpp +17 -0
  12. package/android/src/main/java/app/getbullet/marcus/MarcusModule.kt +28 -0
  13. package/android/src/main/java/app/getbullet/marcus/MarcusPackage.kt +31 -0
  14. package/android/src/main/java/app/getbullet/marcus/MarcusTextInputDecoratorView.kt +63 -0
  15. package/android/src/main/java/app/getbullet/marcus/MarcusTextInputDecoratorViewManager.kt +32 -0
  16. package/android/src/main/java/app/getbullet/marcus/MarcusTextInputDecoratorViewManagerSpec.kt +21 -0
  17. package/android/src/main/java/app/getbullet/marcus/MarkdownFormatter.kt +333 -0
  18. package/android/src/main/java/app/getbullet/marcus/MarkdownParseResult.kt +12 -0
  19. package/android/src/main/java/app/getbullet/marcus/MarkdownParser.kt +89 -0
  20. package/android/src/main/java/app/getbullet/marcus/MarkdownRange.kt +11 -0
  21. package/android/src/main/java/app/getbullet/marcus/MarkdownStyle.kt +81 -0
  22. package/android/src/main/java/app/getbullet/marcus/MarkdownTextWatcher.kt +17 -0
  23. package/android/src/main/java/app/getbullet/marcus/MarkdownUtils.kt +84 -0
  24. package/android/src/main/java/app/getbullet/marcus/ReactLineHeight.java +29 -0
  25. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownBackgroundColorSpan.kt +6 -0
  26. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownBackgroundSpan.kt +105 -0
  27. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownBlockIndentSpan.kt +67 -0
  28. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownBoldSpan.kt +6 -0
  29. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownFontFamilySpan.kt +28 -0
  30. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownFontSizeSpan.kt +7 -0
  31. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownForegroundColorSpan.kt +6 -0
  32. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownGapSpan.kt +57 -0
  33. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownItalicSpan.kt +6 -0
  34. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownLineHeightSpan.kt +21 -0
  35. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownSpan.kt +7 -0
  36. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownStrikethroughSpan.kt +5 -0
  37. package/android/src/main/java/app/getbullet/marcus/spans/MarkdownUnderlineSpan.kt +5 -0
  38. package/android/src/main/new_arch/CMakeLists.txt +70 -0
  39. package/android/src/main/new_arch/RNMarcusSpec.cpp +43 -0
  40. package/android/src/main/new_arch/RNMarcusSpec.h +36 -0
  41. package/android/src/main/new_arch/react/renderer/components/RNMarcusSpec/MarcusTextInputDecoratorShadowNode.cpp +218 -0
  42. package/android/src/main/new_arch/react/renderer/components/RNMarcusSpec/MarcusTextInputDecoratorShadowNode.h +54 -0
  43. package/android/src/reactNativeVersionPatch/CustomMountingManager/81/app/getbullet/marcus/CustomFabricUIManager.java +156 -0
  44. package/android/src/reactNativeVersionPatch/CustomMountingManager/latest/app/getbullet/marcus/CustomFabricUIManager.java +130 -0
  45. package/android/src/test/java/app/getbullet/marcus/MarkdownFormatterTest.kt +205 -0
  46. package/android/src/test/java/app/getbullet/marcus/RenderModel.kt +78 -0
  47. package/android/src/test/resources/render-model.txt +583 -0
  48. package/apple/MarcusModule.h +8 -0
  49. package/apple/MarcusModule.mm +26 -0
  50. package/apple/MarcusRange.h +15 -0
  51. package/apple/MarcusRange.mm +15 -0
  52. package/apple/MarcusTextInputDecoratorComponentView.h +12 -0
  53. package/apple/MarcusTextInputDecoratorComponentView.mm +121 -0
  54. package/apple/MarcusTextInputDecoratorShadowNode.cpp +251 -0
  55. package/apple/MarcusTextInputDecoratorShadowNode.h +65 -0
  56. package/apple/MarcusTextInputDecoratorShadowNode.mm +204 -0
  57. package/apple/MarcusTextInputDecoratorViewManager.h +8 -0
  58. package/apple/MarcusTextInputDecoratorViewManager.mm +11 -0
  59. package/apple/MarkdownAdaptiveImageGlyph.swift +44 -0
  60. package/apple/MarkdownAttributes.h +31 -0
  61. package/apple/MarkdownAttributes.m +9 -0
  62. package/apple/MarkdownBackedTextInputDelegate.swift +117 -0
  63. package/apple/MarkdownDecorator.swift +316 -0
  64. package/apple/MarkdownFonts.swift +21 -0
  65. package/apple/MarkdownFormatter+React.swift +51 -0
  66. package/apple/MarkdownFormatter.swift +509 -0
  67. package/apple/MarkdownLog.h +10 -0
  68. package/apple/MarkdownLog.mm +6 -0
  69. package/apple/MarkdownParser.swift +200 -0
  70. package/apple/MarkdownSwiftInterop.h +23 -0
  71. package/apple/MarkdownTextBackground.swift +17 -0
  72. package/apple/MarkdownTextFieldObserver.swift +90 -0
  73. package/apple/MarkdownTextLayoutFragment.swift +205 -0
  74. package/apple/MarkdownTextLayoutManagerDelegate.swift +84 -0
  75. package/apple/MarkdownTextStorageDelegate.swift +32 -0
  76. package/apple/MarkdownTextViewObserver.swift +30 -0
  77. package/apple/RCTMarcusStyle+Codegen.h +18 -0
  78. package/apple/RCTMarcusStyle+Codegen.mm +64 -0
  79. package/apple/RCTMarcusStyle.h +41 -0
  80. package/apple/RCTMarcusStyle.m +5 -0
  81. package/apple/RCTMarcusUtils.h +26 -0
  82. package/apple/RCTMarcusUtils.mm +26 -0
  83. package/apple/RCTTextInput+AdaptiveImageGlyph.h +16 -0
  84. package/apple/RCTTextInput+AdaptiveImageGlyph.mm +79 -0
  85. package/apple/RCTTextInputComponentView+Marcus.h +11 -0
  86. package/apple/RCTTextInputComponentView+Marcus.mm +79 -0
  87. package/cpp/MarkdownCxx.modulemap +8 -0
  88. package/cpp/MarkdownGlobal.cpp +48 -0
  89. package/cpp/MarkdownGlobal.h +33 -0
  90. package/cpp/MarkdownWorkletParser.cpp +93 -0
  91. package/cpp/MarkdownWorkletParser.h +45 -0
  92. package/cpp/RuntimeDecorator.cpp +39 -0
  93. package/cpp/RuntimeDecorator.h +14 -0
  94. package/cpp/react/renderer/components/RNMarcusSpec/MarcusTextInputDecoratorState.h +33 -0
  95. package/cpp/react/renderer/components/RNMarcusSpec/MarcusTextInputDecoratorViewComponentDescriptor.h +17 -0
  96. package/lib/commonjs/MarcusTextInputDecoratorViewNativeComponent.ts +77 -0
  97. package/lib/commonjs/MarkdownTextInput.js +99 -0
  98. package/lib/commonjs/MarkdownTextInput.js.map +1 -0
  99. package/lib/commonjs/MarkdownTextInput.web.js +618 -0
  100. package/lib/commonjs/MarkdownTextInput.web.js.map +1 -0
  101. package/lib/commonjs/NativeMarcusModule.js +9 -0
  102. package/lib/commonjs/NativeMarcusModule.js.map +1 -0
  103. package/lib/commonjs/commonTypes.js +2 -0
  104. package/lib/commonjs/commonTypes.js.map +1 -0
  105. package/lib/commonjs/global.d.js +2 -0
  106. package/lib/commonjs/global.d.js.map +1 -0
  107. package/lib/commonjs/index.js +27 -0
  108. package/lib/commonjs/index.js.map +1 -0
  109. package/lib/commonjs/package.json +1 -0
  110. package/lib/commonjs/parser/index.js +7030 -0
  111. package/lib/commonjs/parser/index.js.map +7 -0
  112. package/lib/commonjs/rangeUtils.js +71 -0
  113. package/lib/commonjs/rangeUtils.js.map +1 -0
  114. package/lib/commonjs/react-native-web.d.js +2 -0
  115. package/lib/commonjs/react-native-web.d.js.map +1 -0
  116. package/lib/commonjs/styleUtils.js +91 -0
  117. package/lib/commonjs/styleUtils.js.map +1 -0
  118. package/lib/commonjs/web/InputHistory.js +111 -0
  119. package/lib/commonjs/web/InputHistory.js.map +1 -0
  120. package/lib/commonjs/web/MarkdownTextInput.css +72 -0
  121. package/lib/commonjs/web/utils/blockLayout.js +132 -0
  122. package/lib/commonjs/web/utils/blockLayout.js.map +1 -0
  123. package/lib/commonjs/web/utils/blockUtils.js +219 -0
  124. package/lib/commonjs/web/utils/blockUtils.js.map +1 -0
  125. package/lib/commonjs/web/utils/browserUtils.js +40 -0
  126. package/lib/commonjs/web/utils/browserUtils.js.map +1 -0
  127. package/lib/commonjs/web/utils/cursorUtils.js +157 -0
  128. package/lib/commonjs/web/utils/cursorUtils.js.map +1 -0
  129. package/lib/commonjs/web/utils/inputUtils.js +152 -0
  130. package/lib/commonjs/web/utils/inputUtils.js.map +1 -0
  131. package/lib/commonjs/web/utils/measureUtils.js +0 -0
  132. package/lib/commonjs/web/utils/measureUtils.js.map +1 -0
  133. package/lib/commonjs/web/utils/parserUtils.js +552 -0
  134. package/lib/commonjs/web/utils/parserUtils.js.map +1 -0
  135. package/lib/commonjs/web/utils/treeUtils.js +109 -0
  136. package/lib/commonjs/web/utils/treeUtils.js.map +1 -0
  137. package/lib/commonjs/web/utils/webStyleUtils.js +59 -0
  138. package/lib/commonjs/web/utils/webStyleUtils.js.map +1 -0
  139. package/lib/module/MarcusTextInputDecoratorViewNativeComponent.ts +77 -0
  140. package/lib/module/MarkdownTextInput.js +94 -0
  141. package/lib/module/MarkdownTextInput.js.map +1 -0
  142. package/lib/module/MarkdownTextInput.web.js +612 -0
  143. package/lib/module/MarkdownTextInput.web.js.map +1 -0
  144. package/lib/module/NativeMarcusModule.js +5 -0
  145. package/lib/module/NativeMarcusModule.js.map +1 -0
  146. package/lib/module/commonTypes.js +2 -0
  147. package/lib/module/commonTypes.js.map +1 -0
  148. package/lib/module/global.d.js +2 -0
  149. package/lib/module/global.d.js.map +1 -0
  150. package/lib/module/index.js +5 -0
  151. package/lib/module/index.js.map +1 -0
  152. package/lib/module/package.json +1 -0
  153. package/lib/module/parser/index.js +7029 -0
  154. package/lib/module/parser/index.js.map +7 -0
  155. package/lib/module/rangeUtils.js +66 -0
  156. package/lib/module/rangeUtils.js.map +1 -0
  157. package/lib/module/react-native-web.d.js +2 -0
  158. package/lib/module/react-native-web.d.js.map +1 -0
  159. package/lib/module/styleUtils.js +88 -0
  160. package/lib/module/styleUtils.js.map +1 -0
  161. package/lib/module/web/InputHistory.js +106 -0
  162. package/lib/module/web/InputHistory.js.map +1 -0
  163. package/lib/module/web/MarkdownTextInput.css +72 -0
  164. package/lib/module/web/utils/blockLayout.js +128 -0
  165. package/lib/module/web/utils/blockLayout.js.map +1 -0
  166. package/lib/module/web/utils/blockUtils.js +210 -0
  167. package/lib/module/web/utils/blockUtils.js.map +1 -0
  168. package/lib/module/web/utils/browserUtils.js +36 -0
  169. package/lib/module/web/utils/browserUtils.js.map +1 -0
  170. package/lib/module/web/utils/cursorUtils.js +150 -0
  171. package/lib/module/web/utils/cursorUtils.js.map +1 -0
  172. package/lib/module/web/utils/inputUtils.js +144 -0
  173. package/lib/module/web/utils/inputUtils.js.map +1 -0
  174. package/lib/module/web/utils/measureUtils.js +0 -0
  175. package/lib/module/web/utils/measureUtils.js.map +1 -0
  176. package/lib/module/web/utils/parserUtils.js +547 -0
  177. package/lib/module/web/utils/parserUtils.js.map +1 -0
  178. package/lib/module/web/utils/treeUtils.js +103 -0
  179. package/lib/module/web/utils/treeUtils.js.map +1 -0
  180. package/lib/module/web/utils/webStyleUtils.js +54 -0
  181. package/lib/module/web/utils/webStyleUtils.js.map +1 -0
  182. package/lib/typescript/commonjs/e2e/checks.test.d.ts +2 -0
  183. package/lib/typescript/commonjs/e2e/checks.test.d.ts.map +1 -0
  184. package/lib/typescript/commonjs/e2e/editing.test.d.ts +2 -0
  185. package/lib/typescript/commonjs/e2e/editing.test.d.ts.map +1 -0
  186. package/lib/typescript/commonjs/e2e/helpers.d.ts +23 -0
  187. package/lib/typescript/commonjs/e2e/helpers.d.ts.map +1 -0
  188. package/lib/typescript/commonjs/e2e/smoke.test.d.ts +2 -0
  189. package/lib/typescript/commonjs/e2e/smoke.test.d.ts.map +1 -0
  190. package/lib/typescript/commonjs/package.json +1 -0
  191. package/lib/typescript/commonjs/src/MarcusTextInputDecoratorViewNativeComponent.d.ts +63 -0
  192. package/lib/typescript/commonjs/src/MarcusTextInputDecoratorViewNativeComponent.d.ts.map +1 -0
  193. package/lib/typescript/commonjs/src/MarkdownTextInput.d.ts +22 -0
  194. package/lib/typescript/commonjs/src/MarkdownTextInput.d.ts.map +1 -0
  195. package/lib/typescript/commonjs/src/MarkdownTextInput.web.d.ts +41 -0
  196. package/lib/typescript/commonjs/src/MarkdownTextInput.web.d.ts.map +1 -0
  197. package/lib/typescript/commonjs/src/NativeMarcusModule.d.ts +7 -0
  198. package/lib/typescript/commonjs/src/NativeMarcusModule.d.ts.map +1 -0
  199. package/lib/typescript/commonjs/src/commonTypes.d.ts +10 -0
  200. package/lib/typescript/commonjs/src/commonTypes.d.ts.map +1 -0
  201. package/lib/typescript/commonjs/src/index.d.ts +5 -0
  202. package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
  203. package/lib/typescript/commonjs/src/parser/index.d.ts +8 -0
  204. package/lib/typescript/commonjs/src/parser/index.d.ts.map +1 -0
  205. package/lib/typescript/commonjs/src/parser/micromark-extension-mentions.d.ts +8 -0
  206. package/lib/typescript/commonjs/src/parser/micromark-extension-mentions.d.ts.map +1 -0
  207. package/lib/typescript/commonjs/src/rangeUtils.d.ts +6 -0
  208. package/lib/typescript/commonjs/src/rangeUtils.d.ts.map +1 -0
  209. package/lib/typescript/commonjs/src/styleUtils.d.ts +8 -0
  210. package/lib/typescript/commonjs/src/styleUtils.d.ts.map +1 -0
  211. package/lib/typescript/commonjs/src/web/InputHistory.d.ts +24 -0
  212. package/lib/typescript/commonjs/src/web/InputHistory.d.ts.map +1 -0
  213. package/lib/typescript/commonjs/src/web/utils/blockLayout.d.ts +41 -0
  214. package/lib/typescript/commonjs/src/web/utils/blockLayout.d.ts.map +1 -0
  215. package/lib/typescript/commonjs/src/web/utils/blockUtils.d.ts +33 -0
  216. package/lib/typescript/commonjs/src/web/utils/blockUtils.d.ts.map +1 -0
  217. package/lib/typescript/commonjs/src/web/utils/browserUtils.d.ts +7 -0
  218. package/lib/typescript/commonjs/src/web/utils/browserUtils.d.ts.map +1 -0
  219. package/lib/typescript/commonjs/src/web/utils/cursorUtils.d.ts +12 -0
  220. package/lib/typescript/commonjs/src/web/utils/cursorUtils.d.ts.map +1 -0
  221. package/lib/typescript/commonjs/src/web/utils/inputUtils.d.ts +12 -0
  222. package/lib/typescript/commonjs/src/web/utils/inputUtils.d.ts.map +1 -0
  223. package/lib/typescript/commonjs/src/web/utils/measureUtils.d.ts +22 -0
  224. package/lib/typescript/commonjs/src/web/utils/measureUtils.d.ts.map +1 -0
  225. package/lib/typescript/commonjs/src/web/utils/parserUtils.d.ts +44 -0
  226. package/lib/typescript/commonjs/src/web/utils/parserUtils.d.ts.map +1 -0
  227. package/lib/typescript/commonjs/src/web/utils/treeUtils.d.ts +25 -0
  228. package/lib/typescript/commonjs/src/web/utils/treeUtils.d.ts.map +1 -0
  229. package/lib/typescript/commonjs/src/web/utils/webStyleUtils.d.ts +7 -0
  230. package/lib/typescript/commonjs/src/web/utils/webStyleUtils.d.ts.map +1 -0
  231. package/lib/typescript/module/e2e/checks.test.d.ts +2 -0
  232. package/lib/typescript/module/e2e/checks.test.d.ts.map +1 -0
  233. package/lib/typescript/module/e2e/editing.test.d.ts +2 -0
  234. package/lib/typescript/module/e2e/editing.test.d.ts.map +1 -0
  235. package/lib/typescript/module/e2e/helpers.d.ts +23 -0
  236. package/lib/typescript/module/e2e/helpers.d.ts.map +1 -0
  237. package/lib/typescript/module/e2e/smoke.test.d.ts +2 -0
  238. package/lib/typescript/module/e2e/smoke.test.d.ts.map +1 -0
  239. package/lib/typescript/module/package.json +1 -0
  240. package/lib/typescript/module/src/MarcusTextInputDecoratorViewNativeComponent.d.ts +63 -0
  241. package/lib/typescript/module/src/MarcusTextInputDecoratorViewNativeComponent.d.ts.map +1 -0
  242. package/lib/typescript/module/src/MarkdownTextInput.d.ts +22 -0
  243. package/lib/typescript/module/src/MarkdownTextInput.d.ts.map +1 -0
  244. package/lib/typescript/module/src/MarkdownTextInput.web.d.ts +41 -0
  245. package/lib/typescript/module/src/MarkdownTextInput.web.d.ts.map +1 -0
  246. package/lib/typescript/module/src/NativeMarcusModule.d.ts +7 -0
  247. package/lib/typescript/module/src/NativeMarcusModule.d.ts.map +1 -0
  248. package/lib/typescript/module/src/commonTypes.d.ts +10 -0
  249. package/lib/typescript/module/src/commonTypes.d.ts.map +1 -0
  250. package/lib/typescript/module/src/index.d.ts +5 -0
  251. package/lib/typescript/module/src/index.d.ts.map +1 -0
  252. package/lib/typescript/module/src/parser/index.d.ts +8 -0
  253. package/lib/typescript/module/src/parser/index.d.ts.map +1 -0
  254. package/lib/typescript/module/src/parser/micromark-extension-mentions.d.ts +8 -0
  255. package/lib/typescript/module/src/parser/micromark-extension-mentions.d.ts.map +1 -0
  256. package/lib/typescript/module/src/rangeUtils.d.ts +6 -0
  257. package/lib/typescript/module/src/rangeUtils.d.ts.map +1 -0
  258. package/lib/typescript/module/src/styleUtils.d.ts +8 -0
  259. package/lib/typescript/module/src/styleUtils.d.ts.map +1 -0
  260. package/lib/typescript/module/src/web/InputHistory.d.ts +24 -0
  261. package/lib/typescript/module/src/web/InputHistory.d.ts.map +1 -0
  262. package/lib/typescript/module/src/web/utils/blockLayout.d.ts +41 -0
  263. package/lib/typescript/module/src/web/utils/blockLayout.d.ts.map +1 -0
  264. package/lib/typescript/module/src/web/utils/blockUtils.d.ts +33 -0
  265. package/lib/typescript/module/src/web/utils/blockUtils.d.ts.map +1 -0
  266. package/lib/typescript/module/src/web/utils/browserUtils.d.ts +7 -0
  267. package/lib/typescript/module/src/web/utils/browserUtils.d.ts.map +1 -0
  268. package/lib/typescript/module/src/web/utils/cursorUtils.d.ts +12 -0
  269. package/lib/typescript/module/src/web/utils/cursorUtils.d.ts.map +1 -0
  270. package/lib/typescript/module/src/web/utils/inputUtils.d.ts +12 -0
  271. package/lib/typescript/module/src/web/utils/inputUtils.d.ts.map +1 -0
  272. package/lib/typescript/module/src/web/utils/measureUtils.d.ts +22 -0
  273. package/lib/typescript/module/src/web/utils/measureUtils.d.ts.map +1 -0
  274. package/lib/typescript/module/src/web/utils/parserUtils.d.ts +44 -0
  275. package/lib/typescript/module/src/web/utils/parserUtils.d.ts.map +1 -0
  276. package/lib/typescript/module/src/web/utils/treeUtils.d.ts +25 -0
  277. package/lib/typescript/module/src/web/utils/treeUtils.d.ts.map +1 -0
  278. package/lib/typescript/module/src/web/utils/webStyleUtils.d.ts +7 -0
  279. package/lib/typescript/module/src/web/utils/webStyleUtils.d.ts.map +1 -0
  280. package/package.json +167 -0
  281. package/react-native.config.js +10 -0
  282. package/src/MarcusTextInputDecoratorViewNativeComponent.ts +77 -0
  283. package/src/MarkdownTextInput.tsx +139 -0
  284. package/src/MarkdownTextInput.web.tsx +958 -0
  285. package/src/NativeMarcusModule.ts +8 -0
  286. package/src/commonTypes.ts +30 -0
  287. package/src/global.d.ts +1 -0
  288. package/src/index.tsx +4 -0
  289. package/src/parser/index.ts +556 -0
  290. package/src/parser/micromark-extension-mentions.ts +82 -0
  291. package/src/rangeUtils.ts +68 -0
  292. package/src/react-native-web.d.ts +1 -0
  293. package/src/styleUtils.ts +100 -0
  294. package/src/web/InputHistory.ts +137 -0
  295. package/src/web/MarkdownTextInput.css +72 -0
  296. package/src/web/utils/blockLayout.ts +163 -0
  297. package/src/web/utils/blockUtils.ts +245 -0
  298. package/src/web/utils/browserUtils.ts +41 -0
  299. package/src/web/utils/cursorUtils.ts +204 -0
  300. package/src/web/utils/inputUtils.ts +206 -0
  301. package/src/web/utils/measureUtils.ts +0 -0
  302. package/src/web/utils/parserUtils.ts +813 -0
  303. package/src/web/utils/treeUtils.ts +149 -0
  304. package/src/web/utils/webStyleUtils.ts +69 -0
@@ -0,0 +1,547 @@
1
+ "use strict";
2
+
3
+ import { addNodeToTree, createRootTreeNode } from "./treeUtils.js";
4
+ import { getCurrentCursorPosition, moveCursorToEnd, setCursorPosition } from "./cursorUtils.js";
5
+ import { addBlockPrefixGap, addLineLayout, addStyleToBlock, isMultilineMarkdownType } from "./blockUtils.js";
6
+ import { layoutBlocks } from "./blockLayout.js";
7
+ import { createTextMeasurer } from "./measureUtils.js";
8
+ import { sortRanges, ungroupRanges } from "../../rangeUtils.js";
9
+ function splitTextIntoLines(text) {
10
+ let lineStartIndex = 0;
11
+ const lines = text.split("\n").map(line => {
12
+ const lineObject = {
13
+ text: line,
14
+ start: lineStartIndex,
15
+ length: line.length,
16
+ markdownRanges: []
17
+ };
18
+ lineStartIndex += line.length + 1; // Adding 1 for the newline character
19
+ return lineObject;
20
+ });
21
+ return lines;
22
+ }
23
+
24
+ /**
25
+ * Merges lines with multiline markdown tags (like `pre`) into a single line.
26
+ * The main line will contain the text and all markdown ranges from the other lines.
27
+ */
28
+ function mergeLinesWithMultilineTags(lines, currentLine, range, correspondingLineIndexes) {
29
+ const mainLine = currentLine;
30
+ currentLine.markdownRanges.push(range);
31
+ correspondingLineIndexes.forEach(lineIndex => {
32
+ const otherLine = lines[lineIndex];
33
+ mainLine.text += `\n${otherLine.text}`;
34
+ mainLine.length += otherLine.length + 1;
35
+ mainLine.markdownRanges.push(...otherLine.markdownRanges);
36
+ });
37
+ if (correspondingLineIndexes.length > 0 && correspondingLineIndexes[0] !== undefined) {
38
+ lines.splice(correspondingLineIndexes[0], correspondingLineIndexes.length);
39
+ }
40
+ }
41
+
42
+ /**
43
+ * Splits a markdown range that spans multiple lines into separate lines.
44
+ */
45
+ function splitRangeIntoSeparateLines(lines, currentLine, range, correspondingLineIndexes) {
46
+ const mainLineRangeLength = currentLine.start + currentLine.length - range.start;
47
+ // A range starting exactly at the newline has nothing on this line. Pushing the empty portion
48
+ // anyway made the builder render an empty span, and an empty span is given a `<br>` to keep the
49
+ // line height -- a line break in the text that the user never typed.
50
+ if (mainLineRangeLength > 0) {
51
+ currentLine.markdownRanges.push({
52
+ ...range,
53
+ length: mainLineRangeLength
54
+ });
55
+ }
56
+ let rangeLength = range.length - mainLineRangeLength;
57
+ correspondingLineIndexes.forEach(lineIndex => {
58
+ const otherLine = lines[lineIndex];
59
+ let currentLength = otherLine.length;
60
+ if (rangeLength <= currentLength) {
61
+ currentLength = rangeLength - 1;
62
+ }
63
+ if (currentLength > 0) {
64
+ lines[lineIndex]?.markdownRanges.push({
65
+ ...range,
66
+ start: otherLine.start,
67
+ length: currentLength
68
+ });
69
+ }
70
+ rangeLength -= currentLength;
71
+ });
72
+ }
73
+
74
+ /**
75
+ * For singleline markdown types, the function splits markdown ranges that spread beyond the line length into separate lines.
76
+ * For multiline markdown types (like `pre`), it merges them and corresponding text into one line.
77
+ */
78
+ function normalizeLines(lines, ranges) {
79
+ const mergedLines = [...lines];
80
+ const lineIndexes = mergedLines.map((_line, index) => index);
81
+ ranges.forEach(range => {
82
+ const beginLineIndex = mergedLines.findLastIndex(line => line.start <= range.start);
83
+ const endLineIndex = mergedLines.findIndex(line => line.start + line.length >= range.start + range.length);
84
+ const correspondingLineIndexes = lineIndexes.slice(beginLineIndex, endLineIndex + 1);
85
+ if (correspondingLineIndexes.length > 0) {
86
+ const mainLineIndex = correspondingLineIndexes[0];
87
+ const mainLine = mergedLines[mainLineIndex];
88
+ const otherLineIndexes = correspondingLineIndexes.slice(1);
89
+ if (isMultilineMarkdownType(range.type)) {
90
+ mergeLinesWithMultilineTags(mergedLines, mainLine, range, otherLineIndexes);
91
+ } else if (otherLineIndexes.length > 0) {
92
+ splitRangeIntoSeparateLines(mergedLines, mainLine, range, otherLineIndexes);
93
+ } else {
94
+ mainLine.markdownRanges.push(range);
95
+ }
96
+ }
97
+ });
98
+ return mergedLines;
99
+ }
100
+
101
+ /** Adds a value prop to the element and appends the value to the parent node element */
102
+ function appendValueToElement(element, parentTreeNode, value) {
103
+ const targetElement = element;
104
+ const parentNode = parentTreeNode;
105
+ targetElement.value = value;
106
+ parentNode.element.value = (parentNode.element.value || "") + value;
107
+ }
108
+ function appendNode(element, parentTreeNode, type, length, start = null) {
109
+ const node = addNodeToTree(element, parentTreeNode, type, length, start);
110
+ parentTreeNode.element.appendChild(element);
111
+ return node;
112
+ }
113
+ function addBrElement(node) {
114
+ const span = document.createElement("span");
115
+ span.setAttribute("data-type", "br");
116
+ appendValueToElement(span, node, "\n");
117
+ const spanNode = appendNode(span, node, "br", 1);
118
+ appendNode(document.createElement("br"), spanNode, "br", 1);
119
+ return spanNode;
120
+ }
121
+ function addTextToElement(node, text, isMultiline = true) {
122
+ const lines = text.split("\n");
123
+ lines.forEach((line, index) => {
124
+ if (line !== "") {
125
+ const span = document.createElement("span");
126
+ appendValueToElement(span, node, line);
127
+ span.setAttribute("data-type", "text");
128
+ span.appendChild(document.createTextNode(line));
129
+ appendNode(span, node, "text", line.length);
130
+ const parentType = span.parentElement?.dataset.type;
131
+ if (!isMultiline && parentType && ["pre", "code", "mention-here", "mention-user", "mention-report"].includes(parentType)) {
132
+ // this is a fix to background colors being shifted downwards in a singleline input
133
+ addStyleToBlock(span, "text", {}, false);
134
+ }
135
+ }
136
+
137
+ // Only add BR elements for multiline inputs or when there are actual line breaks
138
+ if (isMultiline && (index < lines.length - 1 || index === 0 && line === "")) {
139
+ addBrElement(node);
140
+ }
141
+ });
142
+ }
143
+ function addParagraph(node, text, length, layout, markdownStyle, disableInlineStyles = false) {
144
+ const p = document.createElement("p");
145
+ p.setAttribute("data-type", "line");
146
+ if (!disableInlineStyles) {
147
+ addLineLayout(p, layout, markdownStyle);
148
+ }
149
+ const pNode = appendNode(p, node, "line", length);
150
+ if (text === "") {
151
+ // If the line is empty, we still need to add a br element to keep the line height
152
+ addBrElement(pNode);
153
+ } else if (text) {
154
+ addTextToElement(pNode, text);
155
+ }
156
+ return pNode;
157
+ }
158
+
159
+ /**
160
+ * `syntax`, `block-prefix` and `emoji` decorate whatever they sit in, so where ranges cover exactly
161
+ * the same text those three have to come last: the container, then the `block-prefix` holding its
162
+ * marker, then the `syntax` of the marker itself. Typing a bare `>` produces all three over one
163
+ * character, and the parser emits them in precisely the wrong order -- `flushLine` hands the marker
164
+ * over before the container it belongs to, because that is the pairing the native formatters read.
165
+ * Inverting that is the whole job of `getTagPriority`.
166
+ *
167
+ * Every other tie is already right. A range is emitted when its construct opens, so emission order
168
+ * is containment order, and a stable sort leaves it alone. That is also the only thing that *can*
169
+ * order two containers of the same size: `> - a` and `- > a` are the same pair of containers over
170
+ * the same line, nested opposite ways, and no table of types can say which.
171
+ *
172
+ * So the one thing worth checking is a decoration that sorted ahead of something it belongs to --
173
+ * which is what a container type missing from `getTagPriority` produces. The builder then renders
174
+ * that text once per range, silently, multiplying with every keystroke. Nothing about that failure
175
+ * points at the missing table entry, so say it out loud instead.
176
+ */
177
+ const INNERMOST_TYPES = new Set(["block-prefix", "syntax", "emoji"]);
178
+ function reportAmbiguousNesting(ranges) {
179
+ for (let i = 1; i < ranges.length; i++) {
180
+ const previous = ranges[i - 1];
181
+ const current = ranges[i];
182
+ if (previous.start === current.start && previous.length === current.length && INNERMOST_TYPES.has(previous.type) && !INNERMOST_TYPES.has(current.type)) {
183
+ // eslint-disable-next-line no-console
184
+ console.error(`[react-native-marcus] \`${previous.type}\` sorts ahead of \`${current.type}\` over the same text, so the marker ends up outside what it belongs to and renders once per range. Give \`${current.type}\` a higher priority in src/rangeUtils.ts.`);
185
+ }
186
+ }
187
+ }
188
+
189
+ /**
190
+ * Builds one `<p data-type="line">` under `rootNode`.
191
+ *
192
+ * Lines are independent: nothing carries across from the previous one, which is what lets an update
193
+ * rebuild a single line and leave the rest of the document alone.
194
+ */
195
+ function addLine(rootNode, line, textLength, hasRanges, isMultiline, markdownStyle, disableInlineStyles) {
196
+ if (!hasRanges) {
197
+ return addParagraph(rootNode, line.text, line.length, line.layout, markdownStyle, disableInlineStyles);
198
+ }
199
+ const lineNode = addParagraph(rootNode, null, line.length, line.layout, markdownStyle, disableInlineStyles);
200
+ let currentParentNode = lineNode;
201
+ if (line.markdownRanges.length === 0) {
202
+ addTextToElement(currentParentNode, line.text, isMultiline);
203
+ }
204
+ let lastRangeEndIndex = line.start;
205
+ const lineMarkdownRanges = [...line.markdownRanges];
206
+ // go through all markdown ranges in the line
207
+ while (lineMarkdownRanges.length > 0) {
208
+ const range = lineMarkdownRanges.shift();
209
+ if (!range) {
210
+ break;
211
+ }
212
+ const endOfCurrentRange = range.start + range.length;
213
+ const nextRangeStartIndex = lineMarkdownRanges.length > 0 && !!lineMarkdownRanges[0] ? lineMarkdownRanges[0].start || 0 : textLength;
214
+
215
+ // add text before the markdown range. Ranges that start behind the cursor are already
216
+ // rendered; without the guard `substring` would swap its arguments and emit that text again.
217
+ const textBeforeRange = range.start > lastRangeEndIndex ? line.text.substring(lastRangeEndIndex - line.start, range.start - line.start) : "";
218
+ if (textBeforeRange) {
219
+ addTextToElement(currentParentNode, textBeforeRange, isMultiline);
220
+ }
221
+
222
+ // create markdown span element
223
+ const span = document.createElement("span");
224
+ span.setAttribute("data-type", range.type);
225
+ const spanNode = appendNode(span, currentParentNode, range.type, range.length, range.start);
226
+
227
+ // Styled once it is in the tree, not before: a heading's size depends on how many heading
228
+ // levels enclose it, and an element with no parent looks like the outermost one.
229
+ if (!disableInlineStyles) {
230
+ addStyleToBlock(span, range.type, markdownStyle, isMultiline);
231
+ if (range.type === "block-prefix") {
232
+ addBlockPrefixGap(span, line.layout?.gaps.get(range.start));
233
+ }
234
+ }
235
+ if (lineMarkdownRanges.length > 0 && nextRangeStartIndex < endOfCurrentRange && range.type !== "syntax") {
236
+ // tag nesting
237
+ currentParentNode = spanNode;
238
+ lastRangeEndIndex = range.start;
239
+ } else {
240
+ // adding markdown tag
241
+ addTextToElement(spanNode, line.text.substring(range.start - line.start, endOfCurrentRange - line.start), isMultiline);
242
+ currentParentNode.element.value = (currentParentNode.element.value || "") + (spanNode.element.value || "");
243
+ lastRangeEndIndex = endOfCurrentRange;
244
+ // tag unnesting and adding text after the tag
245
+ while (currentParentNode.parentNode !== null && nextRangeStartIndex >= currentParentNode.start + currentParentNode.length) {
246
+ const parentEndIndex = currentParentNode.start + currentParentNode.length;
247
+ const textAfterRange = parentEndIndex > lastRangeEndIndex ? line.text.substring(lastRangeEndIndex - line.start, parentEndIndex - line.start) : "";
248
+ if (textAfterRange) {
249
+ addTextToElement(currentParentNode, textAfterRange, isMultiline);
250
+ }
251
+ // Never backwards: an enclosing range can end before the text already consumed inside it
252
+ // -- a list whose item holds a code block runs to the end of its marker line while the
253
+ // block inside it runs on for several more. Letting it rewind made the paragraph re-emit
254
+ // everything from there, so the line rendered twice.
255
+ lastRangeEndIndex = parentEndIndex > lastRangeEndIndex ? parentEndIndex : lastRangeEndIndex;
256
+ // A line's content never escapes its own paragraph. Without this the walk could reach the
257
+ // root, and every later range on the line was appended there instead -- a stray top-level
258
+ // element between the paragraphs, which shifts every `data-id` after it and leaves the
259
+ // line it belonged to rendered in two places.
260
+ if (currentParentNode === lineNode) {
261
+ break;
262
+ }
263
+ if (currentParentNode.parentNode.type !== "root") {
264
+ currentParentNode.parentNode.element.value = currentParentNode.element.value || "";
265
+ }
266
+ currentParentNode = currentParentNode.parentNode || rootNode;
267
+ }
268
+ }
269
+ }
270
+ return lineNode;
271
+ }
272
+
273
+ /** Splits the text into lines and hands each the markdown ranges that fall inside it. */
274
+ function prepareLines(text, ranges, markdownStyle, measure) {
275
+ const lines = splitTextIntoLines(text);
276
+ if (ranges.length === 0) {
277
+ return lines;
278
+ }
279
+
280
+ // Before anything reorders them: the block walk reads the ranges in the order the parser emits
281
+ // them -- each marker immediately before the container it belongs to -- and `sortRanges` sorts
282
+ // that order away in place.
283
+ const layouts = layoutBlocks(text, ranges, markdownStyle, measure);
284
+
285
+ // Sort all ranges by start position, length, and by tag hierarchy so the styles and text are applied in correct order
286
+ const sortedRanges = sortRanges(ranges);
287
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
288
+ reportAmbiguousNesting(sortedRanges);
289
+ }
290
+ const normalized = normalizeLines(lines, ungroupRanges(sortedRanges));
291
+
292
+ // Ranges reach a line in document order, but a range spanning several lines hands its tail to
293
+ // those lines as it is processed -- ahead of ranges that start later on the same line and should
294
+ // have come first. `1. *l\nd**` puts an italic that opened on line 1 in front of the list its
295
+ // second half sits inside, and the builder then nests the list *within* the italic and renders
296
+ // the overlap twice. Restoring the order per line costs nothing on lines that were already
297
+ // sorted, which is nearly all of them.
298
+ normalized.forEach(paragraph => {
299
+ const line = paragraph;
300
+ sortRanges(line.markdownRanges);
301
+ line.layout = layouts.get(line.start);
302
+ });
303
+ return normalized;
304
+ }
305
+
306
+ /** Builds HTML DOM structure based on passed text and markdown ranges */
307
+ function parseRangesToHTMLNodes(text, ranges, isMultiline = true, markdownStyle = {}, disableInlineStyles = false, measure = createTextMeasurer(null)) {
308
+ const rootElement = document.createElement("span");
309
+ const textLength = text.length;
310
+ const rootNode = createRootTreeNode(rootElement, textLength);
311
+
312
+ // Built line by line, exactly as an update builds the lines it has to replace, so the two agree
313
+ // by construction and each line sits at the offset the text gives it rather than at wherever the
314
+ // line before it happened to end.
315
+ prepareLines(text, ranges, markdownStyle, measure).forEach((line, index) => {
316
+ const node = buildLine(line, index, textLength, ranges.length > 0, isMultiline, markdownStyle, disableInlineStyles);
317
+ node.parentNode = rootNode;
318
+ rootNode.childNodes.push(node);
319
+ rootElement.appendChild(node.element);
320
+ });
321
+ return {
322
+ dom: rootElement,
323
+ tree: rootNode
324
+ };
325
+ }
326
+
327
+ /**
328
+ * A line as it was last rendered: what it was built from, the markup it produced, and its subtree.
329
+ */
330
+
331
+ /**
332
+ * Everything a line's markup depends on, as a string.
333
+ *
334
+ * A line is rendered from its own text and the ranges falling inside it, and nothing else -- so two
335
+ * lines with equal signatures render identically and the second one need not be built at all. Range
336
+ * offsets go in relative to the line, so a line that only moved still matches.
337
+ */
338
+ function signatureOf(line, hasRanges) {
339
+ let signature = hasRanges ? "r" : "-";
340
+ signature += line.text;
341
+ line.markdownRanges.forEach(range => {
342
+ signature += `\u0000${range.start - line.start},${range.length},${range.type},${range.depth ?? ""}`;
343
+ });
344
+
345
+ // The layout is not derived from this line alone -- a continuation line indents past a marker
346
+ // that belongs to the line that opened the block, and every width comes out of the font the
347
+ // input happens to be rendering in. Both reach the line only through these numbers, so they are
348
+ // what the signature has to compare.
349
+ const layout = line.layout;
350
+ if (layout) {
351
+ signature += `\u0000${layout.firstLineIndent},${layout.indent},${layout.ribbons.join(":")}`;
352
+ layout.gaps.forEach((gap, start) => {
353
+ signature += `,${start - line.start}:${gap}`;
354
+ });
355
+ }
356
+ return signature;
357
+ }
358
+
359
+ /** Moves a subtree along the text by `delta`, for a line that shifted without changing. */
360
+ function shiftSubtree(node, delta) {
361
+ const target = node;
362
+ target.start += delta;
363
+ target.childNodes.forEach(child => shiftSubtree(child, delta));
364
+ }
365
+
366
+ /** Renumbers a subtree, for a line whose index changed because lines were added or removed above. */
367
+ function restampSubtree(node, orderIndex) {
368
+ const target = node;
369
+ target.orderIndex = orderIndex;
370
+ target.element.setAttribute("data-id", orderIndex);
371
+ target.childNodes.forEach((child, index) => restampSubtree(child, `${orderIndex},${index}`));
372
+ }
373
+
374
+ /**
375
+ * Grows every node to at least cover its children.
376
+ *
377
+ * A container range can be shorter than what the builder puts inside it -- a list item's own range
378
+ * stops at the end of its marker line, while a fenced code block opened there runs on for several
379
+ * more. The tree is what maps a text offset onto a node, so a parent that does not reach the end of
380
+ * its own children leaves that overhang mapping to nothing and the caret cannot be placed in it.
381
+ *
382
+ * It runs once the line is built, never during: a node's length decides where its next sibling
383
+ * starts and how far the builder thinks it has got, so growing one mid-build changes the markup.
384
+ */
385
+ function coverChildren(node) {
386
+ const target = node;
387
+ let end = target.start + target.length;
388
+ target.childNodes.forEach(child => {
389
+ coverChildren(child);
390
+ const childEnd = child.start + child.length;
391
+ if (childEnd > end) {
392
+ end = childEnd;
393
+ }
394
+ });
395
+ target.length = end - target.start;
396
+ }
397
+
398
+ /** Builds one line on its own, then places it at the offset and index it occupies in the document. */
399
+ function buildLine(line, index, textLength, hasRanges, isMultiline, markdownStyle, disableInlineStyles = false) {
400
+ // The scratch root carries the line's offset, so the subtree comes out with the absolute `start`
401
+ // values the builder compares against range offsets -- the same ones it would get if the whole
402
+ // document had been built in one pass.
403
+ const scratch = createRootTreeNode(document.createElement("span"), line.length, line.start);
404
+ const node = addLine(scratch, line, textLength, hasRanges, isMultiline, markdownStyle, disableInlineStyles);
405
+ coverChildren(node);
406
+ restampSubtree(node, `${index}`);
407
+ return node;
408
+ }
409
+
410
+ /**
411
+ * A cached line can be reused only if it would be rebuilt identically *and* the live element is
412
+ * still exactly what was put there.
413
+ *
414
+ * The identity check matters as much as the signature: the browser edits the input directly as the
415
+ * user types, and it is free to merge, split or wrap the top-level elements. Requiring the live
416
+ * node to be the very one this entry rendered means anything the browser introduced falls outside
417
+ * the reusable prefix and suffix, and so lands in the run that gets replaced.
418
+ */
419
+ function canReuseLine(cached, signature, liveNode) {
420
+ return !!cached && cached.signature === signature && liveNode === cached.node.element && liveNode.outerHTML === cached.html;
421
+ }
422
+
423
+ /**
424
+ * Renders `lines` into the input, building only the ones that changed.
425
+ *
426
+ * Rebuilding every line and then diffing meant the expensive half of an update happened whatever
427
+ * the edit was -- construction is the dominant cost, not applying the result. Matching lines are
428
+ * skipped from both ends by signature, so a keystroke builds one line and the rest of the document
429
+ * keeps the elements and the subtrees it already had. Lines after the edit are shifted along the
430
+ * text, and renumbered if lines were added or removed above them; both are cheap walks that touch
431
+ * no element beyond a `data-id`.
432
+ */
433
+ function reconcileLines(targetElement, lines, textLength, hasRanges, isMultiline, markdownStyle, shouldForceDOMUpdate) {
434
+ const signatures = lines.map(line => signatureOf(line, hasRanges));
435
+ const cache = targetElement.lineCache;
436
+ const previous = !shouldForceDOMUpdate && cache && cache.markdownStyle === markdownStyle && cache.isMultiline === isMultiline ? cache.lines : [];
437
+ const live = Array.from(targetElement.childNodes);
438
+ let head = 0;
439
+ while (head < lines.length && head < previous.length && canReuseLine(previous[head], signatures[head], live[head])) {
440
+ head += 1;
441
+ }
442
+ let tail = lines.length;
443
+ let previousTail = previous.length;
444
+ let liveTail = live.length;
445
+ while (tail > head && previousTail > head && liveTail > head && canReuseLine(previous[previousTail - 1], signatures[tail - 1], live[liveTail - 1])) {
446
+ tail -= 1;
447
+ previousTail -= 1;
448
+ liveTail -= 1;
449
+ }
450
+ const fresh = [];
451
+ for (let i = head; i < tail; i += 1) {
452
+ fresh.push(buildLine(lines[i], i, textLength, hasRanges, isMultiline, markdownStyle));
453
+ }
454
+
455
+ // Read before removing anything: this is the first live node of the matching tail, which stays.
456
+ const anchor = live[liveTail] ?? null;
457
+ for (let i = head; i < liveTail; i += 1) {
458
+ live[i]?.remove();
459
+ }
460
+ if (fresh.length > 0) {
461
+ const fragment = document.createDocumentFragment();
462
+ fresh.forEach(node => fragment.appendChild(node.element));
463
+ targetElement.insertBefore(fragment, anchor);
464
+ }
465
+ const rootNode = createRootTreeNode(targetElement, textLength);
466
+ const nextCache = [];
467
+ for (let i = 0; i < lines.length; i += 1) {
468
+ const line = lines[i];
469
+ let node;
470
+ let html;
471
+ if (i < head) {
472
+ const cached = previous[i];
473
+ node = cached.node;
474
+ html = cached.html;
475
+ } else if (i < tail) {
476
+ node = fresh[i - head];
477
+ html = node.element.outerHTML;
478
+ } else {
479
+ const cached = previous[previousTail + (i - tail)];
480
+ node = cached.node;
481
+ const delta = line.start - node.start;
482
+ if (delta !== 0) {
483
+ shiftSubtree(node, delta);
484
+ }
485
+ if (node.orderIndex !== `${i}`) {
486
+ restampSubtree(node, `${i}`);
487
+ html = node.element.outerHTML;
488
+ } else {
489
+ html = cached.html;
490
+ }
491
+ }
492
+ node.parentNode = rootNode;
493
+ rootNode.childNodes.push(node);
494
+ nextCache.push({
495
+ signature: signatures[i],
496
+ html,
497
+ node
498
+ });
499
+ }
500
+ targetElement.lineCache = {
501
+ markdownStyle,
502
+ isMultiline,
503
+ lines: nextCache
504
+ };
505
+ return rootNode;
506
+ }
507
+ function moveCursor(isFocused, alwaysMoveCursorToTheEnd, cursorPosition, target, shouldScrollIntoView = false) {
508
+ if (!isFocused) {
509
+ return;
510
+ }
511
+ if (alwaysMoveCursorToTheEnd || cursorPosition === null) {
512
+ moveCursorToEnd(target);
513
+ } else if (cursorPosition !== null) {
514
+ setCursorPosition(target, cursorPosition, null, shouldScrollIntoView);
515
+ }
516
+ }
517
+ function updateInputStructure(parserFunction, target, text, cursorPositionIndex, isMultiline = true, markdownStyle = {}, alwaysMoveCursorToTheEnd = false, shouldForceDOMUpdate = false, shouldScrollIntoView = false) {
518
+ const targetElement = target;
519
+
520
+ // in case the cursorPositionIndex is larger than text length, cursorPosition will be null, i.e: move the caret to the end
521
+ let cursorPosition = cursorPositionIndex !== null && cursorPositionIndex <= text.length ? cursorPositionIndex : null;
522
+ const isFocused = document.activeElement === target;
523
+ if (isFocused && cursorPositionIndex === null) {
524
+ const selection = getCurrentCursorPosition(target);
525
+ cursorPosition = selection ? selection.start : null;
526
+ }
527
+ const markdownRanges = parserFunction(text);
528
+ if (!text || targetElement.innerHTML === "<br>" || targetElement && targetElement.innerHTML === "\n") {
529
+ targetElement.innerHTML = "";
530
+ targetElement.innerText = "";
531
+ }
532
+
533
+ // We don't want to parse text with single '\n', because contentEditable represents it as invisible <br />
534
+ if (text) {
535
+ targetElement.tree = reconcileLines(targetElement, prepareLines(text, markdownRanges, markdownStyle, createTextMeasurer(targetElement)), text.length, markdownRanges.length > 0, isMultiline, markdownStyle, shouldForceDOMUpdate);
536
+ moveCursor(isFocused, alwaysMoveCursorToTheEnd, cursorPosition, targetElement, shouldScrollIntoView);
537
+ } else {
538
+ targetElement.tree = createRootTreeNode(targetElement);
539
+ targetElement.lineCache = undefined;
540
+ }
541
+ return {
542
+ text,
543
+ cursorPosition: cursorPosition || 0
544
+ };
545
+ }
546
+ export { updateInputStructure, parseRangesToHTMLNodes, normalizeLines };
547
+ //# sourceMappingURL=parserUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["addNodeToTree","createRootTreeNode","getCurrentCursorPosition","moveCursorToEnd","setCursorPosition","addBlockPrefixGap","addLineLayout","addStyleToBlock","isMultilineMarkdownType","layoutBlocks","createTextMeasurer","sortRanges","ungroupRanges","splitTextIntoLines","text","lineStartIndex","lines","split","map","line","lineObject","start","length","markdownRanges","mergeLinesWithMultilineTags","currentLine","range","correspondingLineIndexes","mainLine","push","forEach","lineIndex","otherLine","undefined","splice","splitRangeIntoSeparateLines","mainLineRangeLength","rangeLength","currentLength","normalizeLines","ranges","mergedLines","lineIndexes","_line","index","beginLineIndex","findLastIndex","endLineIndex","findIndex","slice","mainLineIndex","otherLineIndexes","type","appendValueToElement","element","parentTreeNode","value","targetElement","parentNode","appendNode","node","appendChild","addBrElement","span","document","createElement","setAttribute","spanNode","addTextToElement","isMultiline","createTextNode","parentType","parentElement","dataset","includes","addParagraph","layout","markdownStyle","disableInlineStyles","p","pNode","INNERMOST_TYPES","Set","reportAmbiguousNesting","i","previous","current","has","console","error","addLine","rootNode","textLength","hasRanges","lineNode","currentParentNode","lastRangeEndIndex","lineMarkdownRanges","shift","endOfCurrentRange","nextRangeStartIndex","textBeforeRange","substring","gaps","get","parentEndIndex","textAfterRange","prepareLines","measure","layouts","sortedRanges","__DEV__","normalized","paragraph","parseRangesToHTMLNodes","rootElement","buildLine","childNodes","dom","tree","signatureOf","signature","depth","firstLineIndent","indent","ribbons","join","gap","shiftSubtree","delta","target","child","restampSubtree","orderIndex","coverChildren","end","childEnd","scratch","canReuseLine","cached","liveNode","outerHTML","html","reconcileLines","shouldForceDOMUpdate","signatures","cache","lineCache","live","Array","from","head","tail","previousTail","liveTail","fresh","anchor","remove","fragment","createDocumentFragment","insertBefore","nextCache","moveCursor","isFocused","alwaysMoveCursorToTheEnd","cursorPosition","shouldScrollIntoView","updateInputStructure","parserFunction","cursorPositionIndex","activeElement","selection","innerHTML","innerText"],"sourceRoot":"../../../../src","sources":["web/utils/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