react-native-nitro-markdown 0.4.3 → 0.5.1

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 (175) hide show
  1. package/README.md +417 -25
  2. package/android/src/main/java/com/margelo/nitro/com/nitromarkdown/HybridMarkdownSession.kt +46 -8
  3. package/android/src/main/java/com/nitromarkdown/NitroMarkdownPackage.kt +2 -1
  4. package/cpp/bindings/HybridMarkdownParser.cpp +216 -66
  5. package/cpp/bindings/HybridMarkdownParser.hpp +2 -0
  6. package/ios/HybridMarkdownSession.swift +51 -7
  7. package/lib/commonjs/MarkdownContext.js.map +1 -1
  8. package/lib/commonjs/headless.js +61 -5
  9. package/lib/commonjs/headless.js.map +1 -1
  10. package/lib/commonjs/index.js +9 -1
  11. package/lib/commonjs/index.js.map +1 -1
  12. package/lib/commonjs/markdown-stream.js +107 -13
  13. package/lib/commonjs/markdown-stream.js.map +1 -1
  14. package/lib/commonjs/markdown.js +191 -26
  15. package/lib/commonjs/markdown.js.map +1 -1
  16. package/lib/commonjs/renderers/code.js +21 -2
  17. package/lib/commonjs/renderers/code.js.map +1 -1
  18. package/lib/commonjs/renderers/table/cell-content.js +32 -0
  19. package/lib/commonjs/renderers/table/cell-content.js.map +1 -0
  20. package/lib/commonjs/renderers/table/index.js +310 -0
  21. package/lib/commonjs/renderers/table/index.js.map +1 -0
  22. package/lib/commonjs/renderers/table/table-reducer.js +29 -0
  23. package/lib/commonjs/renderers/table/table-reducer.js.map +1 -0
  24. package/lib/commonjs/renderers/table/table-utils.js +68 -0
  25. package/lib/commonjs/renderers/table/table-utils.js.map +1 -0
  26. package/lib/commonjs/renderers/table/types.js +6 -0
  27. package/lib/commonjs/renderers/table/types.js.map +1 -0
  28. package/lib/commonjs/renderers/table.js +6 -306
  29. package/lib/commonjs/renderers/table.js.map +1 -1
  30. package/lib/commonjs/theme.js +10 -1
  31. package/lib/commonjs/theme.js.map +1 -1
  32. package/lib/commonjs/use-markdown-stream.js +9 -1
  33. package/lib/commonjs/use-markdown-stream.js.map +1 -1
  34. package/lib/commonjs/utils/code-highlight.js +101 -0
  35. package/lib/commonjs/utils/code-highlight.js.map +1 -0
  36. package/lib/commonjs/utils/incremental-ast.js +153 -0
  37. package/lib/commonjs/utils/incremental-ast.js.map +1 -0
  38. package/lib/module/MarkdownContext.js.map +1 -1
  39. package/lib/module/headless.js +56 -4
  40. package/lib/module/headless.js.map +1 -1
  41. package/lib/module/index.js +1 -0
  42. package/lib/module/index.js.map +1 -1
  43. package/lib/module/markdown-stream.js +108 -14
  44. package/lib/module/markdown-stream.js.map +1 -1
  45. package/lib/module/markdown.js +193 -28
  46. package/lib/module/markdown.js.map +1 -1
  47. package/lib/module/renderers/code.js +21 -2
  48. package/lib/module/renderers/code.js.map +1 -1
  49. package/lib/module/renderers/table/cell-content.js +27 -0
  50. package/lib/module/renderers/table/cell-content.js.map +1 -0
  51. package/lib/module/renderers/table/index.js +305 -0
  52. package/lib/module/renderers/table/index.js.map +1 -0
  53. package/lib/module/renderers/table/table-reducer.js +24 -0
  54. package/lib/module/renderers/table/table-reducer.js.map +1 -0
  55. package/lib/module/renderers/table/table-utils.js +62 -0
  56. package/lib/module/renderers/table/table-utils.js.map +1 -0
  57. package/lib/module/renderers/table/types.js +4 -0
  58. package/lib/module/renderers/table/types.js.map +1 -0
  59. package/lib/module/renderers/table.js +1 -305
  60. package/lib/module/renderers/table.js.map +1 -1
  61. package/lib/module/theme.js +10 -1
  62. package/lib/module/theme.js.map +1 -1
  63. package/lib/module/use-markdown-stream.js +9 -1
  64. package/lib/module/use-markdown-stream.js.map +1 -1
  65. package/lib/module/utils/code-highlight.js +97 -0
  66. package/lib/module/utils/code-highlight.js.map +1 -0
  67. package/lib/module/utils/incremental-ast.js +147 -0
  68. package/lib/module/utils/incremental-ast.js.map +1 -0
  69. package/lib/typescript/commonjs/Markdown.nitro.d.ts +2 -0
  70. package/lib/typescript/commonjs/Markdown.nitro.d.ts.map +1 -1
  71. package/lib/typescript/commonjs/MarkdownContext.d.ts +6 -0
  72. package/lib/typescript/commonjs/MarkdownContext.d.ts.map +1 -1
  73. package/lib/typescript/commonjs/headless.d.ts +18 -0
  74. package/lib/typescript/commonjs/headless.d.ts.map +1 -1
  75. package/lib/typescript/commonjs/index.d.ts +4 -0
  76. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  77. package/lib/typescript/commonjs/markdown-stream.d.ts +6 -1
  78. package/lib/typescript/commonjs/markdown-stream.d.ts.map +1 -1
  79. package/lib/typescript/commonjs/markdown.d.ts +77 -1
  80. package/lib/typescript/commonjs/markdown.d.ts.map +1 -1
  81. package/lib/typescript/commonjs/renderers/code.d.ts.map +1 -1
  82. package/lib/typescript/commonjs/renderers/table/cell-content.d.ts +15 -0
  83. package/lib/typescript/commonjs/renderers/table/cell-content.d.ts.map +1 -0
  84. package/lib/typescript/commonjs/renderers/table/index.d.ts +11 -0
  85. package/lib/typescript/commonjs/renderers/table/index.d.ts.map +1 -0
  86. package/lib/typescript/commonjs/renderers/table/table-reducer.d.ts +5 -0
  87. package/lib/typescript/commonjs/renderers/table/table-reducer.d.ts.map +1 -0
  88. package/lib/typescript/commonjs/renderers/table/table-utils.d.ts +10 -0
  89. package/lib/typescript/commonjs/renderers/table/table-utils.d.ts.map +1 -0
  90. package/lib/typescript/commonjs/renderers/table/types.d.ts +24 -0
  91. package/lib/typescript/commonjs/renderers/table/types.d.ts.map +1 -0
  92. package/lib/typescript/commonjs/renderers/table.d.ts +1 -11
  93. package/lib/typescript/commonjs/renderers/table.d.ts.map +1 -1
  94. package/lib/typescript/commonjs/specs/MarkdownSession.nitro.d.ts +14 -2
  95. package/lib/typescript/commonjs/specs/MarkdownSession.nitro.d.ts.map +1 -1
  96. package/lib/typescript/commonjs/theme.d.ts +18 -2
  97. package/lib/typescript/commonjs/theme.d.ts.map +1 -1
  98. package/lib/typescript/commonjs/use-markdown-stream.d.ts +4 -0
  99. package/lib/typescript/commonjs/use-markdown-stream.d.ts.map +1 -1
  100. package/lib/typescript/commonjs/utils/code-highlight.d.ts +8 -0
  101. package/lib/typescript/commonjs/utils/code-highlight.d.ts.map +1 -0
  102. package/lib/typescript/commonjs/utils/incremental-ast.d.ts +12 -0
  103. package/lib/typescript/commonjs/utils/incremental-ast.d.ts.map +1 -0
  104. package/lib/typescript/module/Markdown.nitro.d.ts +2 -0
  105. package/lib/typescript/module/Markdown.nitro.d.ts.map +1 -1
  106. package/lib/typescript/module/MarkdownContext.d.ts +6 -0
  107. package/lib/typescript/module/MarkdownContext.d.ts.map +1 -1
  108. package/lib/typescript/module/headless.d.ts +18 -0
  109. package/lib/typescript/module/headless.d.ts.map +1 -1
  110. package/lib/typescript/module/index.d.ts +4 -0
  111. package/lib/typescript/module/index.d.ts.map +1 -1
  112. package/lib/typescript/module/markdown-stream.d.ts +6 -1
  113. package/lib/typescript/module/markdown-stream.d.ts.map +1 -1
  114. package/lib/typescript/module/markdown.d.ts +77 -1
  115. package/lib/typescript/module/markdown.d.ts.map +1 -1
  116. package/lib/typescript/module/renderers/code.d.ts.map +1 -1
  117. package/lib/typescript/module/renderers/table/cell-content.d.ts +15 -0
  118. package/lib/typescript/module/renderers/table/cell-content.d.ts.map +1 -0
  119. package/lib/typescript/module/renderers/table/index.d.ts +11 -0
  120. package/lib/typescript/module/renderers/table/index.d.ts.map +1 -0
  121. package/lib/typescript/module/renderers/table/table-reducer.d.ts +5 -0
  122. package/lib/typescript/module/renderers/table/table-reducer.d.ts.map +1 -0
  123. package/lib/typescript/module/renderers/table/table-utils.d.ts +10 -0
  124. package/lib/typescript/module/renderers/table/table-utils.d.ts.map +1 -0
  125. package/lib/typescript/module/renderers/table/types.d.ts +24 -0
  126. package/lib/typescript/module/renderers/table/types.d.ts.map +1 -0
  127. package/lib/typescript/module/renderers/table.d.ts +1 -11
  128. package/lib/typescript/module/renderers/table.d.ts.map +1 -1
  129. package/lib/typescript/module/specs/MarkdownSession.nitro.d.ts +14 -2
  130. package/lib/typescript/module/specs/MarkdownSession.nitro.d.ts.map +1 -1
  131. package/lib/typescript/module/theme.d.ts +18 -2
  132. package/lib/typescript/module/theme.d.ts.map +1 -1
  133. package/lib/typescript/module/use-markdown-stream.d.ts +4 -0
  134. package/lib/typescript/module/use-markdown-stream.d.ts.map +1 -1
  135. package/lib/typescript/module/utils/code-highlight.d.ts +8 -0
  136. package/lib/typescript/module/utils/code-highlight.d.ts.map +1 -0
  137. package/lib/typescript/module/utils/incremental-ast.d.ts +12 -0
  138. package/lib/typescript/module/utils/incremental-ast.d.ts.map +1 -0
  139. package/nitrogen/generated/android/NitroMarkdownOnLoad.cpp +38 -26
  140. package/nitrogen/generated/android/NitroMarkdownOnLoad.hpp +13 -4
  141. package/nitrogen/generated/android/c++/JFunc_void_double_double.hpp +75 -0
  142. package/nitrogen/generated/android/c++/JHybridMarkdownSessionSpec.cpp +49 -34
  143. package/nitrogen/generated/android/c++/JHybridMarkdownSessionSpec.hpp +25 -24
  144. package/nitrogen/generated/android/kotlin/com/margelo/nitro/com/nitromarkdown/Func_void_double_double.kt +80 -0
  145. package/nitrogen/generated/android/kotlin/com/margelo/nitro/com/nitromarkdown/HybridMarkdownSessionSpec.kt +34 -21
  146. package/nitrogen/generated/ios/NitroMarkdown-Swift-Cxx-Bridge.cpp +8 -0
  147. package/nitrogen/generated/ios/NitroMarkdown-Swift-Cxx-Bridge.hpp +31 -0
  148. package/nitrogen/generated/ios/c++/HybridMarkdownSessionSpecSwift.hpp +34 -2
  149. package/nitrogen/generated/ios/swift/Func_void_double_double.swift +46 -0
  150. package/nitrogen/generated/ios/swift/HybridMarkdownSessionSpec.swift +6 -2
  151. package/nitrogen/generated/ios/swift/HybridMarkdownSessionSpec_cxx.swift +57 -9
  152. package/nitrogen/generated/shared/c++/HybridMarkdownParserSpec.cpp +2 -0
  153. package/nitrogen/generated/shared/c++/HybridMarkdownParserSpec.hpp +2 -0
  154. package/nitrogen/generated/shared/c++/HybridMarkdownSessionSpec.cpp +4 -0
  155. package/nitrogen/generated/shared/c++/HybridMarkdownSessionSpec.hpp +6 -2
  156. package/package.json +9 -5
  157. package/react-native-nitro-markdown.podspec +1 -1
  158. package/src/Markdown.nitro.ts +2 -0
  159. package/src/MarkdownContext.ts +6 -0
  160. package/src/headless.ts +54 -4
  161. package/src/index.ts +10 -0
  162. package/src/markdown-stream.tsx +163 -15
  163. package/src/markdown.tsx +381 -26
  164. package/src/renderers/code.tsx +32 -3
  165. package/src/renderers/table/cell-content.tsx +38 -0
  166. package/src/renderers/table/index.tsx +419 -0
  167. package/src/renderers/table/table-reducer.ts +36 -0
  168. package/src/renderers/table/table-utils.ts +81 -0
  169. package/src/renderers/table/types.ts +24 -0
  170. package/src/renderers/table.tsx +1 -401
  171. package/src/specs/MarkdownSession.nitro.ts +16 -2
  172. package/src/theme.ts +29 -1
  173. package/src/use-markdown-stream.ts +10 -0
  174. package/src/utils/code-highlight.ts +102 -0
  175. package/src/utils/incremental-ast.ts +224 -0
