react-native-marcus 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +227 -0
- package/RNMarcus.podspec +78 -0
- package/android/build.gradle +220 -0
- package/android/proguard-rules.pro +1 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/cpp/CMakeLists.txt +41 -0
- package/android/src/main/cpp/MarkdownParser.cpp +49 -0
- package/android/src/main/cpp/MarkdownParser.h +56 -0
- package/android/src/main/cpp/OnLoad.cpp +17 -0
- package/android/src/main/java/app/getbullet/marcus/MarcusModule.kt +28 -0
- package/android/src/main/java/app/getbullet/marcus/MarcusPackage.kt +31 -0
- package/android/src/main/java/app/getbullet/marcus/MarcusTextInputDecoratorView.kt +63 -0
- package/android/src/main/java/app/getbullet/marcus/MarcusTextInputDecoratorViewManager.kt +32 -0
- package/android/src/main/java/app/getbullet/marcus/MarcusTextInputDecoratorViewManagerSpec.kt +21 -0
- package/android/src/main/java/app/getbullet/marcus/MarkdownFormatter.kt +333 -0
- package/android/src/main/java/app/getbullet/marcus/MarkdownParseResult.kt +12 -0
- package/android/src/main/java/app/getbullet/marcus/MarkdownParser.kt +89 -0
- package/android/src/main/java/app/getbullet/marcus/MarkdownRange.kt +11 -0
- package/android/src/main/java/app/getbullet/marcus/MarkdownStyle.kt +81 -0
- package/android/src/main/java/app/getbullet/marcus/MarkdownTextWatcher.kt +17 -0
- package/android/src/main/java/app/getbullet/marcus/MarkdownUtils.kt +84 -0
- package/android/src/main/java/app/getbullet/marcus/ReactLineHeight.java +29 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownBackgroundColorSpan.kt +6 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownBackgroundSpan.kt +105 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownBlockIndentSpan.kt +67 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownBoldSpan.kt +6 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownFontFamilySpan.kt +28 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownFontSizeSpan.kt +7 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownForegroundColorSpan.kt +6 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownGapSpan.kt +57 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownItalicSpan.kt +6 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownLineHeightSpan.kt +21 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownSpan.kt +7 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownStrikethroughSpan.kt +5 -0
- package/android/src/main/java/app/getbullet/marcus/spans/MarkdownUnderlineSpan.kt +5 -0
- package/android/src/main/new_arch/CMakeLists.txt +70 -0
- package/android/src/main/new_arch/RNMarcusSpec.cpp +43 -0
- package/android/src/main/new_arch/RNMarcusSpec.h +36 -0
- package/android/src/main/new_arch/react/renderer/components/RNMarcusSpec/MarcusTextInputDecoratorShadowNode.cpp +218 -0
- package/android/src/main/new_arch/react/renderer/components/RNMarcusSpec/MarcusTextInputDecoratorShadowNode.h +54 -0
- package/android/src/reactNativeVersionPatch/CustomMountingManager/81/app/getbullet/marcus/CustomFabricUIManager.java +156 -0
- package/android/src/reactNativeVersionPatch/CustomMountingManager/latest/app/getbullet/marcus/CustomFabricUIManager.java +130 -0
- package/android/src/test/java/app/getbullet/marcus/MarkdownFormatterTest.kt +205 -0
- package/android/src/test/java/app/getbullet/marcus/RenderModel.kt +78 -0
- package/android/src/test/resources/render-model.txt +583 -0
- package/apple/MarcusModule.h +8 -0
- package/apple/MarcusModule.mm +26 -0
- package/apple/MarcusRange.h +15 -0
- package/apple/MarcusRange.mm +15 -0
- package/apple/MarcusTextInputDecoratorComponentView.h +12 -0
- package/apple/MarcusTextInputDecoratorComponentView.mm +121 -0
- package/apple/MarcusTextInputDecoratorShadowNode.cpp +251 -0
- package/apple/MarcusTextInputDecoratorShadowNode.h +65 -0
- package/apple/MarcusTextInputDecoratorShadowNode.mm +204 -0
- package/apple/MarcusTextInputDecoratorViewManager.h +8 -0
- package/apple/MarcusTextInputDecoratorViewManager.mm +11 -0
- package/apple/MarkdownAdaptiveImageGlyph.swift +44 -0
- package/apple/MarkdownAttributes.h +31 -0
- package/apple/MarkdownAttributes.m +9 -0
- package/apple/MarkdownBackedTextInputDelegate.swift +117 -0
- package/apple/MarkdownDecorator.swift +316 -0
- package/apple/MarkdownFonts.swift +21 -0
- package/apple/MarkdownFormatter+React.swift +51 -0
- package/apple/MarkdownFormatter.swift +509 -0
- package/apple/MarkdownLog.h +10 -0
- package/apple/MarkdownLog.mm +6 -0
- package/apple/MarkdownParser.swift +200 -0
- package/apple/MarkdownSwiftInterop.h +23 -0
- package/apple/MarkdownTextBackground.swift +17 -0
- package/apple/MarkdownTextFieldObserver.swift +90 -0
- package/apple/MarkdownTextLayoutFragment.swift +205 -0
- package/apple/MarkdownTextLayoutManagerDelegate.swift +84 -0
- package/apple/MarkdownTextStorageDelegate.swift +32 -0
- package/apple/MarkdownTextViewObserver.swift +30 -0
- package/apple/RCTMarcusStyle+Codegen.h +18 -0
- package/apple/RCTMarcusStyle+Codegen.mm +64 -0
- package/apple/RCTMarcusStyle.h +41 -0
- package/apple/RCTMarcusStyle.m +5 -0
- package/apple/RCTMarcusUtils.h +26 -0
- package/apple/RCTMarcusUtils.mm +26 -0
- package/apple/RCTTextInput+AdaptiveImageGlyph.h +16 -0
- package/apple/RCTTextInput+AdaptiveImageGlyph.mm +79 -0
- package/apple/RCTTextInputComponentView+Marcus.h +11 -0
- package/apple/RCTTextInputComponentView+Marcus.mm +79 -0
- package/cpp/MarkdownCxx.modulemap +8 -0
- package/cpp/MarkdownGlobal.cpp +48 -0
- package/cpp/MarkdownGlobal.h +33 -0
- package/cpp/MarkdownWorkletParser.cpp +93 -0
- package/cpp/MarkdownWorkletParser.h +45 -0
- package/cpp/RuntimeDecorator.cpp +39 -0
- package/cpp/RuntimeDecorator.h +14 -0
- package/cpp/react/renderer/components/RNMarcusSpec/MarcusTextInputDecoratorState.h +33 -0
- package/cpp/react/renderer/components/RNMarcusSpec/MarcusTextInputDecoratorViewComponentDescriptor.h +17 -0
- package/lib/commonjs/MarcusTextInputDecoratorViewNativeComponent.ts +77 -0
- package/lib/commonjs/MarkdownTextInput.js +99 -0
- package/lib/commonjs/MarkdownTextInput.js.map +1 -0
- package/lib/commonjs/MarkdownTextInput.web.js +618 -0
- package/lib/commonjs/MarkdownTextInput.web.js.map +1 -0
- package/lib/commonjs/NativeMarcusModule.js +9 -0
- package/lib/commonjs/NativeMarcusModule.js.map +1 -0
- package/lib/commonjs/commonTypes.js +2 -0
- package/lib/commonjs/commonTypes.js.map +1 -0
- package/lib/commonjs/global.d.js +2 -0
- package/lib/commonjs/global.d.js.map +1 -0
- package/lib/commonjs/index.js +27 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/parser/index.js +7030 -0
- package/lib/commonjs/parser/index.js.map +7 -0
- package/lib/commonjs/rangeUtils.js +71 -0
- package/lib/commonjs/rangeUtils.js.map +1 -0
- package/lib/commonjs/react-native-web.d.js +2 -0
- package/lib/commonjs/react-native-web.d.js.map +1 -0
- package/lib/commonjs/styleUtils.js +91 -0
- package/lib/commonjs/styleUtils.js.map +1 -0
- package/lib/commonjs/web/InputHistory.js +111 -0
- package/lib/commonjs/web/InputHistory.js.map +1 -0
- package/lib/commonjs/web/MarkdownTextInput.css +72 -0
- package/lib/commonjs/web/utils/blockLayout.js +132 -0
- package/lib/commonjs/web/utils/blockLayout.js.map +1 -0
- package/lib/commonjs/web/utils/blockUtils.js +219 -0
- package/lib/commonjs/web/utils/blockUtils.js.map +1 -0
- package/lib/commonjs/web/utils/browserUtils.js +40 -0
- package/lib/commonjs/web/utils/browserUtils.js.map +1 -0
- package/lib/commonjs/web/utils/cursorUtils.js +157 -0
- package/lib/commonjs/web/utils/cursorUtils.js.map +1 -0
- package/lib/commonjs/web/utils/inputUtils.js +152 -0
- package/lib/commonjs/web/utils/inputUtils.js.map +1 -0
- package/lib/commonjs/web/utils/measureUtils.js +0 -0
- package/lib/commonjs/web/utils/measureUtils.js.map +1 -0
- package/lib/commonjs/web/utils/parserUtils.js +552 -0
- package/lib/commonjs/web/utils/parserUtils.js.map +1 -0
- package/lib/commonjs/web/utils/treeUtils.js +109 -0
- package/lib/commonjs/web/utils/treeUtils.js.map +1 -0
- package/lib/commonjs/web/utils/webStyleUtils.js +59 -0
- package/lib/commonjs/web/utils/webStyleUtils.js.map +1 -0
- package/lib/module/MarcusTextInputDecoratorViewNativeComponent.ts +77 -0
- package/lib/module/MarkdownTextInput.js +94 -0
- package/lib/module/MarkdownTextInput.js.map +1 -0
- package/lib/module/MarkdownTextInput.web.js +612 -0
- package/lib/module/MarkdownTextInput.web.js.map +1 -0
- package/lib/module/NativeMarcusModule.js +5 -0
- package/lib/module/NativeMarcusModule.js.map +1 -0
- package/lib/module/commonTypes.js +2 -0
- package/lib/module/commonTypes.js.map +1 -0
- package/lib/module/global.d.js +2 -0
- package/lib/module/global.d.js.map +1 -0
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/parser/index.js +7029 -0
- package/lib/module/parser/index.js.map +7 -0
- package/lib/module/rangeUtils.js +66 -0
- package/lib/module/rangeUtils.js.map +1 -0
- package/lib/module/react-native-web.d.js +2 -0
- package/lib/module/react-native-web.d.js.map +1 -0
- package/lib/module/styleUtils.js +88 -0
- package/lib/module/styleUtils.js.map +1 -0
- package/lib/module/web/InputHistory.js +106 -0
- package/lib/module/web/InputHistory.js.map +1 -0
- package/lib/module/web/MarkdownTextInput.css +72 -0
- package/lib/module/web/utils/blockLayout.js +128 -0
- package/lib/module/web/utils/blockLayout.js.map +1 -0
- package/lib/module/web/utils/blockUtils.js +210 -0
- package/lib/module/web/utils/blockUtils.js.map +1 -0
- package/lib/module/web/utils/browserUtils.js +36 -0
- package/lib/module/web/utils/browserUtils.js.map +1 -0
- package/lib/module/web/utils/cursorUtils.js +150 -0
- package/lib/module/web/utils/cursorUtils.js.map +1 -0
- package/lib/module/web/utils/inputUtils.js +144 -0
- package/lib/module/web/utils/inputUtils.js.map +1 -0
- package/lib/module/web/utils/measureUtils.js +0 -0
- package/lib/module/web/utils/measureUtils.js.map +1 -0
- package/lib/module/web/utils/parserUtils.js +547 -0
- package/lib/module/web/utils/parserUtils.js.map +1 -0
- package/lib/module/web/utils/treeUtils.js +103 -0
- package/lib/module/web/utils/treeUtils.js.map +1 -0
- package/lib/module/web/utils/webStyleUtils.js +54 -0
- package/lib/module/web/utils/webStyleUtils.js.map +1 -0
- package/lib/typescript/commonjs/e2e/checks.test.d.ts +2 -0
- package/lib/typescript/commonjs/e2e/checks.test.d.ts.map +1 -0
- package/lib/typescript/commonjs/e2e/editing.test.d.ts +2 -0
- package/lib/typescript/commonjs/e2e/editing.test.d.ts.map +1 -0
- package/lib/typescript/commonjs/e2e/helpers.d.ts +23 -0
- package/lib/typescript/commonjs/e2e/helpers.d.ts.map +1 -0
- package/lib/typescript/commonjs/e2e/smoke.test.d.ts +2 -0
- package/lib/typescript/commonjs/e2e/smoke.test.d.ts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/src/MarcusTextInputDecoratorViewNativeComponent.d.ts +63 -0
- package/lib/typescript/commonjs/src/MarcusTextInputDecoratorViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/MarkdownTextInput.d.ts +22 -0
- package/lib/typescript/commonjs/src/MarkdownTextInput.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/MarkdownTextInput.web.d.ts +41 -0
- package/lib/typescript/commonjs/src/MarkdownTextInput.web.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/NativeMarcusModule.d.ts +7 -0
- package/lib/typescript/commonjs/src/NativeMarcusModule.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/commonTypes.d.ts +10 -0
- package/lib/typescript/commonjs/src/commonTypes.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +5 -0
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/parser/index.d.ts +8 -0
- package/lib/typescript/commonjs/src/parser/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/parser/micromark-extension-mentions.d.ts +8 -0
- package/lib/typescript/commonjs/src/parser/micromark-extension-mentions.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/rangeUtils.d.ts +6 -0
- package/lib/typescript/commonjs/src/rangeUtils.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/styleUtils.d.ts +8 -0
- package/lib/typescript/commonjs/src/styleUtils.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/web/InputHistory.d.ts +24 -0
- package/lib/typescript/commonjs/src/web/InputHistory.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/web/utils/blockLayout.d.ts +41 -0
- package/lib/typescript/commonjs/src/web/utils/blockLayout.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/web/utils/blockUtils.d.ts +33 -0
- package/lib/typescript/commonjs/src/web/utils/blockUtils.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/web/utils/browserUtils.d.ts +7 -0
- package/lib/typescript/commonjs/src/web/utils/browserUtils.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/web/utils/cursorUtils.d.ts +12 -0
- package/lib/typescript/commonjs/src/web/utils/cursorUtils.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/web/utils/inputUtils.d.ts +12 -0
- package/lib/typescript/commonjs/src/web/utils/inputUtils.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/web/utils/measureUtils.d.ts +22 -0
- package/lib/typescript/commonjs/src/web/utils/measureUtils.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/web/utils/parserUtils.d.ts +44 -0
- package/lib/typescript/commonjs/src/web/utils/parserUtils.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/web/utils/treeUtils.d.ts +25 -0
- package/lib/typescript/commonjs/src/web/utils/treeUtils.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/web/utils/webStyleUtils.d.ts +7 -0
- package/lib/typescript/commonjs/src/web/utils/webStyleUtils.d.ts.map +1 -0
- package/lib/typescript/module/e2e/checks.test.d.ts +2 -0
- package/lib/typescript/module/e2e/checks.test.d.ts.map +1 -0
- package/lib/typescript/module/e2e/editing.test.d.ts +2 -0
- package/lib/typescript/module/e2e/editing.test.d.ts.map +1 -0
- package/lib/typescript/module/e2e/helpers.d.ts +23 -0
- package/lib/typescript/module/e2e/helpers.d.ts.map +1 -0
- package/lib/typescript/module/e2e/smoke.test.d.ts +2 -0
- package/lib/typescript/module/e2e/smoke.test.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/src/MarcusTextInputDecoratorViewNativeComponent.d.ts +63 -0
- package/lib/typescript/module/src/MarcusTextInputDecoratorViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/module/src/MarkdownTextInput.d.ts +22 -0
- package/lib/typescript/module/src/MarkdownTextInput.d.ts.map +1 -0
- package/lib/typescript/module/src/MarkdownTextInput.web.d.ts +41 -0
- package/lib/typescript/module/src/MarkdownTextInput.web.d.ts.map +1 -0
- package/lib/typescript/module/src/NativeMarcusModule.d.ts +7 -0
- package/lib/typescript/module/src/NativeMarcusModule.d.ts.map +1 -0
- package/lib/typescript/module/src/commonTypes.d.ts +10 -0
- package/lib/typescript/module/src/commonTypes.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +5 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -0
- package/lib/typescript/module/src/parser/index.d.ts +8 -0
- package/lib/typescript/module/src/parser/index.d.ts.map +1 -0
- package/lib/typescript/module/src/parser/micromark-extension-mentions.d.ts +8 -0
- package/lib/typescript/module/src/parser/micromark-extension-mentions.d.ts.map +1 -0
- package/lib/typescript/module/src/rangeUtils.d.ts +6 -0
- package/lib/typescript/module/src/rangeUtils.d.ts.map +1 -0
- package/lib/typescript/module/src/styleUtils.d.ts +8 -0
- package/lib/typescript/module/src/styleUtils.d.ts.map +1 -0
- package/lib/typescript/module/src/web/InputHistory.d.ts +24 -0
- package/lib/typescript/module/src/web/InputHistory.d.ts.map +1 -0
- package/lib/typescript/module/src/web/utils/blockLayout.d.ts +41 -0
- package/lib/typescript/module/src/web/utils/blockLayout.d.ts.map +1 -0
- package/lib/typescript/module/src/web/utils/blockUtils.d.ts +33 -0
- package/lib/typescript/module/src/web/utils/blockUtils.d.ts.map +1 -0
- package/lib/typescript/module/src/web/utils/browserUtils.d.ts +7 -0
- package/lib/typescript/module/src/web/utils/browserUtils.d.ts.map +1 -0
- package/lib/typescript/module/src/web/utils/cursorUtils.d.ts +12 -0
- package/lib/typescript/module/src/web/utils/cursorUtils.d.ts.map +1 -0
- package/lib/typescript/module/src/web/utils/inputUtils.d.ts +12 -0
- package/lib/typescript/module/src/web/utils/inputUtils.d.ts.map +1 -0
- package/lib/typescript/module/src/web/utils/measureUtils.d.ts +22 -0
- package/lib/typescript/module/src/web/utils/measureUtils.d.ts.map +1 -0
- package/lib/typescript/module/src/web/utils/parserUtils.d.ts +44 -0
- package/lib/typescript/module/src/web/utils/parserUtils.d.ts.map +1 -0
- package/lib/typescript/module/src/web/utils/treeUtils.d.ts +25 -0
- package/lib/typescript/module/src/web/utils/treeUtils.d.ts.map +1 -0
- package/lib/typescript/module/src/web/utils/webStyleUtils.d.ts +7 -0
- package/lib/typescript/module/src/web/utils/webStyleUtils.d.ts.map +1 -0
- package/package.json +167 -0
- package/react-native.config.js +10 -0
- package/src/MarcusTextInputDecoratorViewNativeComponent.ts +77 -0
- package/src/MarkdownTextInput.tsx +139 -0
- package/src/MarkdownTextInput.web.tsx +958 -0
- package/src/NativeMarcusModule.ts +8 -0
- package/src/commonTypes.ts +30 -0
- package/src/global.d.ts +1 -0
- package/src/index.tsx +4 -0
- package/src/parser/index.ts +556 -0
- package/src/parser/micromark-extension-mentions.ts +82 -0
- package/src/rangeUtils.ts +68 -0
- package/src/react-native-web.d.ts +1 -0
- package/src/styleUtils.ts +100 -0
- package/src/web/InputHistory.ts +137 -0
- package/src/web/MarkdownTextInput.css +72 -0
- package/src/web/utils/blockLayout.ts +163 -0
- package/src/web/utils/blockUtils.ts +245 -0
- package/src/web/utils/browserUtils.ts +41 -0
- package/src/web/utils/cursorUtils.ts +204 -0
- package/src/web/utils/inputUtils.ts +206 -0
- package/src/web/utils/measureUtils.ts +0 -0
- package/src/web/utils/parserUtils.ts +813 -0
- package/src/web/utils/treeUtils.ts +149 -0
- package/src/web/utils/webStyleUtils.ts +69 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { HTMLMarkdownElement, MarkdownTextInputElement } from "../../MarkdownTextInput.web.js";
|
|
2
|
+
import type { TreeNode } from "./treeUtils.js";
|
|
3
|
+
import type { PartialMarkdownStyle } from "../../styleUtils.js";
|
|
4
|
+
import type { LineLayout } from "./blockLayout.js";
|
|
5
|
+
import type { TextMeasurer } from "./measureUtils.js";
|
|
6
|
+
import type { MarkdownRange } from "../../commonTypes.js";
|
|
7
|
+
type Paragraph = {
|
|
8
|
+
text: string;
|
|
9
|
+
start: number;
|
|
10
|
+
length: number;
|
|
11
|
+
markdownRanges: MarkdownRange[];
|
|
12
|
+
/** Where the containers this line sits in put its text, once they are all placed. */
|
|
13
|
+
layout?: LineLayout;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* For singleline markdown types, the function splits markdown ranges that spread beyond the line length into separate lines.
|
|
17
|
+
* For multiline markdown types (like `pre`), it merges them and corresponding text into one line.
|
|
18
|
+
*/
|
|
19
|
+
declare function normalizeLines(lines: Paragraph[], ranges: MarkdownRange[]): Paragraph[];
|
|
20
|
+
/** Builds HTML DOM structure based on passed text and markdown ranges */
|
|
21
|
+
declare function parseRangesToHTMLNodes(text: string, ranges: MarkdownRange[], isMultiline?: boolean, markdownStyle?: PartialMarkdownStyle, disableInlineStyles?: boolean, measure?: TextMeasurer): {
|
|
22
|
+
dom: HTMLMarkdownElement;
|
|
23
|
+
tree: TreeNode;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* A line as it was last rendered: what it was built from, the markup it produced, and its subtree.
|
|
27
|
+
*/
|
|
28
|
+
type CachedLine = {
|
|
29
|
+
signature: string;
|
|
30
|
+
html: string;
|
|
31
|
+
node: TreeNode;
|
|
32
|
+
};
|
|
33
|
+
type LineCache = {
|
|
34
|
+
markdownStyle: PartialMarkdownStyle;
|
|
35
|
+
isMultiline: boolean;
|
|
36
|
+
lines: CachedLine[];
|
|
37
|
+
};
|
|
38
|
+
declare function updateInputStructure(parserFunction: (input: string) => MarkdownRange[], target: MarkdownTextInputElement, text: string, cursorPositionIndex: number | null, isMultiline?: boolean, markdownStyle?: PartialMarkdownStyle, alwaysMoveCursorToTheEnd?: boolean, shouldForceDOMUpdate?: boolean, shouldScrollIntoView?: boolean): {
|
|
39
|
+
text: string;
|
|
40
|
+
cursorPosition: number;
|
|
41
|
+
};
|
|
42
|
+
export { updateInputStructure, parseRangesToHTMLNodes, normalizeLines };
|
|
43
|
+
export type { Paragraph, LineCache };
|
|
44
|
+
//# sourceMappingURL=parserUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parserUtils.d.ts","sourceRoot":"","sources":["../../../../../../src/web/utils/parserUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,gCAA6B,CAAA;AAEhG,OAAO,KAAK,EAAY,QAAQ,EAAE,MAAM,gBAAa,CAAA;AACrD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAkB,CAAA;AAS5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAe,CAAA;AAE/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAgB,CAAA;AAClD,OAAO,KAAK,EAAE,aAAa,EAAgB,MAAM,sBAAmB,CAAA;AAGpE,KAAK,SAAS,GAAG;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,EAAE,aAAa,EAAE,CAAA;IAC/B,qFAAqF;IACrF,MAAM,CAAC,EAAE,UAAU,CAAA;CACpB,CAAA;AAmFD;;;GAGG;AACH,iBAAS,cAAc,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,eA2BlE;AA2SD,yEAAyE;AACzE,iBAAS,sBAAsB,CAC7B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,aAAa,EAAE,EACvB,WAAW,UAAO,EAClB,aAAa,GAAE,oBAAyB,EACxC,mBAAmB,UAAQ,EAC3B,OAAO,GAAE,YAAuC;;;EAyBjD;AAED;;GAEG;AACH,KAAK,UAAU,GAAG;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,QAAQ,CAAA;CACf,CAAA;AAED,KAAK,SAAS,GAAG;IACf,aAAa,EAAE,oBAAoB,CAAA;IACnC,WAAW,EAAE,OAAO,CAAA;IACpB,KAAK,EAAE,UAAU,EAAE,CAAA;CACpB,CAAA;AA0QD,iBAAS,oBAAoB,CAC3B,cAAc,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,aAAa,EAAE,EAClD,MAAM,EAAE,wBAAwB,EAChC,IAAI,EAAE,MAAM,EACZ,mBAAmB,EAAE,MAAM,GAAG,IAAI,EAClC,WAAW,UAAO,EAClB,aAAa,GAAE,oBAAyB,EACxC,wBAAwB,UAAQ,EAChC,oBAAoB,UAAQ,EAC5B,oBAAoB,UAAQ;;;EAiD7B;AAED,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,cAAc,EAAE,CAAA;AACvE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { HTMLMarkdownElement } from "../../MarkdownTextInput.web.js";
|
|
2
|
+
import type { MarkdownRange, MarkdownType } from "../../commonTypes.js";
|
|
3
|
+
type NodeType = MarkdownType | "line" | "text" | "br" | "root";
|
|
4
|
+
type TreeNode = Omit<MarkdownRange, "type"> & {
|
|
5
|
+
element: HTMLMarkdownElement;
|
|
6
|
+
parentNode: TreeNode | null;
|
|
7
|
+
childNodes: TreeNode[];
|
|
8
|
+
type: NodeType;
|
|
9
|
+
orderIndex: string;
|
|
10
|
+
isGeneratingNewline: boolean;
|
|
11
|
+
};
|
|
12
|
+
declare function createRootTreeNode(target: HTMLMarkdownElement, length?: number, start?: number): TreeNode;
|
|
13
|
+
/**
|
|
14
|
+
* @param start Where the node begins in the text, when the caller knows it. A markdown range
|
|
15
|
+
* carries its own offset, and taking it is the only way to be right when ranges do not tile the
|
|
16
|
+
* line -- overlapping emphasis split across lines leaves gaps, and a node placed at wherever its
|
|
17
|
+
* previous sibling happened to end then reports an offset the text never had. Text and line breaks
|
|
18
|
+
* genuinely do follow on from what precedes them, so they still accumulate.
|
|
19
|
+
*/
|
|
20
|
+
declare function addNodeToTree(element: HTMLMarkdownElement, parentTreeNode: TreeNode, type: NodeType, length?: number | null, start?: number | null): TreeNode;
|
|
21
|
+
declare function findHTMLElementInTree(treeRoot: TreeNode, element: HTMLElement): TreeNode | null;
|
|
22
|
+
declare function getTreeNodeByIndex(treeRoot: TreeNode, index: number): TreeNode | null;
|
|
23
|
+
export { addNodeToTree, findHTMLElementInTree, getTreeNodeByIndex, createRootTreeNode };
|
|
24
|
+
export type { TreeNode, NodeType };
|
|
25
|
+
//# sourceMappingURL=treeUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"treeUtils.d.ts","sourceRoot":"","sources":["../../../../../../src/web/utils/treeUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAA6B,CAAA;AACtE,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,sBAAmB,CAAA;AAEpE,KAAK,QAAQ,GAAG,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,MAAM,CAAA;AAE9D,KAAK,QAAQ,GAAG,IAAI,CAAC,aAAa,EAAE,MAAM,CAAC,GAAG;IAC5C,OAAO,EAAE,mBAAmB,CAAA;IAC5B,UAAU,EAAE,QAAQ,GAAG,IAAI,CAAA;IAC3B,UAAU,EAAE,QAAQ,EAAE,CAAA;IACtB,IAAI,EAAE,QAAQ,CAAA;IACd,UAAU,EAAE,MAAM,CAAA;IAClB,mBAAmB,EAAE,OAAO,CAAA;CAC7B,CAAA;AAED,iBAAS,kBAAkB,CAAC,MAAM,EAAE,mBAAmB,EAAE,MAAM,SAAI,EAAE,KAAK,SAAI,GAAG,QAAQ,CAWxF;AAED;;;;;;GAMG;AACH,iBAAS,aAAa,CACpB,OAAO,EAAE,mBAAmB,EAC5B,cAAc,EAAE,QAAQ,EACxB,IAAI,EAAE,QAAQ,EACd,MAAM,GAAE,MAAM,GAAG,IAAW,EAC5B,KAAK,GAAE,MAAM,GAAG,IAAW,YAyC5B;AAED,iBAAS,qBAAqB,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,WAAW,GAAG,QAAQ,GAAG,IAAI,CAuBxF;AAED,iBAAS,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAqC9E;AAED,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,CAAA;AAEvF,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { TextStyle } from "react-native";
|
|
2
|
+
import type { MarkdownStyle } from "../../MarcusTextInputDecoratorViewNativeComponent";
|
|
3
|
+
declare function processMarkdownStyle(input: MarkdownStyle | undefined): MarkdownStyle;
|
|
4
|
+
declare function parseToReactDOMStyle(style: TextStyle): any;
|
|
5
|
+
declare const idGenerator: Generator<string, void, unknown>;
|
|
6
|
+
export { parseToReactDOMStyle, processMarkdownStyle, idGenerator };
|
|
7
|
+
//# sourceMappingURL=webStyleUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webStyleUtils.d.ts","sourceRoot":"","sources":["../../../../../../src/web/utils/webStyleUtils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mDAAmD,CAAA;AAiDtF,iBAAS,oBAAoB,CAAC,KAAK,EAAE,aAAa,GAAG,SAAS,GAAG,aAAa,CAE7E;AAED,iBAAS,oBAAoB,CAAC,KAAK,EAAE,SAAS,GAAG,GAAG,CAEnD;AASD,QAAA,MAAM,WAAW,kCAAqB,CAAA;AAEtC,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,WAAW,EAAE,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-native-marcus",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Drop-in replacement for React Native's TextInput component with Markdown formatting.",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Tomas Ravinskas",
|
|
7
|
+
"email": "tomas@tomasrav.me",
|
|
8
|
+
"url": "https://tomasrav.me/"
|
|
9
|
+
},
|
|
10
|
+
"contributors": [
|
|
11
|
+
"Expensify, Inc."
|
|
12
|
+
],
|
|
13
|
+
"license": "Apache-2.0",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git@github.com:getbullet-app/react-native-marcus.git"
|
|
17
|
+
},
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/getbullet-app/react-native-marcus/issues"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/getbullet-app/react-native-marcus",
|
|
22
|
+
"main": "./lib/commonjs/index.js",
|
|
23
|
+
"module": "./lib/module/index.js",
|
|
24
|
+
"types": "./lib/typescript/commonjs/src/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"import": {
|
|
28
|
+
"types": "./lib/typescript/module/src/index.d.ts",
|
|
29
|
+
"default": "./lib/module/index.js"
|
|
30
|
+
},
|
|
31
|
+
"require": {
|
|
32
|
+
"types": "./lib/typescript/commonjs/src/index.d.ts",
|
|
33
|
+
"default": "./lib/commonjs/index.js"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"./package.json": "./package.json"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"clean": "del-cli '{.,example}/{android,ios}/**/{build,.cxx}' lib",
|
|
40
|
+
"clean:codegen": "del-cli '{.,example}/{android,ios}/**/build/generated' '{.,example}/ios/Pod{s,file.lock}' && npx --workspace=marcus-example pod-install",
|
|
41
|
+
"example": "npm run --workspace=marcus-example",
|
|
42
|
+
"prepare": "patch-package && bob build && node scripts/bundle-parser.mjs",
|
|
43
|
+
"watch": "nodemon --watch src --ext 'ts tsx js jsx json' --exec npm run prepare",
|
|
44
|
+
"fixtures": "tsx scripts/emit-fixtures.mts",
|
|
45
|
+
"fixtures:check": "tsx scripts/emit-fixtures.mts --check",
|
|
46
|
+
"web:build": "npm run --workspace=marcus-example export:web",
|
|
47
|
+
"web:serve": "npm run --workspace=marcus-example serve:web",
|
|
48
|
+
"test": "npm run fixtures:check && tsc --noEmit && npm run test:unit && npm run web:build && npm run test:web && npm run test:android && npm run test:ios",
|
|
49
|
+
"test:unit": "jest",
|
|
50
|
+
"test:unit:watch": "jest --watch",
|
|
51
|
+
"test:update": "npm run fixtures && npm run test:unit -- -u && npm run web:build && npm run test:web -- -u && npm run test:android:update && npm run test:ios:update",
|
|
52
|
+
"test:web": "playwright test",
|
|
53
|
+
"test:e2e": "npm run test:e2e:ios && npm run test:e2e:android",
|
|
54
|
+
"test:e2e:ios": "detox build-framework-cache && detox build -c ios && detox test -c ios",
|
|
55
|
+
"test:e2e:android": "detox build -c android && detox test -c android",
|
|
56
|
+
"test:android": "cd example/android && ./gradlew :react-native-marcus:testDebugUnitTest",
|
|
57
|
+
"test:android:update": "rm -f android/src/test/resources/render-model.txt && npm run test:android",
|
|
58
|
+
"test:ios": "node scripts/ios-test.mjs -quiet",
|
|
59
|
+
"test:ios:update": "rm -f ios-tests/Tests/MarcusFormatterTests/__baselines__/render-model.txt && npm run test:ios"
|
|
60
|
+
},
|
|
61
|
+
"workspaces": [
|
|
62
|
+
"./example"
|
|
63
|
+
],
|
|
64
|
+
"files": [
|
|
65
|
+
"src",
|
|
66
|
+
"lib",
|
|
67
|
+
"android",
|
|
68
|
+
"apple",
|
|
69
|
+
"cpp",
|
|
70
|
+
"*.podspec",
|
|
71
|
+
"react-native.config.js",
|
|
72
|
+
"!apple/build",
|
|
73
|
+
"!android/build",
|
|
74
|
+
"!android/gradle",
|
|
75
|
+
"!android/gradlew",
|
|
76
|
+
"!android/gradlew.bat",
|
|
77
|
+
"!android/local.properties",
|
|
78
|
+
"!**/__tests__",
|
|
79
|
+
"!**/__fixtures__",
|
|
80
|
+
"!**/__mocks__",
|
|
81
|
+
"!**/.*"
|
|
82
|
+
],
|
|
83
|
+
"keywords": [
|
|
84
|
+
"react-native",
|
|
85
|
+
"ios",
|
|
86
|
+
"android",
|
|
87
|
+
"web",
|
|
88
|
+
"markdown"
|
|
89
|
+
],
|
|
90
|
+
"peerDependencies": {
|
|
91
|
+
"react": "*",
|
|
92
|
+
"react-native": ">=0.81",
|
|
93
|
+
"react-native-web": "^0.21.0",
|
|
94
|
+
"react-native-worklets": ">=0.7.0"
|
|
95
|
+
},
|
|
96
|
+
"peerDependenciesMeta": {
|
|
97
|
+
"react-native-web": {
|
|
98
|
+
"optional": true
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
"devDependencies": {
|
|
102
|
+
"@playwright/test": "^1.62.1",
|
|
103
|
+
"@react-native/babel-preset": "^0.86.3",
|
|
104
|
+
"@react-native/jest-preset": "^0.86.3",
|
|
105
|
+
"@types/jest": "^29.5.14",
|
|
106
|
+
"@types/react": "^19.2.0",
|
|
107
|
+
"del-cli": "^7.0.0",
|
|
108
|
+
"detox": "^20.51.4",
|
|
109
|
+
"emoji-regex": "^10.6.0",
|
|
110
|
+
"esbuild": "^0.25.0",
|
|
111
|
+
"fast-check": "^4.9.0",
|
|
112
|
+
"jest": "^29.6.3",
|
|
113
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
114
|
+
"kleur": "^4.1.5",
|
|
115
|
+
"mdast-util-from-markdown": "^2.0.3",
|
|
116
|
+
"micromark-extension-gfm-autolink-literal": "^2.1.0",
|
|
117
|
+
"micromark-extension-gfm-strikethrough": "^2.1.0",
|
|
118
|
+
"nodemon": "^3.1.14",
|
|
119
|
+
"patch-package": "^8.0.0",
|
|
120
|
+
"prettier": "2.8.8",
|
|
121
|
+
"react": "19.2.3",
|
|
122
|
+
"react-dom": "19.2.3",
|
|
123
|
+
"react-native": "^0.86.3",
|
|
124
|
+
"react-native-builder-bob": "^0.43.0",
|
|
125
|
+
"react-native-web": "^0.21.2",
|
|
126
|
+
"react-native-worklets": "0.10.1",
|
|
127
|
+
"tsx": "^4.23.13",
|
|
128
|
+
"typescript": "~6.0.3"
|
|
129
|
+
},
|
|
130
|
+
"overrides": {
|
|
131
|
+
"react": "19.2.3",
|
|
132
|
+
"react-dom": "19.2.3"
|
|
133
|
+
},
|
|
134
|
+
"react-native-builder-bob": {
|
|
135
|
+
"source": "src",
|
|
136
|
+
"output": "lib",
|
|
137
|
+
"targets": [
|
|
138
|
+
[
|
|
139
|
+
"module",
|
|
140
|
+
{
|
|
141
|
+
"esm": true
|
|
142
|
+
}
|
|
143
|
+
],
|
|
144
|
+
[
|
|
145
|
+
"commonjs",
|
|
146
|
+
{
|
|
147
|
+
"esm": true
|
|
148
|
+
}
|
|
149
|
+
],
|
|
150
|
+
"typescript"
|
|
151
|
+
],
|
|
152
|
+
"exclude": "**/{__tests__,__fixtures__,__mocks__,parser}/**"
|
|
153
|
+
},
|
|
154
|
+
"codegenConfig": {
|
|
155
|
+
"name": "RNMarcusSpec",
|
|
156
|
+
"type": "all",
|
|
157
|
+
"jsSrcsDir": "src",
|
|
158
|
+
"android": {
|
|
159
|
+
"javaPackageName": "app.getbullet.marcus"
|
|
160
|
+
},
|
|
161
|
+
"ios": {
|
|
162
|
+
"componentProvider": {
|
|
163
|
+
"MarcusTextInputDecoratorView": "MarcusTextInputDecoratorComponentView"
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { codegenNativeComponent } from "react-native"
|
|
2
|
+
import type { ColorValue, ViewProps } from "react-native"
|
|
3
|
+
|
|
4
|
+
import type { Float, Int32 } from "react-native/Libraries/Types/CodegenTypes"
|
|
5
|
+
|
|
6
|
+
// Font, colour and background, and nothing else: neither formatter draws a
|
|
7
|
+
// border or reserves padding around a code run, so there is nothing to
|
|
8
|
+
// configure.
|
|
9
|
+
interface CodeBlockStyle {
|
|
10
|
+
fontFamily: string
|
|
11
|
+
fontSize: Float
|
|
12
|
+
color: ColorValue
|
|
13
|
+
backgroundColor: ColorValue
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface MarkdownStyle {
|
|
17
|
+
syntax: {
|
|
18
|
+
color: ColorValue
|
|
19
|
+
}
|
|
20
|
+
emoji: {
|
|
21
|
+
fontSize: Float
|
|
22
|
+
fontFamily: string
|
|
23
|
+
}
|
|
24
|
+
link: {
|
|
25
|
+
color: ColorValue
|
|
26
|
+
}
|
|
27
|
+
heading: {
|
|
28
|
+
fontSize: Float
|
|
29
|
+
// Each level down multiplies the one above, so level N is
|
|
30
|
+
// fontSize * scale^(N - 1). Six levels, matching HTML.
|
|
31
|
+
scale: Float
|
|
32
|
+
}
|
|
33
|
+
blockquote: {
|
|
34
|
+
borderColor: ColorValue
|
|
35
|
+
borderWidth: Float
|
|
36
|
+
marginLeft: Float
|
|
37
|
+
paddingLeft: Float
|
|
38
|
+
}
|
|
39
|
+
// Indent only, no gutter decoration. Kept as two separate entries so a
|
|
40
|
+
// renderer can style ordered and unordered lists differently.
|
|
41
|
+
orderedList: {
|
|
42
|
+
marginLeft: Float
|
|
43
|
+
paddingLeft: Float
|
|
44
|
+
}
|
|
45
|
+
unorderedList: {
|
|
46
|
+
marginLeft: Float
|
|
47
|
+
paddingLeft: Float
|
|
48
|
+
}
|
|
49
|
+
code: CodeBlockStyle
|
|
50
|
+
pre: CodeBlockStyle
|
|
51
|
+
mentionHere: {
|
|
52
|
+
color: ColorValue
|
|
53
|
+
backgroundColor: ColorValue
|
|
54
|
+
borderRadius?: Float
|
|
55
|
+
}
|
|
56
|
+
mentionUser: {
|
|
57
|
+
color: ColorValue
|
|
58
|
+
backgroundColor: ColorValue
|
|
59
|
+
borderRadius?: Float
|
|
60
|
+
}
|
|
61
|
+
mentionReport: {
|
|
62
|
+
color: ColorValue
|
|
63
|
+
backgroundColor: ColorValue
|
|
64
|
+
borderRadius?: Float
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
interface NativeProps extends ViewProps {
|
|
69
|
+
markdownStyle: MarkdownStyle
|
|
70
|
+
parserId: Int32
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export default codegenNativeComponent<NativeProps>("MarcusTextInputDecoratorView", {
|
|
74
|
+
interfaceOnly: true,
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
export type { MarkdownStyle }
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { StyleSheet, TextInput, processColor } from "react-native"
|
|
2
|
+
import React from "react"
|
|
3
|
+
import type { TextInputProps } from "react-native"
|
|
4
|
+
import { createSerializable, createWorkletRuntime } from "react-native-worklets"
|
|
5
|
+
import type { SerializableRef, WorkletFunction, WorkletRuntime } from "react-native-worklets"
|
|
6
|
+
import MarcusTextInputDecoratorViewNativeComponent from "./MarcusTextInputDecoratorViewNativeComponent"
|
|
7
|
+
import type { MarkdownStyle } from "./MarcusTextInputDecoratorViewNativeComponent"
|
|
8
|
+
import NativeMarcusModule from "./NativeMarcusModule"
|
|
9
|
+
import { mergeMarkdownStyleWithDefault } from "./styleUtils"
|
|
10
|
+
import type { PartialMarkdownStyle } from "./styleUtils"
|
|
11
|
+
import type { MarkdownRange } from "./commonTypes"
|
|
12
|
+
|
|
13
|
+
declare global {
|
|
14
|
+
// eslint-disable-next-line no-var
|
|
15
|
+
var jsi_setMarcusRuntime: (runtime: WorkletRuntime) => void
|
|
16
|
+
// eslint-disable-next-line no-var
|
|
17
|
+
var jsi_registerMarcusWorklet: (
|
|
18
|
+
shareableWorklet: SerializableRef<WorkletFunction<[string], MarkdownRange[]>>,
|
|
19
|
+
) => number
|
|
20
|
+
// eslint-disable-next-line no-var
|
|
21
|
+
var jsi_unregisterMarcusWorklet: (parserId: number) => void
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let initialized = false
|
|
25
|
+
let workletRuntime: WorkletRuntime | undefined
|
|
26
|
+
|
|
27
|
+
function getWorkletRuntime(): WorkletRuntime {
|
|
28
|
+
if (workletRuntime === undefined) {
|
|
29
|
+
throw new Error(
|
|
30
|
+
"[react-native-marcus] Worklet runtime hasn't been created yet. Please avoid calling `getWorkletRuntime()` in top-level scope. Instead, call `getWorkletRuntime()` directly in `runOnRuntime` arguments list.",
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
return workletRuntime
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function initializeMarcusIfNeeded() {
|
|
37
|
+
if (initialized) {
|
|
38
|
+
return
|
|
39
|
+
}
|
|
40
|
+
if (NativeMarcusModule) {
|
|
41
|
+
NativeMarcusModule.install()
|
|
42
|
+
}
|
|
43
|
+
if (!global.jsi_setMarcusRuntime) {
|
|
44
|
+
throw new Error("[react-native-marcus] global.jsi_setMarcusRuntime is not available")
|
|
45
|
+
}
|
|
46
|
+
workletRuntime = createWorkletRuntime({ name: "MarcusRuntime" })
|
|
47
|
+
global.jsi_setMarcusRuntime(workletRuntime)
|
|
48
|
+
initialized = true
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function registerParser(parser: (input: string) => MarkdownRange[]): number {
|
|
52
|
+
initializeMarcusIfNeeded()
|
|
53
|
+
const serializableWorklet = createSerializable(
|
|
54
|
+
parser as WorkletFunction<[string], MarkdownRange[]>,
|
|
55
|
+
)
|
|
56
|
+
const parserId = global.jsi_registerMarcusWorklet(serializableWorklet)
|
|
57
|
+
return parserId
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function unregisterParser(parserId: number) {
|
|
61
|
+
global.jsi_unregisterMarcusWorklet(parserId)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
interface MarkdownTextInputProps extends TextInputProps {
|
|
65
|
+
markdownStyle?: PartialMarkdownStyle
|
|
66
|
+
parser: (value: string) => MarkdownRange[]
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
type MarkdownTextInput = TextInput & React.Component<MarkdownTextInputProps>
|
|
70
|
+
|
|
71
|
+
function processColorsInMarkdownStyle(input: MarkdownStyle): MarkdownStyle {
|
|
72
|
+
const output = JSON.parse(JSON.stringify(input))
|
|
73
|
+
|
|
74
|
+
Object.keys(output).forEach((key) => {
|
|
75
|
+
const obj = output[key]
|
|
76
|
+
Object.keys(obj).forEach((prop) => {
|
|
77
|
+
// TODO: use ReactNativeStyleAttributes from 'react-native/Libraries/Components/View/ReactNativeStyleAttributes'
|
|
78
|
+
if (!(prop === "color" || prop.endsWith("Color"))) {
|
|
79
|
+
return
|
|
80
|
+
}
|
|
81
|
+
obj[prop] = processColor(obj[prop])
|
|
82
|
+
})
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
return output as MarkdownStyle
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function processMarkdownStyle(input: PartialMarkdownStyle | undefined): MarkdownStyle {
|
|
89
|
+
return processColorsInMarkdownStyle(mergeMarkdownStyleWithDefault(input))
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const MarkdownTextInput = React.forwardRef<MarkdownTextInput, MarkdownTextInputProps>(
|
|
93
|
+
(props, ref) => {
|
|
94
|
+
const markdownStyle = React.useMemo(
|
|
95
|
+
() => processMarkdownStyle(props.markdownStyle),
|
|
96
|
+
[props.markdownStyle],
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
if (props.parser === undefined) {
|
|
100
|
+
throw new Error("[react-native-marcus] `parser` is undefined")
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
104
|
+
const workletHash = (props.parser as { __workletHash?: number }).__workletHash
|
|
105
|
+
if (workletHash === undefined) {
|
|
106
|
+
throw new Error("[react-native-marcus] `parser` is not a worklet")
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const parserId = React.useMemo(() => {
|
|
110
|
+
return registerParser(props.parser)
|
|
111
|
+
}, [props.parser])
|
|
112
|
+
|
|
113
|
+
React.useEffect(() => {
|
|
114
|
+
return () => unregisterParser(parserId)
|
|
115
|
+
}, [parserId])
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
<MarcusTextInputDecoratorViewNativeComponent
|
|
119
|
+
style={styles.displayContents}
|
|
120
|
+
markdownStyle={markdownStyle}
|
|
121
|
+
parserId={parserId}
|
|
122
|
+
>
|
|
123
|
+
<TextInput {...props} ref={ref} />
|
|
124
|
+
</MarcusTextInputDecoratorViewNativeComponent>
|
|
125
|
+
)
|
|
126
|
+
},
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
const styles = StyleSheet.create({
|
|
130
|
+
displayContents: {
|
|
131
|
+
display: "contents",
|
|
132
|
+
},
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
export type { PartialMarkdownStyle as MarkdownStyle, MarkdownTextInputProps }
|
|
136
|
+
|
|
137
|
+
export default MarkdownTextInput
|
|
138
|
+
|
|
139
|
+
export { getWorkletRuntime }
|