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,219 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.MULTILINE_MARKDOWN_TYPES = void 0;
7
+ exports.addBlockPrefixGap = addBlockPrefixGap;
8
+ exports.addLineLayout = addLineLayout;
9
+ exports.addStyleToBlock = addStyleToBlock;
10
+ exports.isChildOfMarkdownElement = isChildOfMarkdownElement;
11
+ exports.isChildOfMultilineMarkdownElement = isChildOfMultilineMarkdownElement;
12
+ exports.isMultilineMarkdownType = isMultilineMarkdownType;
13
+ var _blockLayout = require("./blockLayout.js");
14
+ /**
15
+ * Assigns CSS properties, skipping the ones the style does not define.
16
+ *
17
+ * Lengths arrive here already carrying their unit -- `processMarkdownStyle` runs the style through
18
+ * react-native-web's compiler before it reaches the builder -- but `parseRangesToHTMLNodes` can be
19
+ * called with a plain object that has not, and `CSSStyleDeclaration` silently drops a bare number.
20
+ * Adding the unit here means both spellings render the same.
21
+ */
22
+ function applyStyle(node, styles) {
23
+ const target = node;
24
+ Object.entries(styles).forEach(([property, value]) => {
25
+ if (value === undefined || value === null || value === "") {
26
+ return;
27
+ }
28
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
+ ;
30
+ target.style[property] = typeof value === "number" ? `${value}px` : value;
31
+ });
32
+ }
33
+
34
+ /**
35
+ * Applies the layout the block walk computed for one line.
36
+ *
37
+ * Everything a container contributes lands here rather than on the container's own span: its gutter
38
+ * is part of the paragraph's indent, and its ribbon is painted behind the whole paragraph. That is
39
+ * how the native formatters do it too, and on the web it is the only placement that works -- a
40
+ * container's span begins before the markers of the containers outside it, so a border drawn on it
41
+ * would sit in front of a bullet that is meant to precede it, and a gutter set on it would open
42
+ * before that bullet rather than after.
43
+ *
44
+ * `padding-left` holds every line of the paragraph at the indent, and the negative `text-indent`
45
+ * pulls the first one back to where its own marker starts -- `firstLineHeadIndent` and `headIndent`,
46
+ * spelled in CSS. A line that wraps, or a line continuing the block with no marker of its own, then
47
+ * lines up with the text above it instead of with the marker.
48
+ */
49
+ function addLineLayout(node, layout, markdownStyle) {
50
+ applyStyle(node, {
51
+ margin: "0",
52
+ padding: "0"
53
+ });
54
+ if (!layout) {
55
+ return;
56
+ }
57
+ if (layout.indent > 0) {
58
+ applyStyle(node, {
59
+ paddingLeft: `${layout.indent}px`,
60
+ textIndent: `${layout.firstLineIndent - layout.indent}px`
61
+ });
62
+ }
63
+ const width = (0, _blockLayout.toNumber)(markdownStyle.blockquote?.borderWidth);
64
+ if (layout.ribbons.length === 0 || width <= 0) {
65
+ return;
66
+ }
67
+
68
+ // One background layer per ribbon, each a solid bar of its own. They are painted on the paragraph
69
+ // rather than on any span so that they run its full height -- a quote that wraps gets one
70
+ // unbroken bar, exactly as `MarkdownTextLayoutFragment` draws it over the whole fragment.
71
+ const color = markdownStyle.blockquote?.borderColor || "transparent";
72
+ applyStyle(node, {
73
+ backgroundImage: layout.ribbons.map(() => `linear-gradient(${color}, ${color})`).join(", "),
74
+ backgroundPosition: layout.ribbons.map(x => `${x}px 0`).join(", "),
75
+ backgroundSize: layout.ribbons.map(() => `${width}px 100%`).join(", "),
76
+ backgroundRepeat: "no-repeat"
77
+ });
78
+ }
79
+
80
+ /**
81
+ * Opens the space a marker holds for the container that follows it.
82
+ *
83
+ * `MarkdownFormatter` kerns the marker's last character; the effect is the same, and it is what
84
+ * puts a nested list's indent between the quote's `>` and the bullet rather than in front of both.
85
+ */
86
+ function addBlockPrefixGap(node, gap) {
87
+ if (gap) {
88
+ node.style.marginRight = `${gap}px`;
89
+ }
90
+ }
91
+ function addStyleToBlock(targetElement, type, markdownStyle, isMultiline = true) {
92
+ const node = targetElement;
93
+ switch (type) {
94
+ case "syntax":
95
+ applyStyle(node, {
96
+ color: markdownStyle.syntax?.color
97
+ });
98
+ break;
99
+ case "bold":
100
+ node.style.fontWeight = "bold";
101
+ break;
102
+ case "italic":
103
+ node.style.fontStyle = "italic";
104
+ break;
105
+ case "strikethrough":
106
+ node.style.textDecoration = "line-through";
107
+ break;
108
+ case "emoji":
109
+ applyStyle(node, {
110
+ fontFamily: markdownStyle.emoji?.fontFamily,
111
+ fontSize: markdownStyle.emoji?.fontSize,
112
+ // Native re-centres a run whose font changed against the line height; the browser has no
113
+ // equivalent, and an emoji font left on the alphabetic baseline sits low.
114
+ verticalAlign: "middle"
115
+ });
116
+ break;
117
+ case "mention-here":
118
+ addMentionStyle(node, markdownStyle.mentionHere);
119
+ break;
120
+ case "mention-user":
121
+ addMentionStyle(node, markdownStyle.mentionUser);
122
+ break;
123
+ case "mention-report":
124
+ addMentionStyle(node, markdownStyle.mentionReport);
125
+ break;
126
+ case "link":
127
+ applyStyle(node, {
128
+ color: markdownStyle.link?.color,
129
+ textDecoration: "underline"
130
+ });
131
+ break;
132
+ // Both carry a font, a colour and a background, and nothing else: native draws no border, no
133
+ // corner radius and no padding around either, so neither does this.
134
+ case "code":
135
+ applyStyle(node, {
136
+ fontFamily: markdownStyle.code?.fontFamily,
137
+ fontSize: markdownStyle.code?.fontSize,
138
+ color: markdownStyle.code?.color,
139
+ backgroundColor: markdownStyle.code?.backgroundColor
140
+ });
141
+ break;
142
+ case "pre":
143
+ applyStyle(node, {
144
+ fontFamily: markdownStyle.pre?.fontFamily,
145
+ fontSize: markdownStyle.pre?.fontSize,
146
+ color: markdownStyle.pre?.color,
147
+ backgroundColor: markdownStyle.pre?.backgroundColor
148
+ });
149
+ break;
150
+ // Block containers hold no box of their own: their gutters and ribbons belong to the
151
+ // paragraph, in `addLineLayout`. All that is left is letting a long unbroken word inside one
152
+ // break rather than push the line past the input's edge.
153
+ case "blockquote":
154
+ case "list-ordered":
155
+ case "list-unordered":
156
+ applyStyle(node, {
157
+ overflowWrap: "anywhere"
158
+ });
159
+ break;
160
+ case "heading":
161
+ addHeadingStyle(node, markdownStyle);
162
+ break;
163
+ case "text":
164
+ if (!isMultiline && targetElement.parentElement?.style) {
165
+ // Move text background styles from parent to the text node
166
+ const parentElement = targetElement.parentElement;
167
+ node.style.cssText = parentElement.style.cssText;
168
+ parentElement.style.cssText = "";
169
+ }
170
+ break;
171
+ default:
172
+ break;
173
+ }
174
+ }
175
+ function addMentionStyle(node, style) {
176
+ applyStyle(node, {
177
+ color: style?.color,
178
+ backgroundColor: style?.backgroundColor,
179
+ borderRadius: style?.borderRadius
180
+ });
181
+ }
182
+
183
+ /**
184
+ * Sizes a heading the way native does: level N is the base size scaled N-1 times.
185
+ *
186
+ * The level does not reach here -- `ungroupRanges` turns it into one nested span per level -- so
187
+ * the scaling is expressed in `em` and compounds down the nesting to the same number. This runs
188
+ * once the span is in the tree, which is what lets it tell an inner level from the outermost one.
189
+ */
190
+ function addHeadingStyle(node, markdownStyle) {
191
+ const nested = isChildOfMarkdownElement(node, "heading");
192
+ const scale = markdownStyle.heading?.scale;
193
+ applyStyle(node, {
194
+ fontWeight: "bold",
195
+ fontSize: nested ? `${scale === undefined ? 1 : scale}em` : markdownStyle.heading?.fontSize
196
+ });
197
+ }
198
+ const MULTILINE_MARKDOWN_TYPES = exports.MULTILINE_MARKDOWN_TYPES = ["codeblock"];
199
+ function isMultilineMarkdownType(type) {
200
+ return MULTILINE_MARKDOWN_TYPES.includes(type);
201
+ }
202
+ function isDescendantOfMarkdownElement(node, predicate) {
203
+ let currentNode = node.parentNode;
204
+ while (currentNode && currentNode?.contentEditable !== "true") {
205
+ const elementType = currentNode.getAttribute?.("data-type");
206
+ if (predicate(elementType)) {
207
+ return true;
208
+ }
209
+ currentNode = currentNode.parentNode;
210
+ }
211
+ return false;
212
+ }
213
+ function isChildOfMarkdownElement(node, elementType) {
214
+ return isDescendantOfMarkdownElement(node, type => type === elementType);
215
+ }
216
+ function isChildOfMultilineMarkdownElement(node) {
217
+ return isDescendantOfMarkdownElement(node, type => MULTILINE_MARKDOWN_TYPES.includes(type));
218
+ }
219
+ //# sourceMappingURL=blockUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_blockLayout","require","applyStyle","node","styles","target","Object","entries","forEach","property","value","undefined","style","addLineLayout","layout","markdownStyle","margin","padding","indent","paddingLeft","textIndent","firstLineIndent","width","toNumber","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","exports","isMultilineMarkdownType","includes","isDescendantOfMarkdownElement","predicate","currentNode","parentNode","contentEditable","elementType","getAttribute","isChildOfMultilineMarkdownElement"],"sourceRoot":"../../../../src","sources":["web/utils/blockUtils.ts"],"mappings":";;;;;;;;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAIA;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;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AAC9B,IAAgB,CACpD,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ // This module is imported during server-side rendering (e.g. Expo Router's static
8
+ // web output), where `window`/`navigator` do not exist. All checks are therefore
9
+ // evaluated lazily on first access instead of at module scope.
10
+ const canUseDOM = typeof window !== "undefined" && typeof navigator !== "undefined";
11
+ function memoize(compute) {
12
+ let value;
13
+ return () => {
14
+ if (value === undefined) {
15
+ value = canUseDOM && compute();
16
+ }
17
+ return value;
18
+ };
19
+ }
20
+ const isFirefox = memoize(() => navigator.userAgent.toLowerCase().includes("firefox"));
21
+ const isChromium = memoize(() => "chrome" in window);
22
+
23
+ /**
24
+ * Whether the platform is a mobile browser.
25
+ * Copied from Expensify App https://github.com/Expensify/App/blob/90dee7accae79c49debf30354c160cab6c52c423/src/libs/Browser/index.website.ts#L41
26
+ */
27
+ const isMobile = memoize(() => /Android|webOS|iPhone|iPad|iPod|BlackBerry|BB|PlayBook|IEMobile|Windows Phone|Silk|Opera Mini/i.test(navigator.userAgent));
28
+ const BrowserUtils = {
29
+ get isFirefox() {
30
+ return isFirefox();
31
+ },
32
+ get isChromium() {
33
+ return isChromium();
34
+ },
35
+ get isMobile() {
36
+ return isMobile();
37
+ }
38
+ };
39
+ var _default = exports.default = BrowserUtils;
40
+ //# 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","_default","exports","default"],"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;AAAA,IAAAG,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEcH,YAAY","ignoreList":[]}
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getCurrentCursorPosition = getCurrentCursorPosition;
7
+ exports.moveCursorToEnd = moveCursorToEnd;
8
+ exports.removeSelection = removeSelection;
9
+ exports.scrollIntoView = scrollIntoView;
10
+ exports.setCursorPosition = setCursorPosition;
11
+ var _blockUtils = require("./blockUtils.js");
12
+ var _treeUtils = require("./treeUtils.js");
13
+ function getMaxRangeOffset(node) {
14
+ return node.nodeType === Node.TEXT_NODE ? (node.textContent ?? "").length : node.childNodes.length;
15
+ }
16
+
17
+ /**
18
+ * Range offsets are applied to the real DOM node, not the parsed markdown tree.
19
+ * When the tree is temporarily stale, clamp to the DOM node's bounds so cursor
20
+ * restoration lands at the nearest valid position instead of throwing.
21
+ */
22
+ function getClampedRangeOffset(node, offset) {
23
+ return Math.max(0, Math.min(offset, getMaxRangeOffset(node)));
24
+ }
25
+ function setCursorPosition(target, startIndex, endIndex = null, shouldScrollIntoView = false) {
26
+ // We don't want to move the cursor if the target is not focused
27
+ if (!target.tree || target !== document.activeElement) {
28
+ return;
29
+ }
30
+ const start = Math.max(0, Math.min(startIndex, target.tree.length));
31
+ const end = endIndex ? Math.max(0, Math.min(endIndex, target.tree.length)) : null;
32
+ if (end && end < start) {
33
+ return;
34
+ }
35
+ const range = document.createRange();
36
+ range.selectNodeContents(target);
37
+ const startTreeNode = (0, _treeUtils.getTreeNodeByIndex)(target.tree, start);
38
+ const endTreeNode = end && startTreeNode && (end < startTreeNode.start || end >= startTreeNode.start + startTreeNode.length) ? (0, _treeUtils.getTreeNodeByIndex)(target.tree, end) : startTreeNode;
39
+ if (!startTreeNode || !endTreeNode) {
40
+ console.error("Invalid start or end tree node");
41
+ return;
42
+ }
43
+ if (startTreeNode.type === "br") {
44
+ range.setStartBefore(startTreeNode.element);
45
+ } else {
46
+ const startElement = startTreeNode.element;
47
+ const startNode = startElement.childNodes[0] || startElement;
48
+ range.setStart(startNode, getClampedRangeOffset(startNode, start - startTreeNode.start));
49
+ }
50
+ if (endTreeNode.type === "br") {
51
+ range.setEndBefore(endTreeNode.element);
52
+ } else {
53
+ const endElement = endTreeNode.element;
54
+ const endNode = endElement.childNodes[0] || endElement;
55
+ range.setEnd(endNode, getClampedRangeOffset(endNode, (end || start) - endTreeNode.start));
56
+ }
57
+ if (!end) {
58
+ range.collapse(true);
59
+ }
60
+ const selection = window.getSelection();
61
+ if (selection) {
62
+ selection.setBaseAndExtent(range.startContainer, range.startOffset, range.endContainer, range.endOffset);
63
+ }
64
+ if (shouldScrollIntoView) {
65
+ scrollIntoView(target, endTreeNode);
66
+ }
67
+ }
68
+ function scrollIntoView(target, node) {
69
+ let scrollTargetElement = node.element;
70
+ const targetElement = target;
71
+ if (!(0, _blockUtils.isChildOfMultilineMarkdownElement)(node.element)) {
72
+ const orderIndex = Number(node.orderIndex.split(",")[0]);
73
+ const currentLine = target.tree.childNodes[orderIndex]?.element;
74
+ if (currentLine) {
75
+ scrollTargetElement = currentLine;
76
+ }
77
+ } else if (node.element.nodeName === "BR") {
78
+ // Force scrolling BR into view
79
+ const selection = window.getSelection();
80
+ if (selection) {
81
+ const range = document.createRange();
82
+ range.setStartBefore(node.element);
83
+ range.collapse(true);
84
+ selection.addRange(range);
85
+
86
+ // Scroll to caret
87
+ const span = document.createElement("span");
88
+ span.textContent = "\u200B"; // zero-width space
89
+ range.insertNode(span);
90
+ span.scrollIntoView({
91
+ block: "center"
92
+ });
93
+ span.remove(); // cleanup
94
+ return;
95
+ }
96
+ }
97
+ const caretRect = scrollTargetElement.getBoundingClientRect();
98
+ const targetRect = target.getBoundingClientRect();
99
+ // In case the caret is below the visible input area, scroll to the end of the node
100
+ if (caretRect.top + caretRect.height > targetRect.top + targetRect.height) {
101
+ targetElement.scrollTop = caretRect.top - targetRect.top + target.scrollTop - targetRect.height + caretRect.height + 4;
102
+ return;
103
+ }
104
+ scrollTargetElement.scrollIntoView({
105
+ block: "nearest"
106
+ });
107
+ }
108
+ function moveCursorToEnd(target) {
109
+ const range = document.createRange();
110
+ const selection = window.getSelection();
111
+ if (selection) {
112
+ range.setStart(target, target.childNodes.length);
113
+ range.collapse(true);
114
+ selection.setBaseAndExtent(range.startContainer, range.startOffset, range.endContainer, range.endOffset);
115
+ }
116
+ }
117
+ function getCurrentCursorPosition(target) {
118
+ function getHTMLElement(node) {
119
+ let element = node;
120
+ if (element instanceof Text) {
121
+ element = node.parentElement;
122
+ }
123
+ return element;
124
+ }
125
+ const selection = window.getSelection();
126
+ if (!selection || selection && selection.rangeCount === 0) {
127
+ return null;
128
+ }
129
+ const range = selection.getRangeAt(0);
130
+ const startElement = getHTMLElement(range.startContainer);
131
+ const endElement = range.startContainer === range.endContainer ? startElement : getHTMLElement(range.endContainer);
132
+ const startTreeNode = (0, _treeUtils.findHTMLElementInTree)(target.tree, startElement);
133
+ const endTreeNode = (0, _treeUtils.findHTMLElementInTree)(target.tree, endElement);
134
+ let start = -1;
135
+ let end = -1;
136
+ if (startTreeNode && endTreeNode) {
137
+ start = startTreeNode.start + range.startOffset;
138
+
139
+ // If the end node is a root node, we need to set the end to the end of the text (FireFox fix)
140
+ if (endTreeNode?.parentNode === null) {
141
+ end = target.value.length;
142
+ } else {
143
+ end = endTreeNode.start + range.endOffset;
144
+ }
145
+ }
146
+ return {
147
+ start,
148
+ end
149
+ };
150
+ }
151
+ function removeSelection() {
152
+ const selection = window.getSelection();
153
+ if (selection) {
154
+ selection.removeAllRanges();
155
+ }
156
+ }
157
+ //# sourceMappingURL=cursorUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_blockUtils","require","_treeUtils","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","getTreeNodeByIndex","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","isChildOfMultilineMarkdownElement","orderIndex","Number","split","currentLine","nodeName","addRange","span","createElement","insertNode","block","remove","caretRect","getBoundingClientRect","targetRect","top","height","scrollTop","moveCursorToEnd","getCurrentCursorPosition","getHTMLElement","Text","parentElement","rangeCount","getRangeAt","findHTMLElementInTree","parentNode","value","removeSelection","removeAllRanges"],"sourceRoot":"../../../../src","sources":["web/utils/cursorUtils.ts"],"mappings":";;;;;;;;;;AACA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAA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M,CAACC,YAAY,CAAC,CAAC;EACvC,IAAIF,SAAS,EAAE;IACbA,SAAS,CAACwC,eAAe,CAAC,CAAC;EAC7B;AACF","ignoreList":[]}
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getElementHeight = getElementHeight;
7
+ exports.getPlaceholderValue = getPlaceholderValue;
8
+ exports.isEventComposing = isEventComposing;
9
+ exports.normalizeValue = normalizeValue;
10
+ exports.parseInnerHTMLToText = parseInnerHTMLToText;
11
+ var _blockUtils = require("./blockUtils.js");
12
+ var _browserUtils = _interopRequireDefault(require("./browserUtils.js"));
13
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
+ const ZERO_WIDTH_SPACE = "\u200B";
15
+
16
+ // If an Input Method Editor is processing key input, the 'keyCode' is 229.
17
+ // https://www.w3.org/TR/uievents/#determine-keydown-keyup-keyCode
18
+ function isEventComposing(nativeEvent) {
19
+ return nativeEvent.isComposing || nativeEvent.keyCode === 229;
20
+ }
21
+ function getPlaceholderValue(placeholder) {
22
+ if (!placeholder) {
23
+ return ZERO_WIDTH_SPACE;
24
+ }
25
+ return placeholder.length ? placeholder : ZERO_WIDTH_SPACE;
26
+ }
27
+ function getElementHeight(node, styles, numberOfLines) {
28
+ if (numberOfLines) {
29
+ const tempElement = document.createElement("div");
30
+ tempElement.setAttribute("contenteditable", "true");
31
+ Object.assign(tempElement.style, styles);
32
+ tempElement.textContent = Array(numberOfLines).fill("A").join("\n");
33
+ if (node.parentElement) {
34
+ node.parentElement.appendChild(tempElement);
35
+ const height = tempElement.clientHeight;
36
+ node.parentElement.removeChild(tempElement);
37
+ return height ? `${height}px` : "auto";
38
+ }
39
+ }
40
+ return styles.height ? `${styles.height}px` : "auto";
41
+ }
42
+ function normalizeValue(value) {
43
+ return value.replaceAll("\r\n", "\n");
44
+ }
45
+
46
+ /**
47
+ * Returns the parent of a given node that is higher in the hierarchy and is of a different type than 'text', 'br' or 'line'
48
+ */
49
+ function getTopParentNode(node) {
50
+ let currentParentNode = node.parentNode;
51
+ while (currentParentNode && ["text", "br", "line"].includes(currentParentNode.parentElement?.getAttribute("data-type") || "")) {
52
+ currentParentNode = currentParentNode?.parentNode || null;
53
+ }
54
+ return currentParentNode;
55
+ }
56
+
57
+ /**
58
+ * On Firefox, when breaking one codeblock, its syntax and the <br> after it can be merged into the closing syntax of the previous codeblock.
59
+ */
60
+ function didTwoCodeblocksMerge(node) {
61
+ if (!node || !_browserUtils.default.isFirefox) {
62
+ return;
63
+ }
64
+ // 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
65
+ const hasPartOfBrokenCodeblock = node.lastChild?.lastChild?.lastChild?.lastChild?.nodeName === "BR";
66
+ return _browserUtils.default.isFirefox && node.lastChild?.getAttribute("data-type") === "codeblock" && hasPartOfBrokenCodeblock;
67
+ }
68
+
69
+ /**
70
+ * Parses the HTML structure of a MarkdownTextInputElement to a plain text string. Used for getting the correct value of the input element.
71
+ */
72
+ function parseInnerHTMLToText(target, cursorPosition, inputType, isMultiline = true) {
73
+ const stack = [target];
74
+ let text = "";
75
+ let shouldAddNewline = false;
76
+ const lastNode = target.childNodes[target.childNodes.length - 1];
77
+ // 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.
78
+ if (lastNode?.nodeName === "DIV" && lastNode?.innerHTML === "<br>") {
79
+ target.removeChild(lastNode);
80
+ }
81
+ while (stack.length > 0) {
82
+ const node = stack.pop();
83
+ if (!node) {
84
+ break;
85
+ }
86
+
87
+ // If we are operating on the nodes that are children of the MarkdownTextInputElement, we need to add a newline after each
88
+ const isTopComponent = node.parentElement?.contentEditable === "true";
89
+ if (isTopComponent) {
90
+ // When inputType is undefined, the first part of the replaced text is added as a text node.
91
+ // Because of it, we need to prevent adding new lines in this case
92
+ if (!isMultiline || !inputType && node.nodeType === Node.TEXT_NODE) {
93
+ shouldAddNewline = false;
94
+ } else {
95
+ const firstChild = node.firstChild;
96
+ const containsEmptyBlockElement = firstChild?.getAttribute?.("data-type") === "block" && firstChild.textContent === "";
97
+ if (firstChild && shouldAddNewline && !containsEmptyBlockElement && !didTwoCodeblocksMerge(node.previousSibling)) {
98
+ text += "\n";
99
+ shouldAddNewline = false;
100
+ }
101
+ shouldAddNewline = true;
102
+ }
103
+ }
104
+ if (node.nodeType === Node.TEXT_NODE) {
105
+ let hasAddedNewline = false;
106
+ // Fix for codeblocks: Removing last codeblock newline, moves codeblock syntax too far into the codeblock content
107
+ // skipping one <br> after the codeblock syntax. We need to force parsing it before the text node is added.
108
+ if (node.parentElement && !node.parentElement.getAttribute?.("data-type") && (0, _blockUtils.isChildOfMarkdownElement)(node, "pre")) {
109
+ text += "\n";
110
+ const nextBR = node.parentElement?.nextElementSibling?.firstElementChild ?? node.parentElement?.nextElementSibling;
111
+ if (nextBR && nextBR.tagName === "BR") {
112
+ nextBR.remove();
113
+ }
114
+ hasAddedNewline = true;
115
+ }
116
+
117
+ // Parse text nodes into text
118
+ text += node.textContent;
119
+
120
+ // Fix for codeblocks: If we are adding text at the end of a multiline markdown type element, we need to add a newline
121
+ // because the new text can replace the last <br> element and it will not be added to the text.
122
+ if (node.parentElement && node.parentNode?.parentElement?.nextSibling && !node.parentNode?.nextSibling && (0, _blockUtils.isChildOfMultilineMarkdownElement)(node) && (!hasAddedNewline && (0, _blockUtils.isChildOfMarkdownElement)(node, "br") || !node.parentElement.getAttribute?.("data-type") && (0, _blockUtils.isChildOfMarkdownElement)(node, "syntax"))) {
123
+ text += "\n";
124
+ }
125
+ } else if (node.nodeName === "BR") {
126
+ const parentNode = getTopParentNode(node);
127
+ if (isMultiline && parentNode && parentNode.parentElement?.contentEditable !== "true" && !!(node.getAttribute("data-id") || node.parentElement.getAttribute("data-type") === "br") || node.parentElement?.getAttribute("data-type") === "text" && (0, _blockUtils.isChildOfMultilineMarkdownElement)(node)) {
128
+ // 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).
129
+ // It prevents adding extra newlines when entering text - and now only for multiline inputs
130
+ text += "\n";
131
+ }
132
+ } else {
133
+ let i = node.childNodes.length - 1;
134
+ while (i > -1) {
135
+ const child = node.childNodes[i];
136
+ if (!child) {
137
+ break;
138
+ }
139
+ stack.push(child);
140
+ i--;
141
+ }
142
+ }
143
+ }
144
+ text = text.replaceAll("\r\n", "\n");
145
+
146
+ // Force letter removal if the input value haven't changed but input type is 'delete'
147
+ if (text === target.value && inputType?.includes("delete")) {
148
+ text = text.slice(0, cursorPosition - 1) + text.slice(cursorPosition);
149
+ }
150
+ return text;
151
+ }
152
+ //# sourceMappingURL=inputUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_blockUtils","require","_browserUtils","_interopRequireDefault","e","__esModule","default","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","BrowserUtils","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","isChildOfMarkdownElement","nextBR","nextElementSibling","firstElementChild","tagName","remove","nextSibling","isChildOfMultilineMarkdownElement","i","child","push","slice"],"sourceRoot":"../../../../src","sources":["web/utils/inputUtils.ts"],"mappings":";;;;;;;;;;AAEA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAC,sBAAA,CAAAF,OAAA;AAAyC,SAAAE,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,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UAAU,CAACoB,CAAC,CAAC;QAChC,IAAI,CAACC,KAAK,EAAE;UACV;QACF;QACAzB,KAAK,CAAC0B,IAAI,CAACD,KAAK,CAAC;QACjBD,CAAC,EAAE;MACL;IACF;EACF;EACAvB,IAAI,GAAGA,IAAI,CAAClB,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC;;EAEpC;EACA,IAAIkB,IAAI,KAAKL,MAAM,CAACd,KAAK,IAAIgB,SAAS,EAAEX,QAAQ,CAAC,QAAQ,CAAC,EAAE;IAC1Dc,IAAI,GAAGA,IAAI,CAAC0B,KAAK,CAAC,CAAC,EAAE9B,cAAc,GAAG,CAAC,CAAC,GAAGI,IAAI,CAAC0B,KAAK,CAAC9B,cAAc,CAAC;EACvE;EACA,OAAOI,IAAI;AACb","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.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAMA,SAAS,GAAG,OAAOC,MAAM,KAAK,WAAW,IAAI,OAAOC,QAAQ,KAAK,WAAW;;AAElF;AACA,MAAMC,eAAe,GAAG,CACtB,YAAY,EACZ,UAAU,EACV,WAAW,EACX,YAAY,EACZ,aAAa,EACb,aAAa,EACb,aAAa,EACb,qBAAqB,EACrB,eAAe,EACf,aAAa,EACb,eAAe,CACP;AAEV,MAAMC,MAAM,GAAG,IAAIC,GAAG,CAAiB,CAAC;AACxC;AACA;AACA,MAAMC,iBAAiB,GAAG,IAAI;AAE9B,IAAIC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