@@ -17,40 +17,52 @@
17
17
 
18
18
  #include "JHybridMarkdownSessionSpec.hpp"
19
19
  #include "JFunc_void.hpp"
20
+ #include "JFunc_void_double_double.hpp"
20
21
  #include "HybridMarkdownParser.hpp"
21
22
  #include <NitroModules/DefaultConstructableObject.hpp>
22
23
 
23
24
  namespace margelo::nitro::Markdown {
24
25
 
25
26
  int initialize(JavaVM* vm) {
27
+ return facebook::jni::initialize(vm, []() {
28
+ ::margelo::nitro::Markdown::registerAllNatives();
29
+ });
30
+ }
31
+
32
+ struct JHybridMarkdownSessionSpecImpl: public jni::JavaClass<JHybridMarkdownSessionSpecImpl, JHybridMarkdownSessionSpec::JavaPart> {
33
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/com/nitromarkdown/HybridMarkdownSession;";
34
+ static std::shared_ptr<JHybridMarkdownSessionSpec> create() {
35
+ static auto constructorFn = javaClassStatic()->getConstructor<JHybridMarkdownSessionSpecImpl::javaobject()>();
36
+ jni::local_ref<JHybridMarkdownSessionSpec::JavaPart> javaPart = javaClassStatic()->newObject(constructorFn);
37
+ return javaPart->getJHybridMarkdownSessionSpec();
38
+ }
39
+ };
40
+
41
+ void registerAllNatives() {
26
42
  using namespace margelo::nitro;
27
43
  using namespace margelo::nitro::Markdown;
28
- using namespace facebook;
29
-
30
- return facebook::jni::initialize(vm, [] {
31
- // Register native JNI methods
32
- margelo::nitro::Markdown::JHybridMarkdownSessionSpec::registerNatives();
33
- margelo::nitro::Markdown::JFunc_void_cxx::registerNatives();
34
-
35
- // Register Nitro Hybrid Objects
36
- HybridObjectRegistry::registerHybridObjectConstructor(
37
- "MarkdownParser",
38
- []() -> std::shared_ptr<HybridObject> {
39
- static_assert(std::is_default_constructible_v<HybridMarkdownParser>,
40
- "The HybridObject \"HybridMarkdownParser\" is not default-constructible! "
41
- "Create a public constructor that takes zero arguments to be able to autolink this HybridObject.");
42
- return std::make_shared<HybridMarkdownParser>();
43
- }
44
- );
45
- HybridObjectRegistry::registerHybridObjectConstructor(
46
- "MarkdownSession",
47
- []() -> std::shared_ptr<HybridObject> {
48
- static DefaultConstructableObject<JHybridMarkdownSessionSpec::javaobject> object("com/margelo/nitro/com/nitromarkdown/HybridMarkdownSession");
49
- auto instance = object.create();
50
- return instance->cthis()->shared();
51
- }
52
- );
53
- });
44
+
45
+ // Register native JNI methods
46
+ margelo::nitro::Markdown::JHybridMarkdownSessionSpec::CxxPart::registerNatives();
47
+ margelo::nitro::Markdown::JFunc_void_cxx::registerNatives();
48
+ margelo::nitro::Markdown::JFunc_void_double_double_cxx::registerNatives();
49
+
50
+ // Register Nitro Hybrid Objects
51
+ HybridObjectRegistry::registerHybridObjectConstructor(
52
+ "MarkdownParser",
53
+ []() -> std::shared_ptr<HybridObject> {
54
+ static_assert(std::is_default_constructible_v<HybridMarkdownParser>,
55
+ "The HybridObject \"HybridMarkdownParser\" is not default-constructible! "
56
+ "Create a public constructor that takes zero arguments to be able to autolink this HybridObject.");
57
+ return std::make_shared<HybridMarkdownParser>();
58
+ }
59
+ );
60
+ HybridObjectRegistry::registerHybridObjectConstructor(
61
+ "MarkdownSession",
62
+ []() -> std::shared_ptr<HybridObject> {
63
+ return JHybridMarkdownSessionSpecImpl::create();
64
+ }
65
+ );
54
66
  }
55
67
 
56
68
  } // namespace margelo::nitro::Markdown
