@apollohg/react-native-prose-editor 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 (47) hide show
  1. package/LICENSE +160 -0
  2. package/README.md +143 -0
  3. package/android/build.gradle +39 -0
  4. package/android/src/main/assets/editor-icons/MaterialIcons.json +2236 -0
  5. package/android/src/main/assets/editor-icons/MaterialIcons.ttf +0 -0
  6. package/android/src/main/java/com/apollohg/editor/EditorAddons.kt +131 -0
  7. package/android/src/main/java/com/apollohg/editor/EditorEditText.kt +1057 -0
  8. package/android/src/main/java/com/apollohg/editor/EditorHeightBehavior.kt +14 -0
  9. package/android/src/main/java/com/apollohg/editor/EditorInputConnection.kt +191 -0
  10. package/android/src/main/java/com/apollohg/editor/EditorTheme.kt +325 -0
  11. package/android/src/main/java/com/apollohg/editor/NativeEditorExpoView.kt +647 -0
  12. package/android/src/main/java/com/apollohg/editor/NativeEditorModule.kt +257 -0
  13. package/android/src/main/java/com/apollohg/editor/NativeToolbar.kt +714 -0
  14. package/android/src/main/java/com/apollohg/editor/PositionBridge.kt +76 -0
  15. package/android/src/main/java/com/apollohg/editor/RenderBridge.kt +1044 -0
  16. package/android/src/main/java/com/apollohg/editor/RichTextEditorView.kt +211 -0
  17. package/expo-module.config.json +9 -0
  18. package/ios/EditorAddons.swift +228 -0
  19. package/ios/EditorCore.xcframework/Info.plist +44 -0
  20. package/ios/EditorCore.xcframework/ios-arm64/libeditor_core.a +0 -0
  21. package/ios/EditorCore.xcframework/ios-arm64_x86_64-simulator/libeditor_core.a +0 -0
  22. package/ios/EditorLayoutManager.swift +254 -0
  23. package/ios/EditorTheme.swift +372 -0
  24. package/ios/Generated_editor_core.swift +1143 -0
  25. package/ios/NativeEditorExpoView.swift +1417 -0
  26. package/ios/NativeEditorModule.swift +263 -0
  27. package/ios/PositionBridge.swift +278 -0
  28. package/ios/ReactNativeProseEditor.podspec +49 -0
  29. package/ios/RenderBridge.swift +825 -0
  30. package/ios/RichTextEditorView.swift +1559 -0
  31. package/ios/editor_coreFFI/editor_coreFFI.h +1014 -0
  32. package/ios/editor_coreFFI/module.modulemap +7 -0
  33. package/ios/editor_coreFFI.h +904 -0
  34. package/ios/editor_coreFFI.modulemap +7 -0
  35. package/package.json +66 -0
  36. package/rust/android/arm64-v8a/libeditor_core.so +0 -0
  37. package/rust/android/armeabi-v7a/libeditor_core.so +0 -0
  38. package/rust/android/x86_64/libeditor_core.so +0 -0
  39. package/rust/bindings/kotlin/uniffi/editor_core/editor_core.kt +2014 -0
  40. package/src/EditorTheme.ts +130 -0
  41. package/src/EditorToolbar.tsx +620 -0
  42. package/src/NativeEditorBridge.ts +607 -0
  43. package/src/NativeRichTextEditor.tsx +951 -0
  44. package/src/addons.ts +158 -0
  45. package/src/index.ts +63 -0
  46. package/src/schemas.ts +153 -0
  47. package/src/useNativeEditor.ts +173 -0
@@ -0,0 +1,76 @@
1
+ package com.apollohg.editor
2
+
3
+ import android.icu.text.BreakIterator
4
+
5
+ /**
6
+ * Converts between Android UTF-16 offsets and Rust editor-core scalar offsets,
7
+ * then snaps UTF-16 positions to grapheme boundaries when Android reports a
8
+ * cursor inside a composed character.
9
+ */
10
+ object PositionBridge {
11
+
12
+ /**
13
+ * Counts code points from the start of the string up to the given UTF-16 offset.
14
+ */
15
+ fun utf16ToScalar(utf16Offset: Int, text: String): Int {
16
+ if (utf16Offset <= 0) return 0
17
+
18
+ val endIndex = minOf(utf16Offset, text.length)
19
+ var scalarCount = 0
20
+ var utf16Pos = 0
21
+
22
+ while (utf16Pos < endIndex) {
23
+ val codePoint = Character.codePointAt(text, utf16Pos)
24
+ val charCount = Character.charCount(codePoint)
25
+ utf16Pos += charCount
26
+ scalarCount++
27
+ }
28
+
29
+ return scalarCount
30
+ }
31
+
32
+ /**
33
+ * Counts UTF-16 code units from the start of the string up to the given scalar offset.
34
+ */
35
+ fun scalarToUtf16(scalarOffset: Int, text: String): Int {
36
+ if (scalarOffset <= 0) return 0
37
+
38
+ var utf16Len = 0
39
+ var scalarsSeen = 0
40
+
41
+ var i = 0
42
+ while (i < text.length && scalarsSeen < scalarOffset) {
43
+ val codePoint = Character.codePointAt(text, i)
44
+ val charCount = Character.charCount(codePoint)
45
+ utf16Len += charCount
46
+ scalarsSeen++
47
+ i += charCount
48
+ }
49
+
50
+ return utf16Len
51
+ }
52
+
53
+ /**
54
+ * Biases forward to the next grapheme boundary when Android reports an
55
+ * offset inside a composed character sequence.
56
+ */
57
+ fun snapToGraphemeBoundary(utf16Offset: Int, text: String): Int {
58
+ if (text.isEmpty()) return 0
59
+
60
+ val clampedOffset = utf16Offset.coerceIn(0, text.length)
61
+
62
+ if (clampedOffset == 0 || clampedOffset == text.length) {
63
+ return clampedOffset
64
+ }
65
+
66
+ val breakIterator = BreakIterator.getCharacterInstance()
67
+ breakIterator.setText(text)
68
+
69
+ if (breakIterator.isBoundary(clampedOffset)) {
70
+ return clampedOffset
71
+ }
72
+
73
+ val nextBoundary = breakIterator.following(clampedOffset)
74
+ return if (nextBoundary == BreakIterator.DONE) text.length else nextBoundary
75
+ }
76
+ }