react-native-nitro-markdown 0.1.2 → 0.3.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.
- package/LICENSE +21 -0
- package/README.md +293 -119
- package/android/src/main/cpp/cpp-adapter.cpp +1 -1
- package/android/src/main/java/com/margelo/nitro/com/nitromarkdown/HybridMarkdownSession.kt +61 -0
- package/android/src/main/java/com/nitromarkdown/NitroMarkdownPackage.kt +5 -1
- package/cpp/bindings/HybridMarkdownParser.cpp +2 -2
- package/cpp/bindings/HybridMarkdownParser.hpp +2 -2
- package/cpp/bindings/HybridMarkdownSession.cpp +0 -0
- package/cpp/core/MarkdownSessionCore.cpp +0 -0
- package/ios/HybridMarkdownSession.swift +64 -0
- package/lib/commonjs/MarkdownContext.js +17 -0
- package/lib/commonjs/MarkdownContext.js.map +1 -0
- package/lib/commonjs/MarkdownSession.js +11 -0
- package/lib/commonjs/MarkdownSession.js.map +1 -0
- package/lib/commonjs/default-markdown-renderer.js +217 -0
- package/lib/commonjs/default-markdown-renderer.js.map +1 -0
- package/lib/commonjs/headless.js +61 -0
- package/lib/commonjs/headless.js.map +1 -0
- package/lib/commonjs/index.js +220 -13
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/markdown-stream.js +32 -0
- package/lib/commonjs/markdown-stream.js.map +1 -0
- package/lib/commonjs/markdown.js +377 -0
- package/lib/commonjs/markdown.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/renderers/blockquote.js +36 -0
- package/lib/commonjs/renderers/blockquote.js.map +1 -0
- package/lib/commonjs/renderers/code.js +99 -0
- package/lib/commonjs/renderers/code.js.map +1 -0
- package/lib/commonjs/renderers/heading.js +63 -0
- package/lib/commonjs/renderers/heading.js.map +1 -0
- package/lib/commonjs/renderers/horizontal-rule.js +29 -0
- package/lib/commonjs/renderers/horizontal-rule.js.map +1 -0
- package/lib/commonjs/renderers/image.js +163 -0
- package/lib/commonjs/renderers/image.js.map +1 -0
- package/lib/commonjs/renderers/link.js +35 -0
- package/lib/commonjs/renderers/link.js.map +1 -0
- package/lib/commonjs/renderers/list.js +118 -0
- package/lib/commonjs/renderers/list.js.map +1 -0
- package/lib/commonjs/renderers/math.js +127 -0
- package/lib/commonjs/renderers/math.js.map +1 -0
- package/lib/commonjs/renderers/paragraph.js +39 -0
- package/lib/commonjs/renderers/paragraph.js.map +1 -0
- package/lib/commonjs/renderers/table.js +290 -0
- package/lib/commonjs/renderers/table.js.map +1 -0
- package/lib/commonjs/specs/MarkdownSession.nitro.js +6 -0
- package/lib/commonjs/specs/MarkdownSession.nitro.js.map +1 -0
- package/lib/commonjs/theme.js +191 -0
- package/lib/commonjs/theme.js.map +1 -0
- package/lib/commonjs/use-markdown-stream.js +71 -0
- package/lib/commonjs/use-markdown-stream.js.map +1 -0
- package/lib/module/MarkdownContext.js +12 -0
- package/lib/module/MarkdownContext.js.map +1 -0
- package/lib/module/MarkdownSession.js +7 -0
- package/lib/module/MarkdownSession.js.map +1 -0
- package/lib/module/default-markdown-renderer.js +212 -0
- package/lib/module/default-markdown-renderer.js.map +1 -0
- package/lib/module/headless.js +54 -0
- package/lib/module/headless.js.map +1 -0
- package/lib/module/index.js +18 -10
- package/lib/module/index.js.map +1 -1
- package/lib/module/markdown-stream.js +27 -0
- package/lib/module/markdown-stream.js.map +1 -0
- package/lib/module/markdown.js +372 -0
- package/lib/module/markdown.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/renderers/blockquote.js +31 -0
- package/lib/module/renderers/blockquote.js.map +1 -0
- package/lib/module/renderers/code.js +93 -0
- package/lib/module/renderers/code.js.map +1 -0
- package/lib/module/renderers/heading.js +58 -0
- package/lib/module/renderers/heading.js.map +1 -0
- package/lib/module/renderers/horizontal-rule.js +24 -0
- package/lib/module/renderers/horizontal-rule.js.map +1 -0
- package/lib/module/renderers/image.js +158 -0
- package/lib/module/renderers/image.js.map +1 -0
- package/lib/module/renderers/link.js +30 -0
- package/lib/module/renderers/link.js.map +1 -0
- package/lib/module/renderers/list.js +111 -0
- package/lib/module/renderers/list.js.map +1 -0
- package/lib/module/renderers/math.js +121 -0
- package/lib/module/renderers/math.js.map +1 -0
- package/lib/module/renderers/paragraph.js +34 -0
- package/lib/module/renderers/paragraph.js.map +1 -0
- package/lib/module/renderers/table.js +285 -0
- package/lib/module/renderers/table.js.map +1 -0
- package/lib/module/specs/MarkdownSession.nitro.js +4 -0
- package/lib/module/specs/MarkdownSession.nitro.js.map +1 -0
- package/lib/module/theme.js +186 -0
- package/lib/module/theme.js.map +1 -0
- package/lib/module/use-markdown-stream.js +66 -0
- package/lib/module/use-markdown-stream.js.map +1 -0
- package/lib/typescript/commonjs/Markdown.nitro.d.ts.map +1 -0
- package/lib/typescript/commonjs/MarkdownContext.d.ts +65 -0
- package/lib/typescript/commonjs/MarkdownContext.d.ts.map +1 -0
- package/lib/typescript/commonjs/MarkdownSession.d.ts +4 -0
- package/lib/typescript/commonjs/MarkdownSession.d.ts.map +1 -0
- package/lib/typescript/commonjs/default-markdown-renderer.d.ts +10 -0
- package/lib/typescript/commonjs/default-markdown-renderer.d.ts.map +1 -0
- package/lib/typescript/commonjs/headless.d.ts +57 -0
- package/lib/typescript/commonjs/headless.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +22 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/markdown-stream.d.ts +15 -0
- package/lib/typescript/commonjs/markdown-stream.d.ts.map +1 -0
- package/lib/typescript/commonjs/markdown.d.ts +47 -0
- package/lib/typescript/commonjs/markdown.d.ts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/renderers/blockquote.d.ts +9 -0
- package/lib/typescript/commonjs/renderers/blockquote.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/code.d.ts +19 -0
- package/lib/typescript/commonjs/renderers/code.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/heading.d.ts +10 -0
- package/lib/typescript/commonjs/renderers/heading.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/horizontal-rule.d.ts +8 -0
- package/lib/typescript/commonjs/renderers/horizontal-rule.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/image.d.ts +13 -0
- package/lib/typescript/commonjs/renderers/image.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/link.d.ts +10 -0
- package/lib/typescript/commonjs/renderers/link.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/list.d.ts +26 -0
- package/lib/typescript/commonjs/renderers/list.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/math.d.ts +14 -0
- package/lib/typescript/commonjs/renderers/math.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/paragraph.d.ts +10 -0
- package/lib/typescript/commonjs/renderers/paragraph.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/table.d.ts +12 -0
- package/lib/typescript/commonjs/renderers/table.d.ts.map +1 -0
- package/lib/typescript/commonjs/specs/MarkdownSession.nitro.d.ts +12 -0
- package/lib/typescript/commonjs/specs/MarkdownSession.nitro.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme.d.ts +65 -0
- package/lib/typescript/commonjs/theme.d.ts.map +1 -0
- package/lib/typescript/commonjs/use-markdown-stream.d.ts +22 -0
- package/lib/typescript/commonjs/use-markdown-stream.d.ts.map +1 -0
- package/lib/typescript/module/Markdown.nitro.d.ts +13 -0
- package/lib/typescript/module/Markdown.nitro.d.ts.map +1 -0
- package/lib/typescript/module/MarkdownContext.d.ts +65 -0
- package/lib/typescript/module/MarkdownContext.d.ts.map +1 -0
- package/lib/typescript/module/MarkdownSession.d.ts +4 -0
- package/lib/typescript/module/MarkdownSession.d.ts.map +1 -0
- package/lib/typescript/module/default-markdown-renderer.d.ts +10 -0
- package/lib/typescript/module/default-markdown-renderer.d.ts.map +1 -0
- package/lib/typescript/module/headless.d.ts +57 -0
- package/lib/typescript/module/headless.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +22 -0
- package/lib/typescript/module/index.d.ts.map +1 -0
- package/lib/typescript/module/markdown-stream.d.ts +15 -0
- package/lib/typescript/module/markdown-stream.d.ts.map +1 -0
- package/lib/typescript/module/markdown.d.ts +47 -0
- package/lib/typescript/module/markdown.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/renderers/blockquote.d.ts +9 -0
- package/lib/typescript/module/renderers/blockquote.d.ts.map +1 -0
- package/lib/typescript/module/renderers/code.d.ts +19 -0
- package/lib/typescript/module/renderers/code.d.ts.map +1 -0
- package/lib/typescript/module/renderers/heading.d.ts +10 -0
- package/lib/typescript/module/renderers/heading.d.ts.map +1 -0
- package/lib/typescript/module/renderers/horizontal-rule.d.ts +8 -0
- package/lib/typescript/module/renderers/horizontal-rule.d.ts.map +1 -0
- package/lib/typescript/module/renderers/image.d.ts +13 -0
- package/lib/typescript/module/renderers/image.d.ts.map +1 -0
- package/lib/typescript/module/renderers/link.d.ts +10 -0
- package/lib/typescript/module/renderers/link.d.ts.map +1 -0
- package/lib/typescript/module/renderers/list.d.ts +26 -0
- package/lib/typescript/module/renderers/list.d.ts.map +1 -0
- package/lib/typescript/module/renderers/math.d.ts +14 -0
- package/lib/typescript/module/renderers/math.d.ts.map +1 -0
- package/lib/typescript/module/renderers/paragraph.d.ts +10 -0
- package/lib/typescript/module/renderers/paragraph.d.ts.map +1 -0
- package/lib/typescript/module/renderers/table.d.ts +12 -0
- package/lib/typescript/module/renderers/table.d.ts.map +1 -0
- package/lib/typescript/module/specs/MarkdownSession.nitro.d.ts +12 -0
- package/lib/typescript/module/specs/MarkdownSession.nitro.d.ts.map +1 -0
- package/lib/typescript/module/theme.d.ts +65 -0
- package/lib/typescript/module/theme.d.ts.map +1 -0
- package/lib/typescript/module/use-markdown-stream.d.ts +22 -0
- package/lib/typescript/module/use-markdown-stream.d.ts.map +1 -0
- package/nitro.json +5 -2
- package/nitrogen/generated/android/NitroMarkdown+autolinking.cmake +3 -2
- package/nitrogen/generated/android/NitroMarkdown+autolinking.gradle +1 -1
- package/nitrogen/generated/android/NitroMarkdownOnLoad.cpp +17 -5
- package/nitrogen/generated/android/NitroMarkdownOnLoad.hpp +4 -4
- package/nitrogen/generated/android/c++/JFunc_void.hpp +75 -0
- package/nitrogen/generated/android/c++/JHybridMarkdownSessionSpec.cpp +91 -0
- package/nitrogen/generated/android/c++/JHybridMarkdownSessionSpec.hpp +70 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/com/nitromarkdown/Func_void.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/com/nitromarkdown/HybridMarkdownSessionSpec.kt +78 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/com/nitromarkdown/NitroMarkdownOnLoad.kt +1 -1
- package/nitrogen/generated/ios/NitroMarkdown+autolinking.rb +2 -2
- package/nitrogen/generated/ios/NitroMarkdown-Swift-Cxx-Bridge.cpp +28 -4
- package/nitrogen/generated/ios/NitroMarkdown-Swift-Cxx-Bridge.hpp +72 -6
- package/nitrogen/generated/ios/NitroMarkdown-Swift-Cxx-Umbrella.hpp +11 -4
- package/nitrogen/generated/ios/NitroMarkdownAutolinking.mm +11 -3
- package/nitrogen/generated/ios/NitroMarkdownAutolinking.swift +16 -3
- package/nitrogen/generated/ios/c++/HybridMarkdownSessionSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridMarkdownSessionSpecSwift.hpp +108 -0
- package/nitrogen/generated/ios/swift/Func_void.swift +47 -0
- package/nitrogen/generated/ios/swift/HybridMarkdownSessionSpec.swift +59 -0
- package/nitrogen/generated/ios/swift/HybridMarkdownSessionSpec_cxx.swift +190 -0
- package/nitrogen/generated/shared/c++/HybridMarkdownParserSpec.cpp +3 -3
- package/nitrogen/generated/shared/c++/HybridMarkdownParserSpec.hpp +4 -4
- package/nitrogen/generated/shared/c++/HybridMarkdownSessionSpec.cpp +26 -0
- package/nitrogen/generated/shared/c++/HybridMarkdownSessionSpec.hpp +67 -0
- package/nitrogen/generated/shared/c++/ParserOptions.hpp +22 -14
- package/package.json +45 -7
- package/react-native-nitro-markdown.podspec +5 -5
- package/src/MarkdownContext.ts +98 -0
- package/src/MarkdownSession.ts +8 -0
- package/src/default-markdown-renderer.tsx +261 -0
- package/src/headless.ts +116 -0
- package/src/index.ts +47 -60
- package/src/markdown-stream.tsx +32 -0
- package/src/markdown.tsx +497 -0
- package/src/renderers/blockquote.tsx +30 -0
- package/src/renderers/code.tsx +112 -0
- package/src/renderers/heading.tsx +66 -0
- package/src/renderers/horizontal-rule.tsx +23 -0
- package/src/renderers/image.tsx +175 -0
- package/src/renderers/link.tsx +33 -0
- package/src/renderers/list.tsx +131 -0
- package/src/renderers/math.tsx +141 -0
- package/src/renderers/paragraph.tsx +47 -0
- package/src/renderers/table.tsx +370 -0
- package/src/specs/MarkdownSession.nitro.ts +16 -0
- package/src/theme.ts +243 -0
- package/src/use-markdown-stream.ts +83 -0
- package/ios/NitroMarkdown-Bridging-Header.h +0 -14
- package/lib/commonjs/MarkdownJS.reference.js +0 -114
- package/lib/commonjs/MarkdownJS.reference.js.map +0 -1
- package/lib/module/MarkdownJS.reference.js +0 -107
- package/lib/module/MarkdownJS.reference.js.map +0 -1
- package/lib/typescript/Markdown.nitro.d.ts.map +0 -1
- package/lib/typescript/MarkdownJS.reference.d.ts +0 -33
- package/lib/typescript/MarkdownJS.reference.d.ts.map +0 -1
- package/lib/typescript/index.d.ts +0 -22
- package/lib/typescript/index.d.ts.map +0 -1
- package/src/MarkdownJS.reference.ts +0 -122
- /package/lib/typescript/{Markdown.nitro.d.ts → commonjs/Markdown.nitro.d.ts} +0 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridMarkdownSessionSpecSwift.cpp
|
|
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
|
+
#include "HybridMarkdownSessionSpecSwift.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::Markdown {
|
|
11
|
+
} // namespace margelo::nitro::Markdown
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridMarkdownSessionSpecSwift.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 "HybridMarkdownSessionSpec.hpp"
|
|
11
|
+
|
|
12
|
+
// Forward declaration of `HybridMarkdownSessionSpec_cxx` to properly resolve imports.
|
|
13
|
+
namespace NitroMarkdown { class HybridMarkdownSessionSpec_cxx; }
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
#include <string>
|
|
18
|
+
#include <functional>
|
|
19
|
+
|
|
20
|
+
#include "NitroMarkdown-Swift-Cxx-Umbrella.hpp"
|
|
21
|
+
|
|
22
|
+
namespace margelo::nitro::Markdown {
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The C++ part of HybridMarkdownSessionSpec_cxx.swift.
|
|
26
|
+
*
|
|
27
|
+
* HybridMarkdownSessionSpecSwift (C++) accesses HybridMarkdownSessionSpec_cxx (Swift), and might
|
|
28
|
+
* contain some additional bridging code for C++ <> Swift interop.
|
|
29
|
+
*
|
|
30
|
+
* Since this obviously introduces an overhead, I hope at some point in
|
|
31
|
+
* the future, HybridMarkdownSessionSpec_cxx can directly inherit from the C++ class HybridMarkdownSessionSpec
|
|
32
|
+
* to simplify the whole structure and memory management.
|
|
33
|
+
*/
|
|
34
|
+
class HybridMarkdownSessionSpecSwift: public virtual HybridMarkdownSessionSpec {
|
|
35
|
+
public:
|
|
36
|
+
// Constructor from a Swift instance
|
|
37
|
+
explicit HybridMarkdownSessionSpecSwift(const NitroMarkdown::HybridMarkdownSessionSpec_cxx& swiftPart):
|
|
38
|
+
HybridObject(HybridMarkdownSessionSpec::TAG),
|
|
39
|
+
_swiftPart(swiftPart) { }
|
|
40
|
+
|
|
41
|
+
public:
|
|
42
|
+
// Get the Swift part
|
|
43
|
+
inline NitroMarkdown::HybridMarkdownSessionSpec_cxx& getSwiftPart() noexcept {
|
|
44
|
+
return _swiftPart;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public:
|
|
48
|
+
inline size_t getExternalMemorySize() noexcept override {
|
|
49
|
+
return _swiftPart.getMemorySize();
|
|
50
|
+
}
|
|
51
|
+
bool equals(const std::shared_ptr<HybridObject>& other) override {
|
|
52
|
+
if (auto otherCast = std::dynamic_pointer_cast<HybridMarkdownSessionSpecSwift>(other)) {
|
|
53
|
+
return _swiftPart.equals(otherCast->_swiftPart);
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
void dispose() noexcept override {
|
|
58
|
+
_swiftPart.dispose();
|
|
59
|
+
}
|
|
60
|
+
std::string toString() override {
|
|
61
|
+
return _swiftPart.toString();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public:
|
|
65
|
+
// Properties
|
|
66
|
+
inline double getHighlightPosition() noexcept override {
|
|
67
|
+
return _swiftPart.getHighlightPosition();
|
|
68
|
+
}
|
|
69
|
+
inline void setHighlightPosition(double highlightPosition) noexcept override {
|
|
70
|
+
_swiftPart.setHighlightPosition(std::forward<decltype(highlightPosition)>(highlightPosition));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public:
|
|
74
|
+
// Methods
|
|
75
|
+
inline void append(const std::string& chunk) override {
|
|
76
|
+
auto __result = _swiftPart.append(chunk);
|
|
77
|
+
if (__result.hasError()) [[unlikely]] {
|
|
78
|
+
std::rethrow_exception(__result.error());
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
inline void clear() override {
|
|
82
|
+
auto __result = _swiftPart.clear();
|
|
83
|
+
if (__result.hasError()) [[unlikely]] {
|
|
84
|
+
std::rethrow_exception(__result.error());
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
inline std::string getAllText() override {
|
|
88
|
+
auto __result = _swiftPart.getAllText();
|
|
89
|
+
if (__result.hasError()) [[unlikely]] {
|
|
90
|
+
std::rethrow_exception(__result.error());
|
|
91
|
+
}
|
|
92
|
+
auto __value = std::move(__result.value());
|
|
93
|
+
return __value;
|
|
94
|
+
}
|
|
95
|
+
inline std::function<void()> addListener(const std::function<void()>& listener) override {
|
|
96
|
+
auto __result = _swiftPart.addListener(listener);
|
|
97
|
+
if (__result.hasError()) [[unlikely]] {
|
|
98
|
+
std::rethrow_exception(__result.error());
|
|
99
|
+
}
|
|
100
|
+
auto __value = std::move(__result.value());
|
|
101
|
+
return __value;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private:
|
|
105
|
+
NitroMarkdown::HybridMarkdownSessionSpec_cxx _swiftPart;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
} // namespace margelo::nitro::Markdown
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_void.swift
|
|
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
|
+
import Foundation
|
|
9
|
+
import NitroModules
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Wraps a Swift `() -> Void` as a class.
|
|
13
|
+
* This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
|
|
14
|
+
*/
|
|
15
|
+
public final class Func_void {
|
|
16
|
+
public typealias bridge = margelo.nitro.Markdown.bridge.swift
|
|
17
|
+
|
|
18
|
+
private let closure: () -> Void
|
|
19
|
+
|
|
20
|
+
public init(_ closure: @escaping () -> Void) {
|
|
21
|
+
self.closure = closure
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@inline(__always)
|
|
25
|
+
public func call() -> Void {
|
|
26
|
+
self.closure()
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
31
|
+
* This acquires one additional strong reference on the object!
|
|
32
|
+
*/
|
|
33
|
+
@inline(__always)
|
|
34
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
35
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Casts an unsafe pointer to a `Func_void`.
|
|
40
|
+
* The pointer has to be a retained opaque `Unmanaged<Func_void>`.
|
|
41
|
+
* This removes one strong reference from the object!
|
|
42
|
+
*/
|
|
43
|
+
@inline(__always)
|
|
44
|
+
public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void {
|
|
45
|
+
return Unmanaged<Func_void>.fromOpaque(pointer).takeRetainedValue()
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridMarkdownSessionSpec.swift
|
|
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
|
+
import Foundation
|
|
9
|
+
import NitroModules
|
|
10
|
+
|
|
11
|
+
/// See ``HybridMarkdownSessionSpec``
|
|
12
|
+
public protocol HybridMarkdownSessionSpec_protocol: HybridObject {
|
|
13
|
+
// Properties
|
|
14
|
+
var highlightPosition: Double { get set }
|
|
15
|
+
|
|
16
|
+
// Methods
|
|
17
|
+
func append(chunk: String) throws -> Void
|
|
18
|
+
func clear() throws -> Void
|
|
19
|
+
func getAllText() throws -> String
|
|
20
|
+
func addListener(listener: @escaping () -> Void) throws -> () -> Void
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public extension HybridMarkdownSessionSpec_protocol {
|
|
24
|
+
/// Default implementation of ``HybridObject.toString``
|
|
25
|
+
func toString() -> String {
|
|
26
|
+
return "[HybridObject MarkdownSession]"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/// See ``HybridMarkdownSessionSpec``
|
|
31
|
+
open class HybridMarkdownSessionSpec_base {
|
|
32
|
+
private weak var cxxWrapper: HybridMarkdownSessionSpec_cxx? = nil
|
|
33
|
+
public init() { }
|
|
34
|
+
public func getCxxWrapper() -> HybridMarkdownSessionSpec_cxx {
|
|
35
|
+
#if DEBUG
|
|
36
|
+
guard self is HybridMarkdownSessionSpec else {
|
|
37
|
+
fatalError("`self` is not a `HybridMarkdownSessionSpec`! Did you accidentally inherit from `HybridMarkdownSessionSpec_base` instead of `HybridMarkdownSessionSpec`?")
|
|
38
|
+
}
|
|
39
|
+
#endif
|
|
40
|
+
if let cxxWrapper = self.cxxWrapper {
|
|
41
|
+
return cxxWrapper
|
|
42
|
+
} else {
|
|
43
|
+
let cxxWrapper = HybridMarkdownSessionSpec_cxx(self as! HybridMarkdownSessionSpec)
|
|
44
|
+
self.cxxWrapper = cxxWrapper
|
|
45
|
+
return cxxWrapper
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* A Swift base-protocol representing the MarkdownSession HybridObject.
|
|
52
|
+
* Implement this protocol to create Swift-based instances of MarkdownSession.
|
|
53
|
+
* ```swift
|
|
54
|
+
* class HybridMarkdownSession : HybridMarkdownSessionSpec {
|
|
55
|
+
* // ...
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
public typealias HybridMarkdownSessionSpec = HybridMarkdownSessionSpec_protocol & HybridMarkdownSessionSpec_base
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridMarkdownSessionSpec_cxx.swift
|
|
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
|
+
import Foundation
|
|
9
|
+
import NitroModules
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A class implementation that bridges HybridMarkdownSessionSpec over to C++.
|
|
13
|
+
* In C++, we cannot use Swift protocols - so we need to wrap it in a class to make it strongly defined.
|
|
14
|
+
*
|
|
15
|
+
* Also, some Swift types need to be bridged with special handling:
|
|
16
|
+
* - Enums need to be wrapped in Structs, otherwise they cannot be accessed bi-directionally (Swift bug: https://github.com/swiftlang/swift/issues/75330)
|
|
17
|
+
* - Other HybridObjects need to be wrapped/unwrapped from the Swift TCxx wrapper
|
|
18
|
+
* - Throwing methods need to be wrapped with a Result<T, Error> type, as exceptions cannot be propagated to C++
|
|
19
|
+
*/
|
|
20
|
+
open class HybridMarkdownSessionSpec_cxx {
|
|
21
|
+
/**
|
|
22
|
+
* The Swift <> C++ bridge's namespace (`margelo::nitro::Markdown::bridge::swift`)
|
|
23
|
+
* from `NitroMarkdown-Swift-Cxx-Bridge.hpp`.
|
|
24
|
+
* This contains specialized C++ templates, and C++ helper functions that can be accessed from Swift.
|
|
25
|
+
*/
|
|
26
|
+
public typealias bridge = margelo.nitro.Markdown.bridge.swift
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Holds an instance of the `HybridMarkdownSessionSpec` Swift protocol.
|
|
30
|
+
*/
|
|
31
|
+
private var __implementation: any HybridMarkdownSessionSpec
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Holds a weak pointer to the C++ class that wraps the Swift class.
|
|
35
|
+
*/
|
|
36
|
+
private var __cxxPart: bridge.std__weak_ptr_HybridMarkdownSessionSpec_
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Create a new `HybridMarkdownSessionSpec_cxx` that wraps the given `HybridMarkdownSessionSpec`.
|
|
40
|
+
* All properties and methods bridge to C++ types.
|
|
41
|
+
*/
|
|
42
|
+
public init(_ implementation: any HybridMarkdownSessionSpec) {
|
|
43
|
+
self.__implementation = implementation
|
|
44
|
+
self.__cxxPart = .init()
|
|
45
|
+
/* no base class */
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Get the actual `HybridMarkdownSessionSpec` instance this class wraps.
|
|
50
|
+
*/
|
|
51
|
+
@inline(__always)
|
|
52
|
+
public func getHybridMarkdownSessionSpec() -> any HybridMarkdownSessionSpec {
|
|
53
|
+
return __implementation
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
58
|
+
* This acquires one additional strong reference on the object!
|
|
59
|
+
*/
|
|
60
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
61
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Casts an unsafe pointer to a `HybridMarkdownSessionSpec_cxx`.
|
|
66
|
+
* The pointer has to be a retained opaque `Unmanaged<HybridMarkdownSessionSpec_cxx>`.
|
|
67
|
+
* This removes one strong reference from the object!
|
|
68
|
+
*/
|
|
69
|
+
public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridMarkdownSessionSpec_cxx {
|
|
70
|
+
return Unmanaged<HybridMarkdownSessionSpec_cxx>.fromOpaque(pointer).takeRetainedValue()
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Gets (or creates) the C++ part of this Hybrid Object.
|
|
75
|
+
* The C++ part is a `std::shared_ptr<HybridMarkdownSessionSpec>`.
|
|
76
|
+
*/
|
|
77
|
+
public func getCxxPart() -> bridge.std__shared_ptr_HybridMarkdownSessionSpec_ {
|
|
78
|
+
let cachedCxxPart = self.__cxxPart.lock()
|
|
79
|
+
if Bool(fromCxx: cachedCxxPart) {
|
|
80
|
+
return cachedCxxPart
|
|
81
|
+
} else {
|
|
82
|
+
let newCxxPart = bridge.create_std__shared_ptr_HybridMarkdownSessionSpec_(self.toUnsafe())
|
|
83
|
+
__cxxPart = bridge.weakify_std__shared_ptr_HybridMarkdownSessionSpec_(newCxxPart)
|
|
84
|
+
return newCxxPart
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Get the memory size of the Swift class (plus size of any other allocations)
|
|
92
|
+
* so the JS VM can properly track it and garbage-collect the JS object if needed.
|
|
93
|
+
*/
|
|
94
|
+
@inline(__always)
|
|
95
|
+
public var memorySize: Int {
|
|
96
|
+
return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Compares this object with the given [other] object for reference equality.
|
|
101
|
+
*/
|
|
102
|
+
@inline(__always)
|
|
103
|
+
public func equals(other: HybridMarkdownSessionSpec_cxx) -> Bool {
|
|
104
|
+
return self.__implementation === other.__implementation
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Call dispose() on the Swift class.
|
|
109
|
+
* This _may_ be called manually from JS.
|
|
110
|
+
*/
|
|
111
|
+
@inline(__always)
|
|
112
|
+
public func dispose() {
|
|
113
|
+
self.__implementation.dispose()
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Call toString() on the Swift class.
|
|
118
|
+
*/
|
|
119
|
+
@inline(__always)
|
|
120
|
+
public func toString() -> String {
|
|
121
|
+
return self.__implementation.toString()
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Properties
|
|
125
|
+
public final var highlightPosition: Double {
|
|
126
|
+
@inline(__always)
|
|
127
|
+
get {
|
|
128
|
+
return self.__implementation.highlightPosition
|
|
129
|
+
}
|
|
130
|
+
@inline(__always)
|
|
131
|
+
set {
|
|
132
|
+
self.__implementation.highlightPosition = newValue
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Methods
|
|
137
|
+
@inline(__always)
|
|
138
|
+
public final func append(chunk: std.string) -> bridge.Result_void_ {
|
|
139
|
+
do {
|
|
140
|
+
try self.__implementation.append(chunk: String(chunk))
|
|
141
|
+
return bridge.create_Result_void_()
|
|
142
|
+
} catch (let __error) {
|
|
143
|
+
let __exceptionPtr = __error.toCpp()
|
|
144
|
+
return bridge.create_Result_void_(__exceptionPtr)
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
@inline(__always)
|
|
149
|
+
public final func clear() -> bridge.Result_void_ {
|
|
150
|
+
do {
|
|
151
|
+
try self.__implementation.clear()
|
|
152
|
+
return bridge.create_Result_void_()
|
|
153
|
+
} catch (let __error) {
|
|
154
|
+
let __exceptionPtr = __error.toCpp()
|
|
155
|
+
return bridge.create_Result_void_(__exceptionPtr)
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
@inline(__always)
|
|
160
|
+
public final func getAllText() -> bridge.Result_std__string_ {
|
|
161
|
+
do {
|
|
162
|
+
let __result = try self.__implementation.getAllText()
|
|
163
|
+
let __resultCpp = std.string(__result)
|
|
164
|
+
return bridge.create_Result_std__string_(__resultCpp)
|
|
165
|
+
} catch (let __error) {
|
|
166
|
+
let __exceptionPtr = __error.toCpp()
|
|
167
|
+
return bridge.create_Result_std__string_(__exceptionPtr)
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
@inline(__always)
|
|
172
|
+
public final func addListener(listener: bridge.Func_void) -> bridge.Result_std__function_void____ {
|
|
173
|
+
do {
|
|
174
|
+
let __result = try self.__implementation.addListener(listener: { () -> () -> Void in
|
|
175
|
+
let __wrappedFunction = bridge.wrap_Func_void(listener)
|
|
176
|
+
return { () -> Void in
|
|
177
|
+
__wrappedFunction.call()
|
|
178
|
+
}
|
|
179
|
+
}())
|
|
180
|
+
let __resultCpp = { () -> bridge.Func_void in
|
|
181
|
+
let __closureWrapper = Func_void(__result)
|
|
182
|
+
return bridge.create_Func_void(__closureWrapper.toUnsafe())
|
|
183
|
+
}()
|
|
184
|
+
return bridge.create_Result_std__function_void____(__resultCpp)
|
|
185
|
+
} catch (let __error) {
|
|
186
|
+
let __exceptionPtr = __error.toCpp()
|
|
187
|
+
return bridge.create_Result_std__function_void____(__exceptionPtr)
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
/// HybridMarkdownParserSpec.cpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#include "HybridMarkdownParserSpec.hpp"
|
|
9
9
|
|
|
10
|
-
namespace margelo::nitro::
|
|
10
|
+
namespace margelo::nitro::Markdown {
|
|
11
11
|
|
|
12
12
|
void HybridMarkdownParserSpec::loadHybridMethods() {
|
|
13
13
|
// load base methods/properties
|
|
@@ -19,4 +19,4 @@ namespace margelo::nitro::NitroMarkdown {
|
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
} // namespace margelo::nitro::
|
|
22
|
+
} // namespace margelo::nitro::Markdown
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// HybridMarkdownParserSpec.hpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#pragma once
|
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
#endif
|
|
15
15
|
|
|
16
16
|
// Forward declaration of `ParserOptions` to properly resolve imports.
|
|
17
|
-
namespace margelo::nitro::
|
|
17
|
+
namespace margelo::nitro::Markdown { struct ParserOptions; }
|
|
18
18
|
|
|
19
19
|
#include <string>
|
|
20
20
|
#include "ParserOptions.hpp"
|
|
21
21
|
|
|
22
|
-
namespace margelo::nitro::
|
|
22
|
+
namespace margelo::nitro::Markdown {
|
|
23
23
|
|
|
24
24
|
using namespace margelo::nitro;
|
|
25
25
|
|
|
@@ -62,4 +62,4 @@ namespace margelo::nitro::NitroMarkdown {
|
|
|
62
62
|
static constexpr auto TAG = "MarkdownParser";
|
|
63
63
|
};
|
|
64
64
|
|
|
65
|
-
} // namespace margelo::nitro::
|
|
65
|
+
} // namespace margelo::nitro::Markdown
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridMarkdownSessionSpec.cpp
|
|
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
|
+
#include "HybridMarkdownSessionSpec.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::Markdown {
|
|
11
|
+
|
|
12
|
+
void HybridMarkdownSessionSpec::loadHybridMethods() {
|
|
13
|
+
// load base methods/properties
|
|
14
|
+
HybridObject::loadHybridMethods();
|
|
15
|
+
// load custom methods/properties
|
|
16
|
+
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
+
prototype.registerHybridGetter("highlightPosition", &HybridMarkdownSessionSpec::getHighlightPosition);
|
|
18
|
+
prototype.registerHybridSetter("highlightPosition", &HybridMarkdownSessionSpec::setHighlightPosition);
|
|
19
|
+
prototype.registerHybridMethod("append", &HybridMarkdownSessionSpec::append);
|
|
20
|
+
prototype.registerHybridMethod("clear", &HybridMarkdownSessionSpec::clear);
|
|
21
|
+
prototype.registerHybridMethod("getAllText", &HybridMarkdownSessionSpec::getAllText);
|
|
22
|
+
prototype.registerHybridMethod("addListener", &HybridMarkdownSessionSpec::addListener);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
} // namespace margelo::nitro::Markdown
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridMarkdownSessionSpec.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
|
+
#if __has_include(<NitroModules/HybridObject.hpp>)
|
|
11
|
+
#include <NitroModules/HybridObject.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
#include <string>
|
|
19
|
+
#include <functional>
|
|
20
|
+
|
|
21
|
+
namespace margelo::nitro::Markdown {
|
|
22
|
+
|
|
23
|
+
using namespace margelo::nitro;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* An abstract base class for `MarkdownSession`
|
|
27
|
+
* Inherit this class to create instances of `HybridMarkdownSessionSpec` in C++.
|
|
28
|
+
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
29
|
+
* @example
|
|
30
|
+
* ```cpp
|
|
31
|
+
* class HybridMarkdownSession: public HybridMarkdownSessionSpec {
|
|
32
|
+
* public:
|
|
33
|
+
* HybridMarkdownSession(...): HybridObject(TAG) { ... }
|
|
34
|
+
* // ...
|
|
35
|
+
* };
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
class HybridMarkdownSessionSpec: public virtual HybridObject {
|
|
39
|
+
public:
|
|
40
|
+
// Constructor
|
|
41
|
+
explicit HybridMarkdownSessionSpec(): HybridObject(TAG) { }
|
|
42
|
+
|
|
43
|
+
// Destructor
|
|
44
|
+
~HybridMarkdownSessionSpec() override = default;
|
|
45
|
+
|
|
46
|
+
public:
|
|
47
|
+
// Properties
|
|
48
|
+
virtual double getHighlightPosition() = 0;
|
|
49
|
+
virtual void setHighlightPosition(double highlightPosition) = 0;
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
// Methods
|
|
53
|
+
virtual void append(const std::string& chunk) = 0;
|
|
54
|
+
virtual void clear() = 0;
|
|
55
|
+
virtual std::string getAllText() = 0;
|
|
56
|
+
virtual std::function<void()> addListener(const std::function<void()>& listener) = 0;
|
|
57
|
+
|
|
58
|
+
protected:
|
|
59
|
+
// Hybrid Setup
|
|
60
|
+
void loadHybridMethods() override;
|
|
61
|
+
|
|
62
|
+
protected:
|
|
63
|
+
// Tag for logging
|
|
64
|
+
static constexpr auto TAG = "MarkdownSession";
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
} // namespace margelo::nitro::Markdown
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// ParserOptions.hpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#pragma once
|
|
@@ -22,17 +22,22 @@
|
|
|
22
22
|
#else
|
|
23
23
|
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
24
|
#endif
|
|
25
|
+
#if __has_include(<NitroModules/PropNameIDCache.hpp>)
|
|
26
|
+
#include <NitroModules/PropNameIDCache.hpp>
|
|
27
|
+
#else
|
|
28
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
29
|
+
#endif
|
|
25
30
|
|
|
26
31
|
|
|
27
32
|
|
|
28
33
|
#include <optional>
|
|
29
34
|
|
|
30
|
-
namespace margelo::nitro::
|
|
35
|
+
namespace margelo::nitro::Markdown {
|
|
31
36
|
|
|
32
37
|
/**
|
|
33
38
|
* A struct which can be represented as a JavaScript object (ParserOptions).
|
|
34
39
|
*/
|
|
35
|
-
struct ParserOptions {
|
|
40
|
+
struct ParserOptions final {
|
|
36
41
|
public:
|
|
37
42
|
std::optional<bool> gfm SWIFT_PRIVATE;
|
|
38
43
|
std::optional<bool> math SWIFT_PRIVATE;
|
|
@@ -40,26 +45,29 @@ namespace margelo::nitro::NitroMarkdown {
|
|
|
40
45
|
public:
|
|
41
46
|
ParserOptions() = default;
|
|
42
47
|
explicit ParserOptions(std::optional<bool> gfm, std::optional<bool> math): gfm(gfm), math(math) {}
|
|
48
|
+
|
|
49
|
+
public:
|
|
50
|
+
friend bool operator==(const ParserOptions& lhs, const ParserOptions& rhs) = default;
|
|
43
51
|
};
|
|
44
52
|
|
|
45
|
-
} // namespace margelo::nitro::
|
|
53
|
+
} // namespace margelo::nitro::Markdown
|
|
46
54
|
|
|
47
55
|
namespace margelo::nitro {
|
|
48
56
|
|
|
49
57
|
// C++ ParserOptions <> JS ParserOptions (object)
|
|
50
58
|
template <>
|
|
51
|
-
struct JSIConverter<margelo::nitro::
|
|
52
|
-
static inline margelo::nitro::
|
|
59
|
+
struct JSIConverter<margelo::nitro::Markdown::ParserOptions> final {
|
|
60
|
+
static inline margelo::nitro::Markdown::ParserOptions fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
53
61
|
jsi::Object obj = arg.asObject(runtime);
|
|
54
|
-
return margelo::nitro::
|
|
55
|
-
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, "gfm")),
|
|
56
|
-
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, "math"))
|
|
62
|
+
return margelo::nitro::Markdown::ParserOptions(
|
|
63
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "gfm"))),
|
|
64
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "math")))
|
|
57
65
|
);
|
|
58
66
|
}
|
|
59
|
-
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::
|
|
67
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::Markdown::ParserOptions& arg) {
|
|
60
68
|
jsi::Object obj(runtime);
|
|
61
|
-
obj.setProperty(runtime, "gfm", JSIConverter<std::optional<bool>>::toJSI(runtime, arg.gfm));
|
|
62
|
-
obj.setProperty(runtime, "math", JSIConverter<std::optional<bool>>::toJSI(runtime, arg.math));
|
|
69
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "gfm"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.gfm));
|
|
70
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "math"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.math));
|
|
63
71
|
return obj;
|
|
64
72
|
}
|
|
65
73
|
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
@@ -70,8 +78,8 @@ namespace margelo::nitro {
|
|
|
70
78
|
if (!nitro::isPlainObject(runtime, obj)) {
|
|
71
79
|
return false;
|
|
72
80
|
}
|
|
73
|
-
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, "gfm"))) return false;
|
|
74
|
-
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, "math"))) return false;
|
|
81
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "gfm")))) return false;
|
|
82
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "math")))) return false;
|
|
75
83
|
return true;
|
|
76
84
|
}
|
|
77
85
|
};
|