@@ -6,20 +6,29 @@
6
6
  ///
7
7
 
8
8
  #include <jni.h>
9
+ #include <functional>
9
10
  #include <NitroModules/NitroDefines.hpp>
10
11
 
11
12
  namespace margelo::nitro::Markdown {
12
13
 
14
+ [[deprecated("Use registerNatives() instead.")]]
15
+ int initialize(JavaVM* vm);
16
+
13
17
  /**
14
- * Initializes the native (C++) part of NitroMarkdown, and autolinks all Hybrid Objects.
15
- * Call this in your `JNI_OnLoad` function (probably inside `cpp-adapter.cpp`).
18
+ * Register the native (C++) part of NitroMarkdown, and autolinks all Hybrid Objects.
19
+ * Call this in your `JNI_OnLoad` function (probably inside `cpp-adapter.cpp`),
20
+ * inside a `facebook::jni::initialize(vm, ...)` call.
16
21
  * Example:
17
22
  * ```cpp (cpp-adapter.cpp)
18
23
  * JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
19
- * return margelo::nitro::Markdown::initialize(vm);
24
+ * return facebook::jni::initialize(vm, []() {
25
+ * // register all NitroMarkdown HybridObjects
26
+ * margelo::nitro::Markdown::registerNatives();
27
+ * // any other custom registrations go here.
28
+ * });
20
29
  * }
21
30
  * ```
22
31
  */
23
- int initialize(JavaVM* vm);
32
+ void registerAllNatives();
24
33
 
25
34
  } // namespace margelo::nitro::Markdown
