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,210 @@
1
+ "use strict";
2
+
3
+ import { toNumber } from "./blockLayout.js";
4
+ /**
5
+ * Assigns CSS properties, skipping the ones the style does not define.
6
+ *
7
+ * Lengths arrive here already carrying their unit -- `processMarkdownStyle` runs the style through
8
+ * react-native-web's compiler before it reaches the builder -- but `parseRangesToHTMLNodes` can be
9
+ * called with a plain object that has not, and `CSSStyleDeclaration` silently drops a bare number.
10
+ * Adding the unit here means both spellings render the same.
11
+ */
12
+ function applyStyle(node, styles) {
13
+ const target = node;
14
+ Object.entries(styles).forEach(([property, value]) => {
15
+ if (value === undefined || value === null || value === "") {
16
+ return;
17
+ }
18
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
+ ;
20
+ target.style[property] = typeof value === "number" ? `${value}px` : value;
21
+ });
22
+ }
23
+
24
+ /**
25
+ * Applies the layout the block walk computed for one line.
26
+ *
27
+ * Everything a container contributes lands here rather than on the container's own span: its gutter
28
+ * is part of the paragraph's indent, and its ribbon is painted behind the whole paragraph. That is
29
+ * how the native formatters do it too, and on the web it is the only placement that works -- a
30
+ * container's span begins before the markers of the containers outside it, so a border drawn on it
31
+ * would sit in front of a bullet that is meant to precede it, and a gutter set on it would open
32
+ * before that bullet rather than after.
33
+ *
34
+ * `padding-left` holds every line of the paragraph at the indent, and the negative `text-indent`
35
+ * pulls the first one back to where its own marker starts -- `firstLineHeadIndent` and `headIndent`,
36
+ * spelled in CSS. A line that wraps, or a line continuing the block with no marker of its own, then
37
+ * lines up with the text above it instead of with the marker.
38
+ */
39
+ function addLineLayout(node, layout, markdownStyle) {
40
+ applyStyle(node, {
41
+ margin: "0",
42
+ padding: "0"
43
+ });
44
+ if (!layout) {
45
+ return;
46
+ }
47
+ if (layout.indent > 0) {
48
+ applyStyle(node, {
49
+ paddingLeft: `${layout.indent}px`,
50
+ textIndent: `${layout.firstLineIndent - layout.indent}px`
51
+ });
52
+ }
53
+ const width = toNumber(markdownStyle.blockquote?.borderWidth);
54
+ if (layout.ribbons.length === 0 || width <= 0) {
55
+ return;
56
+ }
57
+
58
+ // One background layer per ribbon, each a solid bar of its own. They are painted on the paragraph
59
+ // rather than on any span so that they run its full height -- a quote that wraps gets one
60
+ // unbroken bar, exactly as `MarkdownTextLayoutFragment` draws it over the whole fragment.
61
+ const color = markdownStyle.blockquote?.borderColor || "transparent";
62
+ applyStyle(node, {
63
+ backgroundImage: layout.ribbons.map(() => `linear-gradient(${color}, ${color})`).join(", "),
64
+ backgroundPosition: layout.ribbons.map(x => `${x}px 0`).join(", "),
65
+ backgroundSize: layout.ribbons.map(() => `${width}px 100%`).join(", "),
66
+ backgroundRepeat: "no-repeat"
67
+ });
68
+ }
69
+
70
+ /**
71
+ * Opens the space a marker holds for the container that follows it.
72
+ *
73
+ * `MarkdownFormatter` kerns the marker's last character; the effect is the same, and it is what
74
+ * puts a nested list's indent between the quote's `>` and the bullet rather than in front of both.
75
+ */
76
+ function addBlockPrefixGap(node, gap) {
77
+ if (gap) {
78
+ node.style.marginRight = `${gap}px`;
79
+ }
80
+ }
81
+ function addStyleToBlock(targetElement, type, markdownStyle, isMultiline = true) {
82
+ const node = targetElement;
83
+ switch (type) {
84
+ case "syntax":
85
+ applyStyle(node, {
86
+ color: markdownStyle.syntax?.color
87
+ });
88
+ break;
89
+ case "bold":
90
+ node.style.fontWeight = "bold";
91
+ break;
92
+ case "italic":
93
+ node.style.fontStyle = "italic";
94
+ break;
95
+ case "strikethrough":
96
+ node.style.textDecoration = "line-through";
97
+ break;
98
+ case "emoji":
99
+ applyStyle(node, {
100
+ fontFamily: markdownStyle.emoji?.fontFamily,
101
+ fontSize: markdownStyle.emoji?.fontSize,
102
+ // Native re-centres a run whose font changed against the line height; the browser has no
103
+ // equivalent, and an emoji font left on the alphabetic baseline sits low.
104
+ verticalAlign: "middle"
105
+ });
106
+ break;
107
+ case "mention-here":
108
+ addMentionStyle(node, markdownStyle.mentionHere);
109
+ break;
110
+ case "mention-user":
111
+ addMentionStyle(node, markdownStyle.mentionUser);
112
+ break;
113
+ case "mention-report":
114
+ addMentionStyle(node, markdownStyle.mentionReport);
115
+ break;
116
+ case "link":
117
+ applyStyle(node, {
118
+ color: markdownStyle.link?.color,
119
+ textDecoration: "underline"
120
+ });
121
+ break;
122
+ // Both carry a font, a colour and a background, and nothing else: native draws no border, no
123
+ // corner radius and no padding around either, so neither does this.
124
+ case "code":
125
+ applyStyle(node, {
126
+ fontFamily: markdownStyle.code?.fontFamily,
127
+ fontSize: markdownStyle.code?.fontSize,
128
+ color: markdownStyle.code?.color,
129
+ backgroundColor: markdownStyle.code?.backgroundColor
130
+ });
131
+ break;
132
+ case "pre":
133
+ applyStyle(node, {
134
+ fontFamily: markdownStyle.pre?.fontFamily,
135
+ fontSize: markdownStyle.pre?.fontSize,
136
+ color: markdownStyle.pre?.color,
137
+ backgroundColor: markdownStyle.pre?.backgroundColor
138
+ });
139
+ break;
140
+ // Block containers hold no box of their own: their gutters and ribbons belong to the
141
+ // paragraph, in `addLineLayout`. All that is left is letting a long unbroken word inside one
142
+ // break rather than push the line past the input's edge.
143
+ case "blockquote":
144
+ case "list-ordered":
145
+ case "list-unordered":
146
+ applyStyle(node, {
147
+ overflowWrap: "anywhere"
148
+ });
149
+ break;
150
+ case "heading":
151
+ addHeadingStyle(node, markdownStyle);
152
+ break;
153
+ case "text":
154
+ if (!isMultiline && targetElement.parentElement?.style) {
155
+ // Move text background styles from parent to the text node
156
+ const parentElement = targetElement.parentElement;
157
+ node.style.cssText = parentElement.style.cssText;
158
+ parentElement.style.cssText = "";
159
+ }
160
+ break;
161
+ default:
162
+ break;
163
+ }
164
+ }
165
+ function addMentionStyle(node, style) {
166
+ applyStyle(node, {
167
+ color: style?.color,
168
+ backgroundColor: style?.backgroundColor,
169
+ borderRadius: style?.borderRadius
170
+ });
171
+ }
172
+
173
+ /**
174
+ * Sizes a heading the way native does: level N is the base size scaled N-1 times.
175
+ *
176
+ * The level does not reach here -- `ungroupRanges` turns it into one nested span per level -- so
177
+ * the scaling is expressed in `em` and compounds down the nesting to the same number. This runs
178
+ * once the span is in the tree, which is what lets it tell an inner level from the outermost one.
179
+ */
180
+ function addHeadingStyle(node, markdownStyle) {
181
+ const nested = isChildOfMarkdownElement(node, "heading");
182
+ const scale = markdownStyle.heading?.scale;
183
+ applyStyle(node, {
184
+ fontWeight: "bold",
185
+ fontSize: nested ? `${scale === undefined ? 1 : scale}em` : markdownStyle.heading?.fontSize
186
+ });
187
+ }
188
+ const MULTILINE_MARKDOWN_TYPES = ["codeblock"];
189
+ function isMultilineMarkdownType(type) {
190
+ return MULTILINE_MARKDOWN_TYPES.includes(type);
191
+ }
192
+ function isDescendantOfMarkdownElement(node, predicate) {
193
+ let currentNode = node.parentNode;
194
+ while (currentNode && currentNode?.contentEditable !== "true") {
195
+ const elementType = currentNode.getAttribute?.("data-type");
196
+ if (predicate(elementType)) {
197
+ return true;
198
+ }
199
+ currentNode = currentNode.parentNode;
200
+ }
201
+ return false;
202
+ }
203
+ function isChildOfMarkdownElement(node, elementType) {
204
+ return isDescendantOfMarkdownElement(node, type => type === elementType);
205
+ }
206
+ function isChildOfMultilineMarkdownElement(node) {
207
+ return isDescendantOfMarkdownElement(node, type => MULTILINE_MARKDOWN_TYPES.includes(type));
208
+ }
209
+ export { addStyleToBlock, addLineLayout, addBlockPrefixGap, isMultilineMarkdownType, isChildOfMarkdownElement, isChildOfMultilineMarkdownElement, MULTILINE_MARKDOWN_TYPES };
210
+ //# sourceMappingURL=blockUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["toNumber","applyStyle","node","styles","target","Object","entries","forEach","property","value","undefined","style","addLineLayout","layout","markdownStyle","margin","padding","indent","paddingLeft","textIndent","firstLineIndent","width","blockquote","borderWidth","ribbons","length","color","borderColor","backgroundImage","map","join","backgroundPosition","x","backgroundSize","backgroundRepeat","addBlockPrefixGap","gap","marginRight","addStyleToBlock","targetElement","type","isMultiline","syntax","fontWeight","fontStyle","textDecoration","fontFamily","emoji","fontSize","verticalAlign","addMentionStyle","mentionHere","mentionUser","mentionReport","link","code","backgroundColor","pre","overflowWrap","addHeadingStyle","parentElement","cssText","borderRadius","nested","isChildOfMarkdownElement","scale","heading","MULTILINE_MARKDOWN_TYPES","isMultilineMarkdownType","includes","isDescendantOfMarkdownElement","predicate","currentNode","parentNode","contentEditable","elementType","getAttribute","isChildOfMultilineMarkdownElement"],"sourceRoot":"../../../../src","sources":["web/utils/blockUtils.ts"],"mappings":";;AACA,SAASA,QAAQ,QAAQ,kBAAe;AAIxC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,UAAUA,CAACC,IAAiB,EAAEC,MAAmD,EAAE;EAC1F,MAAMC,MAAM,GAAGF,IAAI;EACnBG,MAAM,CAACC,OAAO,CAACH,MAAM,CAAC,CAACI,OAAO,CAAC,CAAC,CAACC,QAAQ,EAAEC,KAAK,CAAC,KAAK;IACpD,IAAIA,KAAK,KAAKC,SAAS,IAAID,KAAK,KAAK,IAAI,IAAIA,KAAK,KAAK,EAAE,EAAE;MACzD;IACF;IACA;IACA;IAAEL,MAAM,CAACO,KAAK,CAASH,QAAQ,CAAC,GAAG,OAAOC,KAAK,KAAK,QAAQ,GAAG,GAAGA,KAAK,IAAI,GAAGA,KAAK;EACrF,CAAC,CAAC;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASG,aAAaA,CACpBV,IAAiB,EACjBW,MAA8B,EAC9BC,aAAmC,EACnC;EACAb,UAAU,CAACC,IAAI,EAAE;IACfa,MAAM,EAAE,GAAG;IACXC,OAAO,EAAE;EACX,CAAC,CAAC;EAEF,IAAI,CAACH,MAAM,EAAE;IACX;EACF;EAEA,IAAIA,MAAM,CAACI,MAAM,GAAG,CAAC,EAAE;IACrBhB,UAAU,CAACC,IAAI,EAAE;MACfgB,WAAW,EAAE,GAAGL,MAAM,CAACI,MAAM,IAAI;MACjCE,UAAU,EAAE,GAAGN,MAAM,CAACO,eAAe,GAAGP,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AEe,MAAM,GAAG,GAAGE,KAAK,KAAKvD,SAAS,GAAG,CAAC,GAAGuD,KAAK,IAAI,GAAGnD,aAAa,CAACoD,OAAO,EAAElB;EACrF,CAAC,CAAC;AACJ;AAEA,MAAMmB,wBAAwB,GAAG,CAAC,WAAW,CAAC;AAE9C,SAASC,uBAAuBA,CAAC5B,IAAc,EAAE;EAC/C,OAAO2B,wBAAwB,CAACE,QAAQ,CAAC7B,IAAI,CAAC;AAChD;AAEA,SAAS8B,6BAA6BA,CACpCpE,IAAiB,EACjBqE,SAA2C,EAClC;EACT,IAAIC,WAAW,GAAGtE,IAAI,CAACuE,UAAU;EACjC,OAAOD,WAAW,IAAKA,WAAW,EAAkBE,eAAe,KAAK,MAAM,EAAE;IAC9E,MAAMC,WAAW,GAAIH,WAAW,CAAiBI,YAAY,GAAG,WAAW,CAAC;IAC5E,IAAIL,SAAS,CAACI,WAAW,CAAC,EAAE;MAC1B,OAAO,IAAI;IACb;IACAH,WAAW,GAAGA,WAAW,CAACC,UAAU;EACtC;EACA,OAAO,KAAK;AACd;AAEA,SAAST,wBAAwBA,CAAC9D,IAAiB,EAAEyE,WAAqB,EAAW;EACnF,OAAOL,6BAA6B,CAACpE,IAAI,EAAGsC,IAAI,IAAKA,IAAI,KAAKmC,WAAW,CAAC;AAC5E;AACA,SAASE,iCAAiCA,CAAC3E,IAAiB,EAAW;EACrE,OAAOoE,6BAA6B,CAACpE,IAAI,EAAGsC,IAAI,IAC9C2B,wBAAwB,CAACE,QAAQ,CAAC7B,IAAgB,CACpD,CAAC;AACH;AAEA,SACEF,eAAe,EACf1B,aAAa,EACbuB,iBAAiB,EACjBiC,uBAAuB,EACvBJ,wBAAwB,EACxBa,iCAAiC,EACjCV,wBAAwB","ignoreList":[]}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ // This module is imported during server-side rendering (e.g. Expo Router's static
4
+ // web output), where `window`/`navigator` do not exist. All checks are therefore
5
+ // evaluated lazily on first access instead of at module scope.
6
+ const canUseDOM = typeof window !== "undefined" && typeof navigator !== "undefined";
7
+ function memoize(compute) {
8
+ let value;
9
+ return () => {
10
+ if (value === undefined) {
11
+ value = canUseDOM && compute();
12
+ }
13
+ return value;
14
+ };
15
+ }
16
+ const isFirefox = memoize(() => navigator.userAgent.toLowerCase().includes("firefox"));
17
+ const isChromium = memoize(() => "chrome" in window);
18
+
19
+ /**
20
+ * Whether the platform is a mobile browser.
21
+ * Copied from Expensify App https://github.com/Expensify/App/blob/90dee7accae79c49debf30354c160cab6c52c423/src/libs/Browser/index.website.ts#L41
22
+ */
23
+ const isMobile = memoize(() => /Android|webOS|iPhone|iPad|iPod|BlackBerry|BB|PlayBook|IEMobile|Windows Phone|Silk|Opera Mini/i.test(navigator.userAgent));
24
+ const BrowserUtils = {
25
+ get isFirefox() {
26
+ return isFirefox();
27
+ },
28
+ get isChromium() {
29
+ return isChromium();
30
+ },
31
+ get isMobile() {
32
+ return isMobile();
33
+ }
34
+ };
35
+ export default BrowserUtils;
36
+ //# sourceMappingURL=browserUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["canUseDOM","window","navigator","memoize","compute","value","undefined","isFirefox","userAgent","toLowerCase","includes","isChromium","isMobile","test","BrowserUtils"],"sourceRoot":"../../../../src","sources":["web/utils/browserUtils.ts"],"mappings":";;AAAA;AACA;AACA;AACA,MAAMA,SAAS,GAAG,OAAOC,MAAM,KAAK,WAAW,IAAI,OAAOC,SAAS,KAAK,WAAW;AAEnF,SAASC,OAAOA,CAACC,OAAsB,EAAiB;EACtD,IAAIC,KAA0B;EAC9B,OAAO,MAAM;IACX,IAAIA,KAAK,KAAKC,SAAS,EAAE;MACvBD,KAAK,GAAGL,SAAS,IAAII,OAAO,CAAC,CAAC;IAChC;IACA,OAAOC,KAAK;EACd,CAAC;AACH;AAEA,MAAME,SAAS,GAAGJ,OAAO,CAAC,MAAMD,SAAS,CAACM,SAAS,CAACC,WAAW,CAAC,CAAC,CAACC,QAAQ,CAAC,SAAS,CAAC,CAAC;AACtF,MAAMC,UAAU,GAAGR,OAAO,CAAC,MAAM,QAAQ,IAAIF,MAAM,CAAC;;AAEpD;AACA;AACA;AACA;AACA,MAAMW,QAAQ,GAAGT,OAAO,CAAC,MACvB,+FAA+F,CAACU,IAAI,CAClGX,SAAS,CAACM,SACZ,CACF,CAAC;AAED,MAAMM,YAAY,GAAG;EACnB,IAAIP,SAASA,CAAA,EAAG;IACd,OAAOA,SAAS,CAAC,CAAC;EACpB,CAAC;EACD,IAAII,UAAUA,CAAA,EAAG;IACf,OAAOA,UAAU,CAAC,CAAC;EACrB,CAAC;EACD,IAAIC,QAAQA,CAAA,EAAG;IACb,OAAOA,QAAQ,CAAC,CAAC;EACnB;AACF,CAAC;AAED,eAAeE,YAAY","ignoreList":[]}
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+
3
+ import { isChildOfMultilineMarkdownElement } from "./blockUtils.js";
4
+ import { findHTMLElementInTree, getTreeNodeByIndex } from "./treeUtils.js";
5
+ function getMaxRangeOffset(node) {
6
+ return node.nodeType === Node.TEXT_NODE ? (node.textContent ?? "").length : node.childNodes.length;
7
+ }
8
+
9
+ /**
10
+ * Range offsets are applied to the real DOM node, not the parsed markdown tree.
11
+ * When the tree is temporarily stale, clamp to the DOM node's bounds so cursor
12
+ * restoration lands at the nearest valid position instead of throwing.
13
+ */
14
+ function getClampedRangeOffset(node, offset) {
15
+ return Math.max(0, Math.min(offset, getMaxRangeOffset(node)));
16
+ }
17
+ function setCursorPosition(target, startIndex, endIndex = null, shouldScrollIntoView = false) {
18
+ // We don't want to move the cursor if the target is not focused
19
+ if (!target.tree || target !== document.activeElement) {
20
+ return;
21
+ }
22
+ const start = Math.max(0, Math.min(startIndex, target.tree.length));
23
+ const end = endIndex ? Math.max(0, Math.min(endIndex, target.tree.length)) : null;
24
+ if (end && end < start) {
25
+ return;
26
+ }
27
+ const range = document.createRange();
28
+ range.selectNodeContents(target);
29
+ const startTreeNode = getTreeNodeByIndex(target.tree, start);
30
+ const endTreeNode = end && startTreeNode && (end < startTreeNode.start || end >= startTreeNode.start + startTreeNode.length) ? getTreeNodeByIndex(target.tree, end) : startTreeNode;
31
+ if (!startTreeNode || !endTreeNode) {
32
+ console.error("Invalid start or end tree node");
33
+ return;
34
+ }
35
+ if (startTreeNode.type === "br") {
36
+ range.setStartBefore(startTreeNode.element);
37
+ } else {
38
+ const startElement = startTreeNode.element;
39
+ const startNode = startElement.childNodes[0] || startElement;
40
+ range.setStart(startNode, getClampedRangeOffset(startNode, start - startTreeNode.start));
41
+ }
42
+ if (endTreeNode.type === "br") {
43
+ range.setEndBefore(endTreeNode.element);
44
+ } else {
45
+ const endElement = endTreeNode.element;
46
+ const endNode = endElement.childNodes[0] || endElement;
47
+ range.setEnd(endNode, getClampedRangeOffset(endNode, (end || start) - endTreeNode.start));
48
+ }
49
+ if (!end) {
50
+ range.collapse(true);
51
+ }
52
+ const selection = window.getSelection();
53
+ if (selection) {
54
+ selection.setBaseAndExtent(range.startContainer, range.startOffset, range.endContainer, range.endOffset);
55
+ }
56
+ if (shouldScrollIntoView) {
57
+ scrollIntoView(target, endTreeNode);
58
+ }
59
+ }
60
+ function scrollIntoView(target, node) {
61
+ let scrollTargetElement = node.element;
62
+ const targetElement = target;
63
+ if (!isChildOfMultilineMarkdownElement(node.element)) {
64
+ const orderIndex = Number(node.orderIndex.split(",")[0]);
65
+ const currentLine = target.tree.childNodes[orderIndex]?.element;
66
+ if (currentLine) {
67
+ scrollTargetElement = currentLine;
68
+ }
69
+ } else if (node.element.nodeName === "BR") {
70
+ // Force scrolling BR into view
71
+ const selection = window.getSelection();
72
+ if (selection) {
73
+ const range = document.createRange();
74
+ range.setStartBefore(node.element);
75
+ range.collapse(true);
76
+ selection.addRange(range);
77
+
78
+ // Scroll to caret
79
+ const span = document.createElement("span");
80
+ span.textContent = "\u200B"; // zero-width space
81
+ range.insertNode(span);
82
+ span.scrollIntoView({
83
+ block: "center"
84
+ });
85
+ span.remove(); // cleanup
86
+ return;
87
+ }
88
+ }
89
+ const caretRect = scrollTargetElement.getBoundingClientRect();
90
+ const targetRect = target.getBoundingClientRect();
91
+ // In case the caret is below the visible input area, scroll to the end of the node
92
+ if (caretRect.top + caretRect.height > targetRect.top + targetRect.height) {
93
+ targetElement.scrollTop = caretRect.top - targetRect.top + target.scrollTop - targetRect.height + caretRect.height + 4;
94
+ return;
95
+ }
96
+ scrollTargetElement.scrollIntoView({
97
+ block: "nearest"
98
+ });
99
+ }
100
+ function moveCursorToEnd(target) {
101
+ const range = document.createRange();
102
+ const selection = window.getSelection();
103
+ if (selection) {
104
+ range.setStart(target, target.childNodes.length);
105
+ range.collapse(true);
106
+ selection.setBaseAndExtent(range.startContainer, range.startOffset, range.endContainer, range.endOffset);
107
+ }
108
+ }
109
+ function getCurrentCursorPosition(target) {
110
+ function getHTMLElement(node) {
111
+ let element = node;
112
+ if (element instanceof Text) {
113
+ element = node.parentElement;
114
+ }
115
+ return element;
116
+ }
117
+ const selection = window.getSelection();
118
+ if (!selection || selection && selection.rangeCount === 0) {
119
+ return null;
120
+ }
121
+ const range = selection.getRangeAt(0);
122
+ const startElement = getHTMLElement(range.startContainer);
123
+ const endElement = range.startContainer === range.endContainer ? startElement : getHTMLElement(range.endContainer);
124
+ const startTreeNode = findHTMLElementInTree(target.tree, startElement);
125
+ const endTreeNode = findHTMLElementInTree(target.tree, endElement);
126
+ let start = -1;
127
+ let end = -1;
128
+ if (startTreeNode && endTreeNode) {
129
+ start = startTreeNode.start + range.startOffset;
130
+
131
+ // If the end node is a root node, we need to set the end to the end of the text (FireFox fix)
132
+ if (endTreeNode?.parentNode === null) {
133
+ end = target.value.length;
134
+ } else {
135
+ end = endTreeNode.start + range.endOffset;
136
+ }
137
+ }
138
+ return {
139
+ start,
140
+ end
141
+ };
142
+ }
143
+ function removeSelection() {
144
+ const selection = window.getSelection();
145
+ if (selection) {
146
+ selection.removeAllRanges();
147
+ }
148
+ }
149
+ export { getCurrentCursorPosition, moveCursorToEnd, setCursorPosition, removeSelection, scrollIntoView };
150
+ //# sourceMappingURL=cursorUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["isChildOfMultilineMarkdownElement","findHTMLElementInTree","getTreeNodeByIndex","getMaxRangeOffset","node","nodeType","Node","TEXT_NODE","textContent","length","childNodes","getClampedRangeOffset","offset","Math","max","min","setCursorPosition","target","startIndex","endIndex","shouldScrollIntoView","tree","document","activeElement","start","end","range","createRange","selectNodeContents","startTreeNode","endTreeNode","console","error","type","setStartBefore","element","startElement","startNode","setStart","setEndBefore","endElement","endNode","setEnd","collapse","selection","window","getSelection","setBaseAndExtent","startContainer","startOffset","endContainer","endOffset","scrollIntoView","scrollTargetElement","targetElement","orderIndex","Number","split","currentLine","nodeName","addRange","span","createElement","insertNode","block","remove","caretRect","getBoundingClientRect","targetRect","top","height","scrollTop","moveCursorToEnd","getCurrentCursorPosition","getHTMLElement","Text","parentElement","rangeCount","getRangeAt","parentNode","value","removeSelection","removeAllRanges"],"sourceRoot":"../../../../src","sources":["web/utils/cursorUtils.ts"],"mappings":";;AACA,SAASA,iCAAiC,QAAQ,iBAAc;AAChE,SAASC,qBAAqB,EAAEC,kBAAkB,QAAQ,gBAAa;AAGvE,SAASC,iBAAiBA,CAACC,IAAe,EAAU;EAClD,OAAOA,IAAI,CAACC,QAAQ,KAAKC,IAAI,CAACC,SAAS,GACnC,CAACH,IAAI,CAACI,WAAW,IAAI,EAAE,EAAEC,MAAM,GAC/BL,IAAI,CAACM,UAAU,CAACD,MAAM;AAC5B;;AAEA;AACA;AACA;AACA;AACA;AACA,SAASE,qBAAqBA,CAACP,IAAe,EAAEQ,MAAc,EAAU;EACtE,OAAOC,IAAI,CAACC,GAAG,CAAC,CAAC,EAAED,IAAI,CAACE,GAAG,CAACH,MAAM,EAAET,iBAAiB,CAACC,IAAI,CAAC,CAAC,CAAC;AAC/D;AAEA,SAASY,iBAAiBA,CACxBC,MAAgC,EAChCC,UAAkB,EAClBC,QAAuB,GAAG,IAAI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,cAAc,CAAChD,KAAK,CAACwB,YAAY,CAAC;EAExC,MAAMrB,aAAa,GAAG5B,qBAAqB,CAACgB,MAAM,CAACI,IAAI,EAAEe,YAAY,CAAC;EACtE,MAAMN,WAAW,GAAG7B,qBAAqB,CAACgB,MAAM,CAACI,IAAI,EAAEmB,UAAU,CAAC;EAElE,IAAIhB,KAAK,GAAG,CAAC,CAAC;EACd,IAAIC,GAAG,GAAG,CAAC,CAAC;EACZ,IAAII,aAAa,IAAIC,WAAW,EAAE;IAChCN,KAAK,GAAGK,aAAa,CAACL,KAAK,GAAGE,KAAK,CAACuB,WAAW;;IAE/C;IACA,IAAInB,WAAW,EAAEiD,UAAU,KAAK,IAAI,EAAE;MACpCtD,GAAG,GAAGR,MAAM,CAAC+D,KAAK,CAACvE,MAAM;IAC3B,CAAC,MAAM;MACLgB,GAAG,GAAGK,WAAW,CAACN,KAAK,GAAGE,KAAK,CAACyB,SAAS;IAC3C;EACF;EACA,OAAO;IAAE3B,KAAK;IAAEC;EAAI,CAAC;AACvB;AAEA,SAASwD,eAAeA,CAAA,EAAG;EACzB,MAAMrC,SAAS,GAAGC,MAAM,CAACC,YAAY,CAAC,CAAC;EACvC,IAAIF,SAAS,EAAE;IACbA,SAAS,CAACsC,eAAe,CAAC,CAAC;EAC7B;AACF;AAEA,SACET,wBAAwB,EACxBD,eAAe,EACfxD,iBAAiB,EACjBiE,eAAe,EACf7B,cAAc","ignoreList":[]}
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+
3
+ import { isChildOfMarkdownElement, isChildOfMultilineMarkdownElement } from "./blockUtils.js";
4
+ import BrowserUtils from "./browserUtils.js";
5
+ const ZERO_WIDTH_SPACE = "\u200B";
6
+
7
+ // If an Input Method Editor is processing key input, the 'keyCode' is 229.
8
+ // https://www.w3.org/TR/uievents/#determine-keydown-keyup-keyCode
9
+ function isEventComposing(nativeEvent) {
10
+ return nativeEvent.isComposing || nativeEvent.keyCode === 229;
11
+ }
12
+ function getPlaceholderValue(placeholder) {
13
+ if (!placeholder) {
14
+ return ZERO_WIDTH_SPACE;
15
+ }
16
+ return placeholder.length ? placeholder : ZERO_WIDTH_SPACE;
17
+ }
18
+ function getElementHeight(node, styles, numberOfLines) {
19
+ if (numberOfLines) {
20
+ const tempElement = document.createElement("div");
21
+ tempElement.setAttribute("contenteditable", "true");
22
+ Object.assign(tempElement.style, styles);
23
+ tempElement.textContent = Array(numberOfLines).fill("A").join("\n");
24
+ if (node.parentElement) {
25
+ node.parentElement.appendChild(tempElement);
26
+ const height = tempElement.clientHeight;
27
+ node.parentElement.removeChild(tempElement);
28
+ return height ? `${height}px` : "auto";
29
+ }
30
+ }
31
+ return styles.height ? `${styles.height}px` : "auto";
32
+ }
33
+ function normalizeValue(value) {
34
+ return value.replaceAll("\r\n", "\n");
35
+ }
36
+
37
+ /**
38
+ * Returns the parent of a given node that is higher in the hierarchy and is of a different type than 'text', 'br' or 'line'
39
+ */
40
+ function getTopParentNode(node) {
41
+ let currentParentNode = node.parentNode;
42
+ while (currentParentNode && ["text", "br", "line"].includes(currentParentNode.parentElement?.getAttribute("data-type") || "")) {
43
+ currentParentNode = currentParentNode?.parentNode || null;
44
+ }
45
+ return currentParentNode;
46
+ }
47
+
48
+ /**
49
+ * On Firefox, when breaking one codeblock, its syntax and the <br> after it can be merged into the closing syntax of the previous codeblock.
50
+ */
51
+ function didTwoCodeblocksMerge(node) {
52
+ if (!node || !BrowserUtils.isFirefox) {
53
+ return;
54
+ }
55
+ // To identify that two codeblock has merged, we check if current line ends with <br> tag, that previously was second codeblock's opening syntax line break
56
+ const hasPartOfBrokenCodeblock = node.lastChild?.lastChild?.lastChild?.lastChild?.nodeName === "BR";
57
+ return BrowserUtils.isFirefox && node.lastChild?.getAttribute("data-type") === "codeblock" && hasPartOfBrokenCodeblock;
58
+ }
59
+
60
+ /**
61
+ * Parses the HTML structure of a MarkdownTextInputElement to a plain text string. Used for getting the correct value of the input element.
62
+ */
63
+ function parseInnerHTMLToText(target, cursorPosition, inputType, isMultiline = true) {
64
+ const stack = [target];
65
+ let text = "";
66
+ let shouldAddNewline = false;
67
+ const lastNode = target.childNodes[target.childNodes.length - 1];
68
+ // 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.
69
+ if (lastNode?.nodeName === "DIV" && lastNode?.innerHTML === "<br>") {
70
+ target.removeChild(lastNode);
71
+ }
72
+ while (stack.length > 0) {
73
+ const node = stack.pop();
74
+ if (!node) {
75
+ break;
76
+ }
77
+
78
+ // If we are operating on the nodes that are children of the MarkdownTextInputElement, we need to add a newline after each
79
+ const isTopComponent = node.parentElement?.contentEditable === "true";
80
+ if (isTopComponent) {
81
+ // When inputType is undefined, the first part of the replaced text is added as a text node.
82
+ // Because of it, we need to prevent adding new lines in this case
83
+ if (!isMultiline || !inputType && node.nodeType === Node.TEXT_NODE) {
84
+ shouldAddNewline = false;
85
+ } else {
86
+ const firstChild = node.firstChild;
87
+ const containsEmptyBlockElement = firstChild?.getAttribute?.("data-type") === "block" && firstChild.textContent === "";
88
+ if (firstChild && shouldAddNewline && !containsEmptyBlockElement && !didTwoCodeblocksMerge(node.previousSibling)) {
89
+ text += "\n";
90
+ shouldAddNewline = false;
91
+ }
92
+ shouldAddNewline = true;
93
+ }
94
+ }
95
+ if (node.nodeType === Node.TEXT_NODE) {
96
+ let hasAddedNewline = false;
97
+ // Fix for codeblocks: Removing last codeblock newline, moves codeblock syntax too far into the codeblock content
98
+ // skipping one <br> after the codeblock syntax. We need to force parsing it before the text node is added.
99
+ if (node.parentElement && !node.parentElement.getAttribute?.("data-type") && isChildOfMarkdownElement(node, "pre")) {
100
+ text += "\n";
101
+ const nextBR = node.parentElement?.nextElementSibling?.firstElementChild ?? node.parentElement?.nextElementSibling;
102
+ if (nextBR && nextBR.tagName === "BR") {
103
+ nextBR.remove();
104
+ }
105
+ hasAddedNewline = true;
106
+ }
107
+
108
+ // Parse text nodes into text
109
+ text += node.textContent;
110
+
111
+ // Fix for codeblocks: If we are adding text at the end of a multiline markdown type element, we need to add a newline
112
+ // because the new text can replace the last <br> element and it will not be added to the text.
113
+ if (node.parentElement && node.parentNode?.parentElement?.nextSibling && !node.parentNode?.nextSibling && isChildOfMultilineMarkdownElement(node) && (!hasAddedNewline && isChildOfMarkdownElement(node, "br") || !node.parentElement.getAttribute?.("data-type") && isChildOfMarkdownElement(node, "syntax"))) {
114
+ text += "\n";
115
+ }
116
+ } else if (node.nodeName === "BR") {
117
+ const parentNode = getTopParentNode(node);
118
+ if (isMultiline && parentNode && parentNode.parentElement?.contentEditable !== "true" && !!(node.getAttribute("data-id") || node.parentElement.getAttribute("data-type") === "br") || node.parentElement?.getAttribute("data-type") === "text" && isChildOfMultilineMarkdownElement(node)) {
119
+ // 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).
120
+ // It prevents adding extra newlines when entering text - and now only for multiline inputs
121
+ text += "\n";
122
+ }
123
+ } else {
124
+ let i = node.childNodes.length - 1;
125
+ while (i > -1) {
126
+ const child = node.childNodes[i];
127
+ if (!child) {
128
+ break;
129
+ }
130
+ stack.push(child);
131
+ i--;
132
+ }
133
+ }
134
+ }
135
+ text = text.replaceAll("\r\n", "\n");
136
+
137
+ // Force letter removal if the input value haven't changed but input type is 'delete'
138
+ if (text === target.value && inputType?.includes("delete")) {
139
+ text = text.slice(0, cursorPosition - 1) + text.slice(cursorPosition);
140
+ }
141
+ return text;
142
+ }
143
+ export { isEventComposing, getPlaceholderValue, getElementHeight, parseInnerHTMLToText, normalizeValue };
144
+ //# sourceMappingURL=inputUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["isChildOfMarkdownElement","isChildOfMultilineMarkdownElement","BrowserUtils","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","getTopParentNode","currentParentNode","parentNode","includes","getAttribute","didTwoCodeblocksMerge","isFirefox","hasPartOfBrokenCodeblock","lastChild","nodeName","parseInnerHTMLToText","target","cursorPosition","inputType","isMultiline","stack","text","shouldAddNewline","lastNode","childNodes","innerHTML","pop","isTopComponent","contentEditable","nodeType","Node","TEXT_NODE","firstChild","containsEmptyBlockElement","previousSibling","hasAddedNewline","nextBR","nextElementSibling","firstElementChild","tagName","remove","nextSibling","i","child","push","slice"],"sourceRoot":"../../../../src","sources":["web/utils/inputUtils.ts"],"mappings":";;AAEA,SAASA,wBAAwB,EAAEC,iCAAiC,QAAQ,iBAAc;AAC1F,OAAOC,YAAY,MAAM,mBAAgB;AAEzC,MAAMC,gBAAgB,GAAG,QAAQ;;AAEjC;AACA;AACA,SAASC,gBAAgBA,CAACC,WAA2D,EAAE;EACrF,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,CACvBC,IAAoB,EACpBC,MAAqB,EACrBC,aAAiC,EACjC;EACA,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,GAAG,CAAC,CAACC,IAAI,CAAC,IAAI,CAAC;IACnE,IAAIb,IAAI,CAACc,aAAa,EAAE;MACtBd,IAAI,CAACc,aAAa,CA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,CAAC,KAAK,IAAI,CACvE,IACF1B,IAAI,CAACc,aAAa,EAAEY,YAAY,CAAC,WAAW,CAAC,KAAK,MAAM,IACvDrC,iCAAiC,CAACW,IAAI,CAAE,EAC1C;QACA;QACA;QACAsC,IAAI,IAAI,IAAI;MACd;IACF,CAAC,MAAM;MACL,IAAIqB,CAAC,GAAG3D,IAAI,CAACyC,UAAU,CAAC3C,MAAM,GAAG,CAAC;MAClC,OAAO6D,CAAC,GAAG,CAAC,CAAC,EAAE;QACb,MAAMC,KAAK,GAAG5D,IAAI,CAACyC,UAAU,CAACkB,CAAC,CAAC;QAChC,IAAI,CAACC,KAAK,EAAE;UACV;QACF;QACAvB,KAAK,CAACwB,IAAI,CAACD,KAAK,CAAC;QACjBD,CAAC,EAAE;MACL;IACF;EACF;EACArB,IAAI,GAAGA,IAAI,CAACjB,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC;;EAEpC;EACA,IAAIiB,IAAI,KAAKL,MAAM,CAACb,KAAK,IAAIe,SAAS,EAAEV,QAAQ,CAAC,QAAQ,CAAC,EAAE;IAC1Da,IAAI,GAAGA,IAAI,CAACwB,KAAK,CAAC,CAAC,EAAE5B,cAAc,GAAG,CAAC,CAAC,GAAGI,IAAI,CAACwB,KAAK,CAAC5B,cAAc,CAAC;EACvE;EACA,OAAOI,IAAI;AACb;AAEA,SACE9C,gBAAgB,EAChBI,mBAAmB,EACnBG,gBAAgB,EAChBiC,oBAAoB,EACpBb,cAAc","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"version":3,"names":["canUseDOM","window","document","FONT_PROPERTIES","widths","Map","MAX_CACHED_WIDTHS","measurer","measurerFont","getMeasurer","body","isConnected","element","createElement","Object","assign","style","position","top","left","whiteSpace","visibility","pointerEvents","setAttribute","appendChild","createTextMeasurer","source","font","sourceStyle","measureText","text","getComputedStyle","map","property","join","key","cached","get","undefined","forEach","textContent","width","getBoundingClientRect","size","clear","set"],"sourceRoot":"../../../../src","sources":["web/utils/measureUtils.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