react-native-nitro-markdown 0.5.0 → 0.5.2
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/README.md +68 -5
- package/android/src/main/cpp/cpp-adapter.cpp +4 -1
- package/android/src/main/java/com/margelo/nitro/com/nitromarkdown/HybridMarkdownSession.kt +19 -0
- package/android/src/main/java/com/nitromarkdown/NitroMarkdownPackage.kt +4 -3
- package/ios/HybridMarkdownSession.swift +18 -0
- package/lib/commonjs/MarkdownContext.js.map +1 -1
- package/lib/commonjs/headless.js +20 -0
- package/lib/commonjs/headless.js.map +1 -1
- package/lib/commonjs/index.js +9 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/markdown.js +21 -11
- package/lib/commonjs/markdown.js.map +1 -1
- package/lib/commonjs/renderers/code.js +20 -2
- package/lib/commonjs/renderers/code.js.map +1 -1
- package/lib/commonjs/renderers/table/cell-content.js +32 -0
- package/lib/commonjs/renderers/table/cell-content.js.map +1 -0
- package/lib/commonjs/renderers/table/index.js +310 -0
- package/lib/commonjs/renderers/table/index.js.map +1 -0
- package/lib/commonjs/renderers/table/table-reducer.js +29 -0
- package/lib/commonjs/renderers/table/table-reducer.js.map +1 -0
- package/lib/commonjs/renderers/table/table-utils.js +68 -0
- package/lib/commonjs/renderers/table/table-utils.js.map +1 -0
- package/lib/commonjs/renderers/table/types.js +6 -0
- package/lib/commonjs/renderers/table/types.js.map +1 -0
- package/lib/commonjs/renderers/table.js +6 -398
- package/lib/commonjs/renderers/table.js.map +1 -1
- package/lib/commonjs/theme.js +10 -1
- package/lib/commonjs/theme.js.map +1 -1
- package/lib/commonjs/use-markdown-stream.js +9 -1
- package/lib/commonjs/use-markdown-stream.js.map +1 -1
- package/lib/commonjs/utils/code-highlight.js +101 -0
- package/lib/commonjs/utils/code-highlight.js.map +1 -0
- package/lib/module/MarkdownContext.js.map +1 -1
- package/lib/module/headless.js +19 -0
- package/lib/module/headless.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/markdown.js +21 -11
- package/lib/module/markdown.js.map +1 -1
- package/lib/module/renderers/code.js +20 -2
- package/lib/module/renderers/code.js.map +1 -1
- package/lib/module/renderers/table/cell-content.js +27 -0
- package/lib/module/renderers/table/cell-content.js.map +1 -0
- package/lib/module/renderers/table/index.js +305 -0
- package/lib/module/renderers/table/index.js.map +1 -0
- package/lib/module/renderers/table/table-reducer.js +24 -0
- package/lib/module/renderers/table/table-reducer.js.map +1 -0
- package/lib/module/renderers/table/table-utils.js +62 -0
- package/lib/module/renderers/table/table-utils.js.map +1 -0
- package/lib/module/renderers/table/types.js +4 -0
- package/lib/module/renderers/table/types.js.map +1 -0
- package/lib/module/renderers/table.js +1 -397
- package/lib/module/renderers/table.js.map +1 -1
- package/lib/module/theme.js +10 -1
- package/lib/module/theme.js.map +1 -1
- package/lib/module/use-markdown-stream.js +9 -1
- package/lib/module/use-markdown-stream.js.map +1 -1
- package/lib/module/utils/code-highlight.js +97 -0
- package/lib/module/utils/code-highlight.js.map +1 -0
- package/lib/typescript/commonjs/MarkdownContext.d.ts +6 -0
- package/lib/typescript/commonjs/MarkdownContext.d.ts.map +1 -1
- package/lib/typescript/commonjs/headless.d.ts +5 -0
- package/lib/typescript/commonjs/headless.d.ts.map +1 -1
- package/lib/typescript/commonjs/index.d.ts +2 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/markdown.d.ts +24 -0
- package/lib/typescript/commonjs/markdown.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/code.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/table/cell-content.d.ts +15 -0
- package/lib/typescript/commonjs/renderers/table/cell-content.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/table/index.d.ts +11 -0
- package/lib/typescript/commonjs/renderers/table/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/table/table-reducer.d.ts +5 -0
- package/lib/typescript/commonjs/renderers/table/table-reducer.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/table/table-utils.d.ts +10 -0
- package/lib/typescript/commonjs/renderers/table/table-utils.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/table/types.d.ts +24 -0
- package/lib/typescript/commonjs/renderers/table/types.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/table.d.ts +1 -11
- package/lib/typescript/commonjs/renderers/table.d.ts.map +1 -1
- package/lib/typescript/commonjs/specs/MarkdownSession.nitro.d.ts +9 -0
- package/lib/typescript/commonjs/specs/MarkdownSession.nitro.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme.d.ts +18 -2
- package/lib/typescript/commonjs/theme.d.ts.map +1 -1
- package/lib/typescript/commonjs/use-markdown-stream.d.ts +4 -0
- package/lib/typescript/commonjs/use-markdown-stream.d.ts.map +1 -1
- package/lib/typescript/commonjs/utils/code-highlight.d.ts +8 -0
- package/lib/typescript/commonjs/utils/code-highlight.d.ts.map +1 -0
- package/lib/typescript/module/MarkdownContext.d.ts +6 -0
- package/lib/typescript/module/MarkdownContext.d.ts.map +1 -1
- package/lib/typescript/module/headless.d.ts +5 -0
- package/lib/typescript/module/headless.d.ts.map +1 -1
- package/lib/typescript/module/index.d.ts +2 -0
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/markdown.d.ts +24 -0
- package/lib/typescript/module/markdown.d.ts.map +1 -1
- package/lib/typescript/module/renderers/code.d.ts.map +1 -1
- package/lib/typescript/module/renderers/table/cell-content.d.ts +15 -0
- package/lib/typescript/module/renderers/table/cell-content.d.ts.map +1 -0
- package/lib/typescript/module/renderers/table/index.d.ts +11 -0
- package/lib/typescript/module/renderers/table/index.d.ts.map +1 -0
- package/lib/typescript/module/renderers/table/table-reducer.d.ts +5 -0
- package/lib/typescript/module/renderers/table/table-reducer.d.ts.map +1 -0
- package/lib/typescript/module/renderers/table/table-utils.d.ts +10 -0
- package/lib/typescript/module/renderers/table/table-utils.d.ts.map +1 -0
- package/lib/typescript/module/renderers/table/types.d.ts +24 -0
- package/lib/typescript/module/renderers/table/types.d.ts.map +1 -0
- package/lib/typescript/module/renderers/table.d.ts +1 -11
- package/lib/typescript/module/renderers/table.d.ts.map +1 -1
- package/lib/typescript/module/specs/MarkdownSession.nitro.d.ts +9 -0
- package/lib/typescript/module/specs/MarkdownSession.nitro.d.ts.map +1 -1
- package/lib/typescript/module/theme.d.ts +18 -2
- package/lib/typescript/module/theme.d.ts.map +1 -1
- package/lib/typescript/module/use-markdown-stream.d.ts +4 -0
- package/lib/typescript/module/use-markdown-stream.d.ts.map +1 -1
- package/lib/typescript/module/utils/code-highlight.d.ts +8 -0
- package/lib/typescript/module/utils/code-highlight.d.ts.map +1 -0
- package/nitrogen/generated/android/NitroMarkdownOnLoad.cpp +37 -27
- package/nitrogen/generated/android/NitroMarkdownOnLoad.hpp +13 -4
- package/nitrogen/generated/android/c++/JHybridMarkdownSessionSpec.cpp +35 -32
- package/nitrogen/generated/android/c++/JHybridMarkdownSessionSpec.hpp +21 -22
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/com/nitromarkdown/HybridMarkdownSessionSpec.kt +23 -18
- package/nitrogen/generated/ios/c++/HybridMarkdownSessionSpecSwift.hpp +14 -0
- package/nitrogen/generated/ios/swift/HybridMarkdownSessionSpec.swift +2 -0
- package/nitrogen/generated/ios/swift/HybridMarkdownSessionSpec_cxx.swift +23 -0
- package/nitrogen/generated/shared/c++/HybridMarkdownSessionSpec.cpp +2 -0
- package/nitrogen/generated/shared/c++/HybridMarkdownSessionSpec.hpp +2 -0
- package/package.json +6 -3
- package/react-native-nitro-markdown.podspec +1 -1
- package/src/MarkdownContext.ts +6 -0
- package/src/headless.ts +12 -0
- package/src/index.ts +3 -0
- package/src/markdown.tsx +47 -7
- package/src/renderers/code.tsx +27 -2
- package/src/renderers/table/cell-content.tsx +38 -0
- package/src/renderers/table/index.tsx +419 -0
- package/src/renderers/table/table-reducer.ts +36 -0
- package/src/renderers/table/table-utils.ts +81 -0
- package/src/renderers/table/types.ts +24 -0
- package/src/renderers/table.tsx +1 -547
- package/src/specs/MarkdownSession.nitro.ts +10 -0
- package/src/theme.ts +29 -1
- package/src/use-markdown-stream.ts +10 -0
- package/src/utils/code-highlight.ts +102 -0
|
@@ -1,12 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { type ViewStyle } from "react-native";
|
|
3
|
-
import { type MarkdownNode } from "../headless";
|
|
4
|
-
import { type NodeRendererProps } from "../MarkdownContext";
|
|
5
|
-
type TableRendererProps = {
|
|
6
|
-
node: MarkdownNode;
|
|
7
|
-
Renderer: ComponentType<NodeRendererProps>;
|
|
8
|
-
style?: ViewStyle;
|
|
9
|
-
};
|
|
10
|
-
export declare const TableRenderer: FC<TableRendererProps>;
|
|
11
|
-
export {};
|
|
1
|
+
export { TableRenderer } from "./table/index";
|
|
12
2
|
//# sourceMappingURL=table.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../../../src/renderers/table.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../../../src/renderers/table.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -11,5 +11,14 @@ export interface MarkdownSession extends HybridObject<{
|
|
|
11
11
|
getTextRange(from: number, to: number): string;
|
|
12
12
|
highlightPosition: number;
|
|
13
13
|
addListener(listener: MarkdownSessionListener): () => void;
|
|
14
|
+
/**
|
|
15
|
+
* Replaces the entire buffer with new text and notifies listeners with (0, newLength).
|
|
16
|
+
*/
|
|
17
|
+
reset(text: string): void;
|
|
18
|
+
/**
|
|
19
|
+
* Replaces the text in [from, to) with the given text.
|
|
20
|
+
* Returns the new total buffer length.
|
|
21
|
+
*/
|
|
22
|
+
replace(from: number, to: number, text: string): number;
|
|
14
23
|
}
|
|
15
24
|
//# sourceMappingURL=MarkdownSession.nitro.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarkdownSession.nitro.d.ts","sourceRoot":"","sources":["../../../../src/specs/MarkdownSession.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE/D,MAAM,MAAM,uBAAuB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;AAEzE,MAAM,WAAW,eAAgB,SAAQ,YAAY,CAAC;IACpD,GAAG,EAAE,OAAO,CAAC;IACb,OAAO,EAAE,QAAQ,CAAC;CACnB,CAAC;IACA,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAC9B,KAAK,IAAI,IAAI,CAAC;IACd,UAAU,IAAI,MAAM,CAAC;IACrB,SAAS,IAAI,MAAM,CAAC;IACpB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IAE/C,iBAAiB,EAAE,MAAM,CAAC;IAE1B,WAAW,CAAC,QAAQ,EAAE,uBAAuB,GAAG,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"MarkdownSession.nitro.d.ts","sourceRoot":"","sources":["../../../../src/specs/MarkdownSession.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE/D,MAAM,MAAM,uBAAuB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;AAEzE,MAAM,WAAW,eAAgB,SAAQ,YAAY,CAAC;IACpD,GAAG,EAAE,OAAO,CAAC;IACb,OAAO,EAAE,QAAQ,CAAC;CACnB,CAAC;IACA,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAC9B,KAAK,IAAI,IAAI,CAAC;IACd,UAAU,IAAI,MAAM,CAAC;IACrB,SAAS,IAAI,MAAM,CAAC;IACpB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IAE/C,iBAAiB,EAAE,MAAM,CAAC;IAE1B,WAAW,CAAC,QAAQ,EAAE,uBAAuB,GAAG,MAAM,IAAI,CAAC;IAE3D;;OAEG;IACH,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B;;;OAGG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CACzD"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { type TextStyle, type ViewStyle } from "react-native";
|
|
2
|
-
import type { MarkdownNode } from "./headless";
|
|
3
2
|
export type MarkdownTheme = {
|
|
4
3
|
colors: {
|
|
5
4
|
text: string | undefined;
|
|
@@ -19,6 +18,16 @@ export type MarkdownTheme = {
|
|
|
19
18
|
tableHeaderText: string | undefined;
|
|
20
19
|
tableRowEven: string | undefined;
|
|
21
20
|
tableRowOdd: string | undefined;
|
|
21
|
+
codeTokenColors?: {
|
|
22
|
+
keyword?: string;
|
|
23
|
+
string?: string;
|
|
24
|
+
comment?: string;
|
|
25
|
+
number?: string;
|
|
26
|
+
operator?: string;
|
|
27
|
+
punctuation?: string;
|
|
28
|
+
type?: string;
|
|
29
|
+
default?: string;
|
|
30
|
+
};
|
|
22
31
|
};
|
|
23
32
|
spacing: {
|
|
24
33
|
xs: number;
|
|
@@ -57,8 +66,15 @@ export declare const defaultMarkdownTheme: MarkdownTheme;
|
|
|
57
66
|
export type PartialMarkdownTheme = {
|
|
58
67
|
[K in keyof MarkdownTheme]?: K extends "showCodeLanguage" | "headingWeight" ? MarkdownTheme[K] : MarkdownTheme[K] extends object ? Partial<MarkdownTheme[K]> : MarkdownTheme[K];
|
|
59
68
|
};
|
|
60
|
-
|
|
69
|
+
type TextNodeType = "text" | "bold" | "italic" | "strikethrough" | "link" | "code_inline" | "heading" | "paragraph" | "math_inline" | "html_inline";
|
|
70
|
+
type ViewNodeType = "document" | "blockquote" | "code_block" | "horizontal_rule" | "image" | "list" | "list_item" | "task_list_item" | "table" | "table_head" | "table_body" | "table_row" | "table_cell" | "math_block" | "html_block" | "line_break" | "soft_break";
|
|
71
|
+
export type NodeStyleOverrides = Partial<{
|
|
72
|
+
[K in TextNodeType]: TextStyle;
|
|
73
|
+
} & {
|
|
74
|
+
[K in ViewNodeType]: ViewStyle;
|
|
75
|
+
}>;
|
|
61
76
|
export type StylingStrategy = "opinionated" | "minimal";
|
|
62
77
|
export declare const minimalMarkdownTheme: MarkdownTheme;
|
|
63
78
|
export declare const mergeThemes: (base: MarkdownTheme, partial?: PartialMarkdownTheme) => MarkdownTheme;
|
|
79
|
+
export {};
|
|
64
80
|
//# sourceMappingURL=theme.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../../src/theme.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../../src/theme.ts"],"names":[],"mappings":"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"}
|
|
@@ -7,6 +7,8 @@ export declare function useMarkdownSession(): {
|
|
|
7
7
|
stop: () => void;
|
|
8
8
|
clear: () => void;
|
|
9
9
|
setHighlight: (position: number) => void;
|
|
10
|
+
reset: (text: string) => void;
|
|
11
|
+
replace: (from: number, to: number, text: string) => number;
|
|
10
12
|
};
|
|
11
13
|
export declare function useStream(timestamps?: Record<number, number>): {
|
|
12
14
|
isPlaying: boolean;
|
|
@@ -18,5 +20,7 @@ export declare function useStream(timestamps?: Record<number, number>): {
|
|
|
18
20
|
stop: () => void;
|
|
19
21
|
clear: () => void;
|
|
20
22
|
setHighlight: (position: number) => void;
|
|
23
|
+
reset: (text: string) => void;
|
|
24
|
+
replace: (from: number, to: number, text: string) => number;
|
|
21
25
|
};
|
|
22
26
|
//# sourceMappingURL=use-markdown-stream.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-markdown-stream.d.ts","sourceRoot":"","sources":["../../../src/use-markdown-stream.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAO1D,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEvE,wBAAgB,kBAAkB;;;;;;6BAyBY,MAAM;
|
|
1
|
+
{"version":3,"file":"use-markdown-stream.d.ts","sourceRoot":"","sources":["../../../src/use-markdown-stream.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAO1D,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEvE,wBAAgB,kBAAkB;;;;;;6BAyBY,MAAM;kBAMjB,MAAM;oBAIJ,MAAM,MAAM,MAAM,QAAQ,MAAM;EAcpE;AAED,wBAAgB,SAAS,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;;;0BAgBzC,MAAM;;;;;;6BA1CoB,MAAM;kBAMjB,MAAM;oBAIJ,MAAM,MAAM,MAAM,QAAQ,MAAM;EAqDpE"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type TokenType = 'keyword' | 'string' | 'comment' | 'number' | 'operator' | 'punctuation' | 'type' | 'default';
|
|
2
|
+
export type HighlightedToken = {
|
|
3
|
+
text: string;
|
|
4
|
+
type: TokenType;
|
|
5
|
+
};
|
|
6
|
+
export type CodeHighlighter = (language: string, code: string) => HighlightedToken[];
|
|
7
|
+
export declare function defaultHighlighter(language: string, code: string): HighlightedToken[];
|
|
8
|
+
//# sourceMappingURL=code-highlight.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-highlight.d.ts","sourceRoot":"","sources":["../../../../src/utils/code-highlight.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GACjB,SAAS,GACT,QAAQ,GACR,SAAS,GACT,QAAQ,GACR,UAAU,GACV,aAAa,GACb,MAAM,GACN,SAAS,CAAC;AAEd,MAAM,MAAM,gBAAgB,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC;AACjE,MAAM,MAAM,eAAe,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,gBAAgB,EAAE,CAAC;AA2ErF,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAerF"}
|
|
@@ -24,35 +24,45 @@
|
|
|
24
24
|
namespace margelo::nitro::Markdown {
|
|
25
25
|
|
|
26
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() {
|
|
27
42
|
using namespace margelo::nitro;
|
|
28
43
|
using namespace margelo::nitro::Markdown;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
auto instance = object.create();
|
|
52
|
-
return instance->cthis()->shared();
|
|
53
|
-
}
|
|
54
|
-
);
|
|
55
|
-
});
|
|
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
|
+
);
|
|
56
66
|
}
|
|
57
67
|
|
|
58
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
|
-
*
|
|
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
|
|
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
|
-
|
|
32
|
+
void registerAllNatives();
|
|
24
33
|
|
|
25
34
|
} // namespace margelo::nitro::Markdown
|
|
@@ -17,77 +17,71 @@
|
|
|
17
17
|
|
|
18
18
|
namespace margelo::nitro::Markdown {
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
});
|
|
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;
|
|
28
27
|
}
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return method(_javaPart);
|
|
29
|
+
jni::local_ref<JHybridMarkdownSessionSpec::CxxPart::jhybriddata> JHybridMarkdownSessionSpec::CxxPart::initHybrid(jni::alias_ref<jhybridobject> jThis) {
|
|
30
|
+
return makeCxxInstance(jThis);
|
|
33
31
|
}
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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!");
|
|
38
37
|
}
|
|
39
|
-
return
|
|
38
|
+
return std::make_shared<JHybridMarkdownSessionSpec>(castJavaPart);
|
|
40
39
|
}
|
|
41
40
|
|
|
42
|
-
void JHybridMarkdownSessionSpec::
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
std::string JHybridMarkdownSessionSpec::toString() {
|
|
48
|
-
static const auto method = javaClassStatic()->getMethod<jni::JString()>("toString");
|
|
49
|
-
auto javaString = method(_javaPart);
|
|
50
|
-
return javaString->toStdString();
|
|
41
|
+
void JHybridMarkdownSessionSpec::CxxPart::registerNatives() {
|
|
42
|
+
registerHybrid({
|
|
43
|
+
makeNativeMethod("initHybrid", JHybridMarkdownSessionSpec::CxxPart::initHybrid),
|
|
44
|
+
});
|
|
51
45
|
}
|
|
52
46
|
|
|
53
47
|
// Properties
|
|
54
48
|
double JHybridMarkdownSessionSpec::getHighlightPosition() {
|
|
55
|
-
static const auto method = javaClassStatic()->getMethod<double()>("getHighlightPosition");
|
|
49
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<double()>("getHighlightPosition");
|
|
56
50
|
auto __result = method(_javaPart);
|
|
57
51
|
return __result;
|
|
58
52
|
}
|
|
59
53
|
void JHybridMarkdownSessionSpec::setHighlightPosition(double highlightPosition) {
|
|
60
|
-
static const auto method = javaClassStatic()->getMethod<void(double /* highlightPosition */)>("setHighlightPosition");
|
|
54
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<void(double /* highlightPosition */)>("setHighlightPosition");
|
|
61
55
|
method(_javaPart, highlightPosition);
|
|
62
56
|
}
|
|
63
57
|
|
|
64
58
|
// Methods
|
|
65
59
|
double JHybridMarkdownSessionSpec::append(const std::string& chunk) {
|
|
66
|
-
static const auto method = javaClassStatic()->getMethod<double(jni::alias_ref<jni::JString> /* chunk */)>("append");
|
|
60
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<double(jni::alias_ref<jni::JString> /* chunk */)>("append");
|
|
67
61
|
auto __result = method(_javaPart, jni::make_jstring(chunk));
|
|
68
62
|
return __result;
|
|
69
63
|
}
|
|
70
64
|
void JHybridMarkdownSessionSpec::clear() {
|
|
71
|
-
static const auto method = javaClassStatic()->getMethod<void()>("clear");
|
|
65
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<void()>("clear");
|
|
72
66
|
method(_javaPart);
|
|
73
67
|
}
|
|
74
68
|
std::string JHybridMarkdownSessionSpec::getAllText() {
|
|
75
|
-
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");
|
|
76
70
|
auto __result = method(_javaPart);
|
|
77
71
|
return __result->toStdString();
|
|
78
72
|
}
|
|
79
73
|
double JHybridMarkdownSessionSpec::getLength() {
|
|
80
|
-
static const auto method = javaClassStatic()->getMethod<double()>("getLength");
|
|
74
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<double()>("getLength");
|
|
81
75
|
auto __result = method(_javaPart);
|
|
82
76
|
return __result;
|
|
83
77
|
}
|
|
84
78
|
std::string JHybridMarkdownSessionSpec::getTextRange(double from, double to) {
|
|
85
|
-
static const auto method = javaClassStatic()->getMethod<jni::local_ref<jni::JString>(double /* from */, double /* to */)>("getTextRange");
|
|
79
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<jni::JString>(double /* from */, double /* to */)>("getTextRange");
|
|
86
80
|
auto __result = method(_javaPart, from, to);
|
|
87
81
|
return __result->toStdString();
|
|
88
82
|
}
|
|
89
83
|
std::function<void()> JHybridMarkdownSessionSpec::addListener(const std::function<void(double /* from */, double /* to */)>& listener) {
|
|
90
|
-
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JFunc_void::javaobject>(jni::alias_ref<JFunc_void_double_double::javaobject> /* listener */)>("addListener_cxx");
|
|
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");
|
|
91
85
|
auto __result = method(_javaPart, JFunc_void_double_double_cxx::fromCpp(listener));
|
|
92
86
|
return [&]() -> std::function<void()> {
|
|
93
87
|
if (__result->isInstanceOf(JFunc_void_cxx::javaClassStatic())) [[likely]] {
|
|
@@ -99,5 +93,14 @@ namespace margelo::nitro::Markdown {
|
|
|
99
93
|
}
|
|
100
94
|
}();
|
|
101
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
|
+
}
|
|
102
105
|
|
|
103
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
|
|
22
|
-
public virtual HybridMarkdownSessionSpec {
|
|
21
|
+
class JHybridMarkdownSessionSpec: public virtual HybridMarkdownSessionSpec, public virtual JHybridObject {
|
|
23
22
|
public:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
HybridBase
|
|
33
|
-
|
|
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
|
-
|
|
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
|
|
|
@@ -62,11 +61,11 @@ namespace margelo::nitro::Markdown {
|
|
|
62
61
|
double getLength() override;
|
|
63
62
|
std::string getTextRange(double from, double to) override;
|
|
64
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;
|
|
65
66
|
|
|
66
67
|
private:
|
|
67
|
-
|
|
68
|
-
using HybridBase::HybridBase;
|
|
69
|
-
jni::global_ref<JHybridMarkdownSessionSpec::javaobject> _javaPart;
|
|
68
|
+
jni::global_ref<JHybridMarkdownSessionSpec::JavaPart> _javaPart;
|
|
70
69
|
};
|
|
71
70
|
|
|
72
71
|
} // namespace margelo::nitro::Markdown
|
|
@@ -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
|
|
@@ -77,8 +60,30 @@ abstract class HybridMarkdownSessionSpec: HybridObject() {
|
|
|
77
60
|
val __result = addListener(listener)
|
|
78
61
|
return Func_void_java(__result)
|
|
79
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
|
+
}
|
|
80
76
|
|
|
81
|
-
|
|
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
|
+
}
|
|
82
87
|
|
|
83
88
|
companion object {
|
|
84
89
|
protected const val TAG = "HybridMarkdownSessionSpec"
|
|
@@ -118,6 +118,20 @@ namespace margelo::nitro::Markdown {
|
|
|
118
118
|
auto __value = std::move(__result.value());
|
|
119
119
|
return __value;
|
|
120
120
|
}
|
|
121
|
+
inline void reset(const std::string& text) override {
|
|
122
|
+
auto __result = _swiftPart.reset(text);
|
|
123
|
+
if (__result.hasError()) [[unlikely]] {
|
|
124
|
+
std::rethrow_exception(__result.error());
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
inline double replace(double from, double to, const std::string& text) override {
|
|
128
|
+
auto __result = _swiftPart.replace(std::forward<decltype(from)>(from), std::forward<decltype(to)>(to), text);
|
|
129
|
+
if (__result.hasError()) [[unlikely]] {
|
|
130
|
+
std::rethrow_exception(__result.error());
|
|
131
|
+
}
|
|
132
|
+
auto __value = std::move(__result.value());
|
|
133
|
+
return __value;
|
|
134
|
+
}
|
|
121
135
|
|
|
122
136
|
private:
|
|
123
137
|
NitroMarkdown::HybridMarkdownSessionSpec_cxx _swiftPart;
|
|
@@ -19,6 +19,8 @@ public protocol HybridMarkdownSessionSpec_protocol: HybridObject {
|
|
|
19
19
|
func getLength() throws -> Double
|
|
20
20
|
func getTextRange(from: Double, to: Double) throws -> String
|
|
21
21
|
func addListener(listener: @escaping (_ from: Double, _ to: Double) -> Void) throws -> () -> Void
|
|
22
|
+
func reset(text: String) throws -> Void
|
|
23
|
+
func replace(from: Double, to: Double, text: String) throws -> Double
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
public extension HybridMarkdownSessionSpec_protocol {
|
|
@@ -211,4 +211,27 @@ open class HybridMarkdownSessionSpec_cxx {
|
|
|
211
211
|
return bridge.create_Result_std__function_void____(__exceptionPtr)
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
|
+
|
|
215
|
+
@inline(__always)
|
|
216
|
+
public final func reset(text: std.string) -> bridge.Result_void_ {
|
|
217
|
+
do {
|
|
218
|
+
try self.__implementation.reset(text: String(text))
|
|
219
|
+
return bridge.create_Result_void_()
|
|
220
|
+
} catch (let __error) {
|
|
221
|
+
let __exceptionPtr = __error.toCpp()
|
|
222
|
+
return bridge.create_Result_void_(__exceptionPtr)
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
@inline(__always)
|
|
227
|
+
public final func replace(from: Double, to: Double, text: std.string) -> bridge.Result_double_ {
|
|
228
|
+
do {
|
|
229
|
+
let __result = try self.__implementation.replace(from: from, to: to, text: String(text))
|
|
230
|
+
let __resultCpp = __result
|
|
231
|
+
return bridge.create_Result_double_(__resultCpp)
|
|
232
|
+
} catch (let __error) {
|
|
233
|
+
let __exceptionPtr = __error.toCpp()
|
|
234
|
+
return bridge.create_Result_double_(__exceptionPtr)
|
|
235
|
+
}
|
|
236
|
+
}
|
|
214
237
|
}
|
|
@@ -22,6 +22,8 @@ namespace margelo::nitro::Markdown {
|
|
|
22
22
|
prototype.registerHybridMethod("getLength", &HybridMarkdownSessionSpec::getLength);
|
|
23
23
|
prototype.registerHybridMethod("getTextRange", &HybridMarkdownSessionSpec::getTextRange);
|
|
24
24
|
prototype.registerHybridMethod("addListener", &HybridMarkdownSessionSpec::addListener);
|
|
25
|
+
prototype.registerHybridMethod("reset", &HybridMarkdownSessionSpec::reset);
|
|
26
|
+
prototype.registerHybridMethod("replace", &HybridMarkdownSessionSpec::replace);
|
|
25
27
|
});
|
|
26
28
|
}
|
|
27
29
|
|
|
@@ -56,6 +56,8 @@ namespace margelo::nitro::Markdown {
|
|
|
56
56
|
virtual double getLength() = 0;
|
|
57
57
|
virtual std::string getTextRange(double from, double to) = 0;
|
|
58
58
|
virtual std::function<void()> addListener(const std::function<void(double /* from */, double /* to */)>& listener) = 0;
|
|
59
|
+
virtual void reset(const std::string& text) = 0;
|
|
60
|
+
virtual double replace(double from, double to, const std::string& text) = 0;
|
|
59
61
|
|
|
60
62
|
protected:
|
|
61
63
|
// Hybrid Setup
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-nitro-markdown",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "High-performance Markdown parser for React Native using Nitro Modules and md4c",
|
|
5
5
|
"main": "lib/commonjs/index.js",
|
|
6
6
|
"module": "lib/module/index.js",
|
|
@@ -61,7 +61,8 @@
|
|
|
61
61
|
"benchmark": "node ../../scripts/benchmark-comparison.js",
|
|
62
62
|
"prepack": "node -e \"const fs=require('fs'); fs.copyFileSync('../../README.md','./README.md'); fs.copyFileSync('../../LICENSE','./LICENSE')\"",
|
|
63
63
|
"postpack": "node -e \"const fs=require('fs'); if(fs.existsSync('./README.md'))fs.unlinkSync('./README.md'); if(fs.existsSync('./LICENSE'))fs.unlinkSync('./LICENSE')\"",
|
|
64
|
-
"test:cpp": "node scripts/test-cpp.js"
|
|
64
|
+
"test:cpp": "node scripts/test-cpp.js",
|
|
65
|
+
"size": "size-limit"
|
|
65
66
|
},
|
|
66
67
|
"keywords": [
|
|
67
68
|
"react-native",
|
|
@@ -87,17 +88,19 @@
|
|
|
87
88
|
"registry": "https://registry.npmjs.org/"
|
|
88
89
|
},
|
|
89
90
|
"devDependencies": {
|
|
91
|
+
"@size-limit/preset-small-lib": "^11.0.0",
|
|
90
92
|
"@types/react": "^19.2.14",
|
|
91
93
|
"@types/react-native": "^0.73.0",
|
|
92
94
|
"@types/react-test-renderer": "^19.1.0",
|
|
93
95
|
"react-native-builder-bob": "^0.40.18",
|
|
94
96
|
"react-test-renderer": "^19.2.4",
|
|
97
|
+
"size-limit": "^11.0.0",
|
|
95
98
|
"typescript": "^5.9.3"
|
|
96
99
|
},
|
|
97
100
|
"peerDependencies": {
|
|
98
101
|
"react": "*",
|
|
99
102
|
"react-native": ">=0.75.0",
|
|
100
|
-
"react-native-nitro-modules": "
|
|
103
|
+
"react-native-nitro-modules": ">=0.35.0",
|
|
101
104
|
"react-native-mathjax-svg": ">=0.9.0",
|
|
102
105
|
"react-native-svg": ">=13.0.0"
|
|
103
106
|
},
|
|
@@ -10,7 +10,7 @@ Pod::Spec.new do |s|
|
|
|
10
10
|
s.license = package["license"]
|
|
11
11
|
s.authors = package["author"]
|
|
12
12
|
|
|
13
|
-
s.platforms = { :ios => "
|
|
13
|
+
s.platforms = { :ios => "15.1" }
|
|
14
14
|
s.source = { :git => "https://github.com/JoaoPauloCMarra/react-native-nitro-markdown.git", :tag => "#{s.version}" }
|
|
15
15
|
s.module_name = "NitroMarkdown"
|
|
16
16
|
|
package/src/MarkdownContext.ts
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
type NodeStyleOverrides,
|
|
12
12
|
type StylingStrategy,
|
|
13
13
|
} from "./theme";
|
|
14
|
+
import type { CodeHighlighter } from "./utils/code-highlight";
|
|
14
15
|
|
|
15
16
|
export type NodeRendererProps = {
|
|
16
17
|
node: MarkdownNode;
|
|
@@ -91,6 +92,11 @@ export type MarkdownContextValue = {
|
|
|
91
92
|
styles?: NodeStyleOverrides;
|
|
92
93
|
stylingStrategy: StylingStrategy;
|
|
93
94
|
onLinkPress?: LinkPressHandler;
|
|
95
|
+
highlightCode?: boolean | CodeHighlighter;
|
|
96
|
+
tableOptions?: {
|
|
97
|
+
minColumnWidth?: number;
|
|
98
|
+
measurementStabilizeMs?: number;
|
|
99
|
+
};
|
|
94
100
|
};
|
|
95
101
|
|
|
96
102
|
export const MarkdownContext = createContext<MarkdownContextValue>({
|