@@ -0,0 +1,75 @@
1
+ ///
2
+ /// JFunc_void_double_double.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #include <fbjni/fbjni.h>
11
+ #include <functional>
12
+
13
+ #include <functional>
14
+ #include <NitroModules/JNICallable.hpp>
15
+
16
+ namespace margelo::nitro::Markdown {
17
+
18
+ using namespace facebook;
19
+
20
+ /**
21
+ * Represents the Java/Kotlin callback `(from: Double, to: Double) -> Unit`.
22
+ * This can be passed around between C++ and Java/Kotlin.
23
+ */
24
+ struct JFunc_void_double_double: public jni::JavaClass<JFunc_void_double_double> {
25
+ public:
26
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/com/nitromarkdown/Func_void_double_double;";
27
+
28
+ public:
29
+ /**
30
+ * Invokes the function this `JFunc_void_double_double` instance holds through JNI.
31
+ */
32
+ void invoke(double from, double to) const {
33
+ static const auto method = javaClassStatic()->getMethod<void(double /* from */, double /* to */)>("invoke");
34
+ method(self(), from, to);
35
+ }
36
+ };
37
+
38
+ /**
39
+ * An implementation of Func_void_double_double that is backed by a C++ implementation (using `std::function<...>`)
40
+ */
41
+ class JFunc_void_double_double_cxx final: public jni::HybridClass<JFunc_void_double_double_cxx, JFunc_void_double_double> {
42
+ public:
43
+ static jni::local_ref<JFunc_void_double_double::javaobject> fromCpp(const std::function<void(double /* from */, double /* to */)>& func) {
44
+ return JFunc_void_double_double_cxx::newObjectCxxArgs(func);
45
+ }
46
+
47
+ public:
48
+ /**
49
+ * Invokes the C++ `std::function<...>` this `JFunc_void_double_double_cxx` instance holds.
50
+ */
51
+ void invoke_cxx(double from, double to) {
52
+ _func(from, to);
53
+ }
54
+
55
+ public:
56
+ [[nodiscard]]
57
+ inline const std::function<void(double /* from */, double /* to */)>& getFunction() const {
58
+ return _func;
59
+ }
60
+
61
+ public:
62
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/com/nitromarkdown/Func_void_double_double_cxx;";
63
+ static void registerNatives() {
64
+ registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_double_double_cxx::invoke_cxx)});
65
+ }
66
+
67
+ private:
68
+ explicit JFunc_void_double_double_cxx(const std::function<void(double /* from */, double /* to */)>& func): _func(func) { }
69
+
70
+ private:
71
+ friend HybridBase;
72
+ std::function<void(double /* from */, double /* to */)> _func;
73
+ };
74
+
75
+ } // namespace margelo::nitro::Markdown
@@ -13,70 +13,76 @@
13
13
  #include <functional>
14
14
  #include "JFunc_void.hpp"
15
15
  #include <NitroModules/JNICallable.hpp>
16
+ #include "JFunc_void_double_double.hpp"
16
17
 
17
18
  namespace margelo::nitro::Markdown {
18
19
 
19
- jni::local_ref<JHybridMarkdownSessionSpec::jhybriddata> JHybridMarkdownSessionSpec::initHybrid(jni::alias_ref<jhybridobject> jThis) {
20
- return makeCxxInstance(jThis);
21
- }
22
-
23
- void JHybridMarkdownSessionSpec::registerNatives() {
24
- registerHybrid({
25
- makeNativeMethod("initHybrid", JHybridMarkdownSessionSpec::initHybrid),
26
- });
20
+ std::shared_ptr<JHybridMarkdownSessionSpec> JHybridMarkdownSessionSpec::JavaPart::getJHybridMarkdownSessionSpec() {
21
+ auto hybridObject = JHybridObject::JavaPart::getJHybridObject();
22
+ auto castHybridObject = std::dynamic_pointer_cast<JHybridMarkdownSessionSpec>(hybridObject);
23
+ if (castHybridObject == nullptr) [[unlikely]] {
24
+ throw std::runtime_error("Failed to downcast JHybridObject to JHybridMarkdownSessionSpec!");
25
+ }
26
+ return castHybridObject;
27
27
  }
28
28
 
29
- size_t JHybridMarkdownSessionSpec::getExternalMemorySize() noexcept {
30
- static const auto method = javaClassStatic()->getMethod<jlong()>("getMemorySize");
31
- return method(_javaPart);
29
+ jni::local_ref<JHybridMarkdownSessionSpec::CxxPart::jhybriddata> JHybridMarkdownSessionSpec::CxxPart::initHybrid(jni::alias_ref<jhybridobject> jThis) {
30
+ return makeCxxInstance(jThis);
32
31
  }
33
32
 
34
- bool JHybridMarkdownSessionSpec::equals(const std::shared_ptr<HybridObject>& other) {
35
- if (auto otherCast = std::dynamic_pointer_cast<JHybridMarkdownSessionSpec>(other)) {
36
- return _javaPart == otherCast->_javaPart;
33
+ std::shared_ptr<JHybridObject> JHybridMarkdownSessionSpec::CxxPart::createHybridObject(const jni::local_ref<JHybridObject::JavaPart>& javaPart) {
34
+ auto castJavaPart = jni::dynamic_ref_cast<JHybridMarkdownSessionSpec::JavaPart>(javaPart);
35
+ if (castJavaPart == nullptr) [[unlikely]] {
36
+ throw std::runtime_error("Failed to cast JHybridObject::JavaPart to JHybridMarkdownSessionSpec::JavaPart!");
37
37
  }
38
- return false;
38
+ return std::make_shared<JHybridMarkdownSessionSpec>(castJavaPart);
39
39
  }
40
40
 
41
- void JHybridMarkdownSessionSpec::dispose() noexcept {
42
- static const auto method = javaClassStatic()->getMethod<void()>("dispose");
43
- method(_javaPart);
44
- }
45
-
46
- std::string JHybridMarkdownSessionSpec::toString() {
47
- static const auto method = javaClassStatic()->getMethod<jni::JString()>("toString");
48
- auto javaString = method(_javaPart);
49
- return javaString->toStdString();
41
+ void JHybridMarkdownSessionSpec::CxxPart::registerNatives() {
42
+ registerHybrid({
43
+ makeNativeMethod("initHybrid", JHybridMarkdownSessionSpec::CxxPart::initHybrid),
44
+ });
50
45
  }
51
46
 
52
47
  // Properties
53
48
  double JHybridMarkdownSessionSpec::getHighlightPosition() {
54
- static const auto method = javaClassStatic()->getMethod<double()>("getHighlightPosition");
49
+ static const auto method = _javaPart->javaClassStatic()->getMethod<double()>("getHighlightPosition");
55
50
  auto __result = method(_javaPart);
56
51
  return __result;
57
52
  }
58
53
  void JHybridMarkdownSessionSpec::setHighlightPosition(double highlightPosition) {
59
- static const auto method = javaClassStatic()->getMethod<void(double /* highlightPosition */)>("setHighlightPosition");
54
+ static const auto method = _javaPart->javaClassStatic()->getMethod<void(double /* highlightPosition */)>("setHighlightPosition");
60
55
  method(_javaPart, highlightPosition);
61
56
  }
62
57
 
63
58
  // Methods
64
- void JHybridMarkdownSessionSpec::append(const std::string& chunk) {
65
- static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* chunk */)>("append");
66
- method(_javaPart, jni::make_jstring(chunk));
59
+ double JHybridMarkdownSessionSpec::append(const std::string& chunk) {
60
+ static const auto method = _javaPart->javaClassStatic()->getMethod<double(jni::alias_ref<jni::JString> /* chunk */)>("append");
61
+ auto __result = method(_javaPart, jni::make_jstring(chunk));
62
+ return __result;
67
63
  }
68
64
  void JHybridMarkdownSessionSpec::clear() {
69
- static const auto method = javaClassStatic()->getMethod<void()>("clear");
65
+ static const auto method = _javaPart->javaClassStatic()->getMethod<void()>("clear");
70
66
  method(_javaPart);
71
67
  }
72
68
  std::string JHybridMarkdownSessionSpec::getAllText() {
73
- static const auto method = javaClassStatic()->getMethod<jni::local_ref<jni::JString>()>("getAllText");
69
+ static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<jni::JString>()>("getAllText");
70
+ auto __result = method(_javaPart);
71
+ return __result->toStdString();
72
+ }
73
+ double JHybridMarkdownSessionSpec::getLength() {
74
+ static const auto method = _javaPart->javaClassStatic()->getMethod<double()>("getLength");
74
75
  auto __result = method(_javaPart);
76
+ return __result;
77
+ }
78
+ std::string JHybridMarkdownSessionSpec::getTextRange(double from, double to) {
79
+ static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<jni::JString>(double /* from */, double /* to */)>("getTextRange");
80
+ auto __result = method(_javaPart, from, to);
75
81
  return __result->toStdString();
76
82
  }
77
- std::function<void()> JHybridMarkdownSessionSpec::addListener(const std::function<void()>& listener) {
78
- static const auto method = javaClassStatic()->getMethod<jni::local_ref<JFunc_void::javaobject>(jni::alias_ref<JFunc_void::javaobject> /* listener */)>("addListener_cxx");
79
- auto __result = method(_javaPart, JFunc_void_cxx::fromCpp(listener));
83
+ std::function<void()> JHybridMarkdownSessionSpec::addListener(const std::function<void(double /* from */, double /* to */)>& listener) {
84
+ static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JFunc_void::javaobject>(jni::alias_ref<JFunc_void_double_double::javaobject> /* listener */)>("addListener_cxx");
85
+ auto __result = method(_javaPart, JFunc_void_double_double_cxx::fromCpp(listener));
80
86
  return [&]() -> std::function<void()> {
81
87
  if (__result->isInstanceOf(JFunc_void_cxx::javaClassStatic())) [[likely]] {
82
88
  auto downcast = jni::static_ref_cast<JFunc_void_cxx::javaobject>(__result);
@@ -87,5 +93,14 @@ namespace margelo::nitro::Markdown {
87
93
  }
88
94
  }();
89
95
  }
96
+ void JHybridMarkdownSessionSpec::reset(const std::string& text) {
97
+ static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* text */)>("reset");
98
+ method(_javaPart, jni::make_jstring(text));
99
+ }
100
+ double JHybridMarkdownSessionSpec::replace(double from, double to, const std::string& text) {
101
+ static const auto method = _javaPart->javaClassStatic()->getMethod<double(double /* from */, double /* to */, jni::alias_ref<jni::JString> /* text */)>("replace");
102
+ auto __result = method(_javaPart, from, to, jni::make_jstring(text));
103
+ return __result;
104
+ }
90
105
 
91
106
  } // namespace margelo::nitro::Markdown
@@ -18,34 +18,33 @@ namespace margelo::nitro::Markdown {
18
18
 
19
19
  using namespace facebook;
20
20
 
21
- class JHybridMarkdownSessionSpec: public jni::HybridClass<JHybridMarkdownSessionSpec, JHybridObject>,
22
- public virtual HybridMarkdownSessionSpec {
21
+ class JHybridMarkdownSessionSpec: public virtual HybridMarkdownSessionSpec, public virtual JHybridObject {
23
22
  public:
24
- static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/com/nitromarkdown/HybridMarkdownSessionSpec;";
25
- static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis);
26
- static void registerNatives();
27
-
28
- protected:
29
- // C++ constructor (called from Java via `initHybrid()`)
30
- explicit JHybridMarkdownSessionSpec(jni::alias_ref<jhybridobject> jThis) :
31
- HybridObject(HybridMarkdownSessionSpec::TAG),
32
- HybridBase(jThis),
33
- _javaPart(jni::make_global(jThis)) {}
23
+ struct JavaPart: public jni::JavaClass<JavaPart, JHybridObject::JavaPart> {
24
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/com/nitromarkdown/HybridMarkdownSessionSpec;";
25
+ std::shared_ptr<JHybridMarkdownSessionSpec> getJHybridMarkdownSessionSpec();
26
+ };
27
+ struct CxxPart: public jni::HybridClass<CxxPart, JHybridObject::CxxPart> {
28
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/com/nitromarkdown/HybridMarkdownSessionSpec$CxxPart;";
29
+ static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis);
30
+ static void registerNatives();
31
+ using HybridBase::HybridBase;
32
+ protected:
33
+ std::shared_ptr<JHybridObject> createHybridObject(const jni::local_ref<JHybridObject::JavaPart>& javaPart) override;
34
+ };
34
35
 
35
36
  public:
37
+ explicit JHybridMarkdownSessionSpec(const jni::local_ref<JHybridMarkdownSessionSpec::JavaPart>& javaPart):
38
+ HybridObject(HybridMarkdownSessionSpec::TAG),
39
+ JHybridObject(javaPart),
40
+ _javaPart(jni::make_global(javaPart)) {}
36
41
  ~JHybridMarkdownSessionSpec() override {
37
42
  // Hermes GC can destroy JS objects on a non-JNI Thread.
38
43
  jni::ThreadScope::WithClassLoader([&] { _javaPart.reset(); });
39
44
  }
40
45
 
41
46
  public:
42
- size_t getExternalMemorySize() noexcept override;
43
- bool equals(const std::shared_ptr<HybridObject>& other) override;
44
- void dispose() noexcept override;
45
- std::string toString() override;
46
-
47
- public:
48
- inline const jni::global_ref<JHybridMarkdownSessionSpec::javaobject>& getJavaPart() const noexcept {
47
+ inline const jni::global_ref<JHybridMarkdownSessionSpec::JavaPart>& getJavaPart() const noexcept {
49
48
  return _javaPart;
50
49
  }
51
50
 
@@ -56,15 +55,17 @@ namespace margelo::nitro::Markdown {
56
55
 
57
56
  public:
58
57
  // Methods
59
- void append(const std::string& chunk) override;
58
+ double append(const std::string& chunk) override;
60
59
  void clear() override;
61
60
  std::string getAllText() override;
62
- std::function<void()> addListener(const std::function<void()>& listener) override;
61
+ double getLength() override;
62
+ std::string getTextRange(double from, double to) override;
63
+ std::function<void()> addListener(const std::function<void(double /* from */, double /* to */)>& listener) override;
64
+ void reset(const std::string& text) override;
65
+ double replace(double from, double to, const std::string& text) override;
63
66
 
64
67
  private:
65
- friend HybridBase;
66
- using HybridBase::HybridBase;
67
- jni::global_ref<JHybridMarkdownSessionSpec::javaobject> _javaPart;
68
+ jni::global_ref<JHybridMarkdownSessionSpec::JavaPart> _javaPart;
68
69
  };
69
70
 
70
71
  } // namespace margelo::nitro::Markdown
@@ -0,0 +1,80 @@
1
+ ///
2
+ /// Func_void_double_double.kt
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ package com.margelo.nitro.com.nitromarkdown
9
+
10
+ import androidx.annotation.Keep
11
+ import com.facebook.jni.HybridData
12
+ import com.facebook.proguard.annotations.DoNotStrip
13
+ import dalvik.annotation.optimization.FastNative
14
+
15
+
16
+ /**
17
+ * Represents the JavaScript callback `(from: number, to: number) => void`.
18
+ * This can be either implemented in C++ (in which case it might be a callback coming from JS),
19
+ * or in Kotlin/Java (in which case it is a native callback).
20
+ */
21
+ @DoNotStrip
22
+ @Keep
23
+ @Suppress("ClassName", "RedundantUnitReturnType")
24
+ fun interface Func_void_double_double: (Double, Double) -> Unit {
25
+ /**
26
+ * Call the given JS callback.
27
+ * @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted.
28
+ */
29
+ @DoNotStrip
30
+ @Keep
31
+ override fun invoke(from: Double, to: Double): Unit
32
+ }
33
+
34
+ /**
35
+ * Represents the JavaScript callback `(from: number, to: number) => void`.
36
+ * This is implemented in C++, via a `std::function<...>`.
37
+ * The callback might be coming from JS.
38
+ */
39
+ @DoNotStrip
40
+ @Keep
41
+ @Suppress(
42
+ "KotlinJniMissingFunction", "unused",
43
+ "RedundantSuppression", "RedundantUnitReturnType", "FunctionName",
44
+ "ConvertSecondaryConstructorToPrimary", "ClassName", "LocalVariableName",
45
+ )
46
+ class Func_void_double_double_cxx: Func_void_double_double {
47
+ @DoNotStrip
48
+ @Keep
49
+ private val mHybridData: HybridData
50
+
51
+ @DoNotStrip
52
+ @Keep
53
+ private constructor(hybridData: HybridData) {
54
+ mHybridData = hybridData
55
+ }
56
+
57
+ @DoNotStrip
58
+ @Keep
59
+ override fun invoke(from: Double, to: Double): Unit
60
+ = invoke_cxx(from,to)
61
+
62
+ @FastNative
63
+ private external fun invoke_cxx(from: Double, to: Double): Unit
64
+ }
65
+
66
+ /**
67
+ * Represents the JavaScript callback `(from: number, to: number) => void`.
68
+ * This is implemented in Java/Kotlin, via a `(Double, Double) -> Unit`.
69
+ * The callback is always coming from native.
70
+ */
71
+ @DoNotStrip
72
+ @Keep
73
+ @Suppress("ClassName", "RedundantUnitReturnType", "unused")
74
+ class Func_void_double_double_java(private val function: (Double, Double) -> Unit): Func_void_double_double {
75
+ @DoNotStrip
76
+ @Keep
77
+ override fun invoke(from: Double, to: Double): Unit {
78
+ return this.function(from, to)
79
+ }
80
+ }
@@ -24,23 +24,6 @@ import com.margelo.nitro.core.HybridObject
24
24
  "LocalVariableName", "PropertyName", "PrivatePropertyName", "FunctionName"
25
25
  )
26
26
  abstract class HybridMarkdownSessionSpec: HybridObject() {
27
- @DoNotStrip
28
- private var mHybridData: HybridData = initHybrid()
29
-
30
- init {
31
- super.updateNative(mHybridData)
32
- }
33
-
34
- override fun updateNative(hybridData: HybridData) {
35
- mHybridData = hybridData
36
- super.updateNative(hybridData)
37
- }
38
-
39
- // Default implementation of `HybridObject.toString()`
40
- override fun toString(): String {
41
- return "[HybridObject MarkdownSession]"
42
- }
43
-
44
27
  // Properties
45
28
  @get:DoNotStrip
46
29
  @get:Keep
@@ -51,7 +34,7 @@ abstract class HybridMarkdownSessionSpec: HybridObject() {
51
34
  // Methods
52
35
  @DoNotStrip
53
36
  @Keep
54
- abstract fun append(chunk: String): Unit
37
+ abstract fun append(chunk: String): Double
55
38
 
56
39
  @DoNotStrip
57
40
  @Keep
@@ -61,16 +44,46 @@ abstract class HybridMarkdownSessionSpec: HybridObject() {
61
44
  @Keep
62
45
  abstract fun getAllText(): String
63
46
 
64
- abstract fun addListener(listener: () -> Unit): () -> Unit
47
+ @DoNotStrip
48
+ @Keep
49
+ abstract fun getLength(): Double
50
+
51
+ @DoNotStrip
52
+ @Keep
53
+ abstract fun getTextRange(from: Double, to: Double): String
54
+
55
+ abstract fun addListener(listener: (from: Double, to: Double) -> Unit): () -> Unit
65
56
 
66
57
  @DoNotStrip
67
58
  @Keep
68
- private fun addListener_cxx(listener: Func_void): Func_void {
59
+ private fun addListener_cxx(listener: Func_void_double_double): Func_void {
69
60
  val __result = addListener(listener)
70
61
  return Func_void_java(__result)
71
62
  }
63
+
64
+ @DoNotStrip
65
+ @Keep
66
+ abstract fun reset(text: String): Unit
67
+
68
+ @DoNotStrip
69
+ @Keep
70
+ abstract fun replace(from: Double, to: Double, text: String): Double
71
+
72
+ // Default implementation of `HybridObject.toString()`
73
+ override fun toString(): String {
74
+ return "[HybridObject MarkdownSession]"
75
+ }
72
76
 
73
- private external fun initHybrid(): HybridData
77
+ // C++ backing class
78
+ @DoNotStrip
79
+ @Keep
80
+ protected open class CxxPart(javaPart: HybridMarkdownSessionSpec): HybridObject.CxxPart(javaPart) {
81
+ // C++ JHybridMarkdownSessionSpec::CxxPart::initHybrid(...)
82
+ external override fun initHybrid(): HybridData
83
+ }
84
+ override fun createCxxPart(): CxxPart {
85
+ return CxxPart(this)
86
+ }
74
87
 
75
88
  companion object {
76
89
  protected const val TAG = "HybridMarkdownSessionSpec"
@@ -22,6 +22,14 @@ namespace margelo::nitro::Markdown::bridge::swift {
22
22
  };
23
23
  }
24
24
 
25
+ // pragma MARK: std::function<void(double /* from */, double /* to */)>
26
+ Func_void_double_double create_Func_void_double_double(void* NON_NULL swiftClosureWrapper) noexcept {
27
+ auto swiftClosure = NitroMarkdown::Func_void_double_double::fromUnsafe(swiftClosureWrapper);
28
+ return [swiftClosure = std::move(swiftClosure)](double from, double to) mutable -> void {
29
+ swiftClosure.call(from, to);
30
+ };
31
+ }
32
+
25
33
  // pragma MARK: std::shared_ptr<HybridMarkdownSessionSpec>
26
34
  std::shared_ptr<HybridMarkdownSessionSpec> create_std__shared_ptr_HybridMarkdownSessionSpec_(void* NON_NULL swiftUnsafePointer) noexcept {
27
35
  NitroMarkdown::HybridMarkdownSessionSpec_cxx swiftPart = NitroMarkdown::HybridMarkdownSessionSpec_cxx::fromUnsafe(swiftUnsafePointer);
@@ -51,6 +51,28 @@ namespace margelo::nitro::Markdown::bridge::swift {
51
51
  return Func_void_Wrapper(std::move(value));
52
52
  }
53
53
 
54
+ // pragma MARK: std::function<void(double /* from */, double /* to */)>
55
+ /**
56
+ * Specialized version of `std::function<void(double, double)>`.
57
+ */
58
+ using Func_void_double_double = std::function<void(double /* from */, double /* to */)>;
59
+ /**
60
+ * Wrapper class for a `std::function<void(double / * from * /, double / * to * /)>`, this can be used from Swift.
61
+ */
62
+ class Func_void_double_double_Wrapper final {
63
+ public:
64
+ explicit Func_void_double_double_Wrapper(std::function<void(double /* from */, double /* to */)>&& func): _function(std::make_unique<std::function<void(double /* from */, double /* to */)>>(std::move(func))) {}
65
+ inline void call(double from, double to) const noexcept {
66
+ _function->operator()(from, to);
67
+ }
68
+ private:
69
+ std::unique_ptr<std::function<void(double /* from */, double /* to */)>> _function;
70
+ } SWIFT_NONCOPYABLE;
71
+ Func_void_double_double create_Func_void_double_double(void* NON_NULL swiftClosureWrapper) noexcept;
72
+ inline Func_void_double_double_Wrapper wrap_Func_void_double_double(Func_void_double_double value) noexcept {
73
+ return Func_void_double_double_Wrapper(std::move(value));
74
+ }
75
+
54
76
  // pragma MARK: std::shared_ptr<HybridMarkdownSessionSpec>
55
77
  /**
56
78
  * Specialized version of `std::shared_ptr<HybridMarkdownSessionSpec>`.
@@ -63,6 +85,15 @@ namespace margelo::nitro::Markdown::bridge::swift {
63
85
  using std__weak_ptr_HybridMarkdownSessionSpec_ = std::weak_ptr<HybridMarkdownSessionSpec>;
64
86
  inline std__weak_ptr_HybridMarkdownSessionSpec_ weakify_std__shared_ptr_HybridMarkdownSessionSpec_(const std::shared_ptr<HybridMarkdownSessionSpec>& strong) noexcept { return strong; }
65
87
 
88
+ // pragma MARK: Result<double>
89
+ using Result_double_ = Result<double>;
90
+ inline Result_double_ create_Result_double_(double value) noexcept {
91
+ return Result<double>::withValue(std::move(value));
92
+ }
93
+ inline Result_double_ create_Result_double_(const std::exception_ptr& error) noexcept {
94
+ return Result<double>::withError(error);
95
+ }
96
+
66
97
  // pragma MARK: Result<void>
67
98
  using Result_void_ = Result<void>;
68
99
  inline Result_void_ create_Result_void_() noexcept {