react-native-jet-markdown 0.2.0 → 0.2.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 +4 -56
- package/android/src/main/cpp/JniBindings.cpp +0 -106
- package/android/src/main/java/com/jetmarkdown/JetMarkdownNative.kt +0 -79
- package/android/src/main/java/com/jetmarkdown/JetMarkdownPackage.kt +1 -2
- package/android/src/main/java/com/jetmarkdown/render/spans/MarkdownLineHeightSpan.kt +2 -13
- package/cpp/react/override/react/renderer/components/JetMarkdownViewSpec/ComponentDescriptors.h +0 -4
- package/cpp/tests/parser_tests.cpp +0 -402
- package/cpp/tests/run_tests.sh +0 -3
- package/ios/JetMarkdownView.mm +33 -2
- package/lib/module/index.js +0 -2
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -3
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +0 -127
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/package.json +2 -5
- package/src/index.tsx +0 -9
- package/src/types.ts +0 -134
- package/android/src/main/java/com/jetmarkdown/editor/EditorSpans.kt +0 -217
- package/android/src/main/java/com/jetmarkdown/editor/JetMarkdownEditorManager.kt +0 -224
- package/android/src/main/java/com/jetmarkdown/editor/JetMarkdownEditorView.kt +0 -1736
- package/cpp/core/AstToMarkdown.cpp +0 -549
- package/cpp/core/AstToMarkdown.h +0 -16
- package/cpp/core/EditorRuns.cpp +0 -640
- package/cpp/core/EditorRuns.h +0 -94
- package/cpp/core/EditorText.cpp +0 -15
- package/cpp/core/EditorText.h +0 -18
- package/cpp/react/JetMarkdownEditorShadowNode.cpp +0 -54
- package/cpp/react/JetMarkdownEditorShadowNode.h +0 -55
- package/cpp/react/JetMarkdownEditorState.h +0 -35
- package/ios/editor/JetMarkdownEditor.h +0 -12
- package/ios/editor/JetMarkdownEditor.mm +0 -2002
- package/lib/module/JetMarkdownEditor.js +0 -85
- package/lib/module/JetMarkdownEditor.js.map +0 -1
- package/lib/module/JetMarkdownEditor.native.js +0 -244
- package/lib/module/JetMarkdownEditor.native.js.map +0 -1
- package/lib/module/JetMarkdownEditorNativeComponent.ts +0 -173
- package/lib/module/useJetMarkdownEditor.js +0 -41
- package/lib/module/useJetMarkdownEditor.js.map +0 -1
- package/lib/typescript/src/JetMarkdownEditor.d.ts +0 -6
- package/lib/typescript/src/JetMarkdownEditor.d.ts.map +0 -1
- package/lib/typescript/src/JetMarkdownEditor.native.d.ts +0 -6
- package/lib/typescript/src/JetMarkdownEditor.native.d.ts.map +0 -1
- package/lib/typescript/src/JetMarkdownEditorNativeComponent.d.ts +0 -105
- package/lib/typescript/src/JetMarkdownEditorNativeComponent.d.ts.map +0 -1
- package/lib/typescript/src/useJetMarkdownEditor.d.ts +0 -36
- package/lib/typescript/src/useJetMarkdownEditor.d.ts.map +0 -1
- package/src/JetMarkdownEditor.native.tsx +0 -301
- package/src/JetMarkdownEditor.tsx +0 -90
- package/src/JetMarkdownEditorNativeComponent.ts +0 -173
- package/src/useJetMarkdownEditor.ts +0 -50
package/cpp/core/EditorRuns.h
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <cstdint>
|
|
4
|
-
#include <string>
|
|
5
|
-
#include <vector>
|
|
6
|
-
|
|
7
|
-
namespace jetmarkdown {
|
|
8
|
-
|
|
9
|
-
// Inline mark bits carried by editor styled runs. Mirrored by the native
|
|
10
|
-
// editors (JMDEditorMarks attribute on iOS, EditorMarkSpan on Android).
|
|
11
|
-
enum EditorMark : uint32_t {
|
|
12
|
-
MarkBold = 1u << 0,
|
|
13
|
-
MarkItalic = 1u << 1,
|
|
14
|
-
MarkStrikethrough = 1u << 2,
|
|
15
|
-
MarkInlineCode = 1u << 3,
|
|
16
|
-
MarkSpoiler = 1u << 4,
|
|
17
|
-
MarkSuperscript = 1u << 5,
|
|
18
|
-
MarkSubscript = 1u << 6,
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
// Per-line block types. Mirrored by the native editors (JMDEditorBlock
|
|
22
|
-
// attribute on iOS, EditorBlockSpan on Android).
|
|
23
|
-
enum class EditorBlockType : uint8_t {
|
|
24
|
-
Paragraph = 0,
|
|
25
|
-
Heading = 1, // level = 1..6
|
|
26
|
-
Quote = 2,
|
|
27
|
-
Code = 3,
|
|
28
|
-
Bullet = 4,
|
|
29
|
-
Ordered = 5,
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
// A contiguous marked range over the editor's text. Offsets are UTF-16 code
|
|
33
|
-
// units (NSRange / Spannable indices), converted internally.
|
|
34
|
-
struct StyledRun {
|
|
35
|
-
uint32_t start = 0;
|
|
36
|
-
uint32_t end = 0;
|
|
37
|
-
uint32_t flags = 0;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
struct EditorLine {
|
|
41
|
-
EditorBlockType type = EditorBlockType::Paragraph;
|
|
42
|
-
uint8_t level = 0;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
// A linked range (mentions are links whose URL carries an app scheme, e.g.
|
|
46
|
-
// users://ali). Links never overlap; offsets are UTF-16 code units.
|
|
47
|
-
struct LinkRun {
|
|
48
|
-
uint32_t start = 0;
|
|
49
|
-
uint32_t end = 0;
|
|
50
|
-
std::string url;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
struct StyledText {
|
|
54
|
-
std::string text;
|
|
55
|
-
std::vector<StyledRun> runs;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
struct EditorDocument {
|
|
59
|
-
std::string text;
|
|
60
|
-
std::vector<StyledRun> runs;
|
|
61
|
-
// One entry per text line (newline-separated); missing entries mean
|
|
62
|
-
// Paragraph.
|
|
63
|
-
std::vector<EditorLine> lines;
|
|
64
|
-
std::vector<LinkRun> links;
|
|
65
|
-
// Running UTF-16 length of `text`, maintained by every append during
|
|
66
|
-
// extraction so run offsets never require an O(N) rescan (which made
|
|
67
|
-
// opening large documents quadratic).
|
|
68
|
-
uint32_t textUtf16Length = 0;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
// Serializes the editor's content to markdown. Every newline in `text` is a
|
|
72
|
-
// line break; `lines` assigns each line its block type, and consecutive
|
|
73
|
-
// same-type lines merge into one block (quote, code fence, list).
|
|
74
|
-
// Overlapping mark runs are nested by longest extent; inline-code content is
|
|
75
|
-
// emitted verbatim; run edges are trimmed past whitespace so emphasis
|
|
76
|
-
// delimiters always re-parse. Code lines ignore inline marks.
|
|
77
|
-
std::string markdownFromEditor(
|
|
78
|
-
const std::string& text,
|
|
79
|
-
const std::vector<StyledRun>& runs,
|
|
80
|
-
const std::vector<EditorLine>& lines,
|
|
81
|
-
const std::vector<LinkRun>& links = {});
|
|
82
|
-
|
|
83
|
-
// Parses markdown and flattens it to editor text + mark runs + line blocks
|
|
84
|
-
// (the inverse of markdownFromEditor for the editor's subset; unsupported
|
|
85
|
-
// structure flattens to paragraph lines).
|
|
86
|
-
EditorDocument editorFromMarkdown(const std::string& markdown);
|
|
87
|
-
|
|
88
|
-
// Marks-only conveniences (all lines are paragraphs).
|
|
89
|
-
std::string markdownFromStyledText(
|
|
90
|
-
const std::string& text,
|
|
91
|
-
const std::vector<StyledRun>& runs);
|
|
92
|
-
StyledText styledTextFromMarkdown(const std::string& markdown);
|
|
93
|
-
|
|
94
|
-
} // namespace jetmarkdown
|
package/cpp/core/EditorText.cpp
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
#include "EditorText.h"
|
|
2
|
-
|
|
3
|
-
#include "EditorRuns.h"
|
|
4
|
-
|
|
5
|
-
namespace jetmarkdown {
|
|
6
|
-
|
|
7
|
-
std::string markdownFromPlainText(const std::string& text) {
|
|
8
|
-
return markdownFromStyledText(text, {});
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
std::string plainTextFromMarkdown(const std::string& markdown) {
|
|
12
|
-
return styledTextFromMarkdown(markdown).text;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
} // namespace jetmarkdown
|
package/cpp/core/EditorText.h
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <string>
|
|
4
|
-
|
|
5
|
-
namespace jetmarkdown {
|
|
6
|
-
|
|
7
|
-
// E1 editor bridge: the editor holds plain text until inline marks (E2) and
|
|
8
|
-
// block formatting (E3) attach structure.
|
|
9
|
-
|
|
10
|
-
// Lines become paragraphs (blank lines separate them) and text is escaped,
|
|
11
|
-
// so literal markdown characters the user typed survive as literals.
|
|
12
|
-
std::string markdownFromPlainText(const std::string& text);
|
|
13
|
-
|
|
14
|
-
// Flattens parsed markdown to the editor's plain-text representation:
|
|
15
|
-
// blocks become lines; inline formatting reduces to its text content.
|
|
16
|
-
std::string plainTextFromMarkdown(const std::string& markdown);
|
|
17
|
-
|
|
18
|
-
} // namespace jetmarkdown
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
#include "JetMarkdownEditorShadowNode.h"
|
|
2
|
-
|
|
3
|
-
#include <algorithm>
|
|
4
|
-
#include <cmath>
|
|
5
|
-
|
|
6
|
-
#include "JetMarkdownMeasurer.h"
|
|
7
|
-
|
|
8
|
-
namespace facebook::react {
|
|
9
|
-
|
|
10
|
-
Size JetMarkdownEditorShadowNode::measureContent(
|
|
11
|
-
const LayoutContext& layoutContext,
|
|
12
|
-
const LayoutConstraints& layoutConstraints) const {
|
|
13
|
-
const auto& props = getConcreteProps();
|
|
14
|
-
const auto& state = getStateData();
|
|
15
|
-
|
|
16
|
-
Float maxWidth = layoutConstraints.maximumSize.width;
|
|
17
|
-
if (!std::isfinite(maxWidth)) {
|
|
18
|
-
maxWidth = std::max(layoutConstraints.minimumSize.width, Float{0});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
Float height = static_cast<Float>(state.height);
|
|
22
|
-
if (height <= 0) {
|
|
23
|
-
// Initial layout: size the defaultValue (or one empty line) with the
|
|
24
|
-
// shared measurer so the editor mounts at its real height.
|
|
25
|
-
const std::string& markdown =
|
|
26
|
-
props.defaultValue.empty() ? " " : props.defaultValue;
|
|
27
|
-
float fontScale = 1.0f;
|
|
28
|
-
if (props.allowFontScaling && layoutContext.fontSizeMultiplier > 0) {
|
|
29
|
-
fontScale = static_cast<float>(layoutContext.fontSizeMultiplier);
|
|
30
|
-
}
|
|
31
|
-
height = static_cast<Float>(jetmarkdown::JetMarkdownMeasurer::shared().measure(
|
|
32
|
-
markdown,
|
|
33
|
-
props.stylesJson,
|
|
34
|
-
"{}",
|
|
35
|
-
static_cast<float>(maxWidth),
|
|
36
|
-
fontScale));
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Autogrow cap: past maxHeight the view scrolls internally instead of
|
|
40
|
-
// growing (the view publishes capped heights too; this covers the
|
|
41
|
-
// initial defaultValue measurement).
|
|
42
|
-
if (props.maxHeight > 0) {
|
|
43
|
-
height = std::min(height, static_cast<Float>(props.maxHeight));
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
height = std::clamp(
|
|
47
|
-
height,
|
|
48
|
-
layoutConstraints.minimumSize.height,
|
|
49
|
-
layoutConstraints.maximumSize.height);
|
|
50
|
-
|
|
51
|
-
return Size{maxWidth, height};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
} // namespace facebook::react
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <react/renderer/components/JetMarkdownViewSpec/EventEmitters.h>
|
|
4
|
-
#include <react/renderer/components/JetMarkdownViewSpec/Props.h>
|
|
5
|
-
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
|
|
6
|
-
#include <react/renderer/core/LayoutConstraints.h>
|
|
7
|
-
#include <react/renderer/core/LayoutContext.h>
|
|
8
|
-
|
|
9
|
-
#include "JetMarkdownEditorState.h"
|
|
10
|
-
|
|
11
|
-
namespace facebook::react {
|
|
12
|
-
|
|
13
|
-
// Defined in the codegen-generated ShadowNodes.cpp.
|
|
14
|
-
extern const char JetMarkdownEditorComponentName[];
|
|
15
|
-
|
|
16
|
-
// Custom shadow node: the editor grows with its content. The platform view
|
|
17
|
-
// publishes its measured height into state after every edit; before the
|
|
18
|
-
// first publish (initial layout), the shared markdown measurer sizes the
|
|
19
|
-
// defaultValue so prefilled editors mount at the right height.
|
|
20
|
-
class JetMarkdownEditorShadowNode final : public ConcreteViewShadowNode<
|
|
21
|
-
JetMarkdownEditorComponentName,
|
|
22
|
-
JetMarkdownEditorProps,
|
|
23
|
-
JetMarkdownEditorEventEmitter,
|
|
24
|
-
JetMarkdownEditorState> {
|
|
25
|
-
public:
|
|
26
|
-
JetMarkdownEditorShadowNode(
|
|
27
|
-
const ShadowNodeFragment& fragment,
|
|
28
|
-
const ShadowNodeFamily::Shared& family,
|
|
29
|
-
ShadowNodeTraits traits)
|
|
30
|
-
: ConcreteViewShadowNode(fragment, family, traits) {}
|
|
31
|
-
|
|
32
|
-
JetMarkdownEditorShadowNode(
|
|
33
|
-
const ShadowNode& sourceShadowNode,
|
|
34
|
-
const ShadowNodeFragment& fragment)
|
|
35
|
-
: ConcreteViewShadowNode(sourceShadowNode, fragment) {
|
|
36
|
-
// State carries the content height; Yoga must re-measure when a new
|
|
37
|
-
// state arrives.
|
|
38
|
-
if (fragment.state != nullptr) {
|
|
39
|
-
dirtyLayout();
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
static ShadowNodeTraits BaseTraits() {
|
|
44
|
-
auto traits = ConcreteViewShadowNode::BaseTraits();
|
|
45
|
-
traits.set(ShadowNodeTraits::Trait::LeafYogaNode);
|
|
46
|
-
traits.set(ShadowNodeTraits::Trait::MeasurableYogaNode);
|
|
47
|
-
return traits;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
Size measureContent(
|
|
51
|
-
const LayoutContext& layoutContext,
|
|
52
|
-
const LayoutConstraints& layoutConstraints) const override;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
} // namespace facebook::react
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#ifdef RN_SERIALIZABLE_STATE
|
|
4
|
-
#include <folly/dynamic.h>
|
|
5
|
-
#endif
|
|
6
|
-
|
|
7
|
-
namespace facebook::react {
|
|
8
|
-
|
|
9
|
-
// Shadow-node state: the editor's current content height, published by the
|
|
10
|
-
// platform view whenever the text changes so Fabric re-measures (autogrow).
|
|
11
|
-
class JetMarkdownEditorState final {
|
|
12
|
-
public:
|
|
13
|
-
JetMarkdownEditorState() = default;
|
|
14
|
-
explicit JetMarkdownEditorState(double height) : height(height) {}
|
|
15
|
-
|
|
16
|
-
#ifdef RN_SERIALIZABLE_STATE
|
|
17
|
-
JetMarkdownEditorState(
|
|
18
|
-
const JetMarkdownEditorState& previousState,
|
|
19
|
-
folly::dynamic data) {
|
|
20
|
-
height = previousState.height;
|
|
21
|
-
const auto& value = data["height"];
|
|
22
|
-
if (value.isNumber()) {
|
|
23
|
-
height = value.getDouble();
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
folly::dynamic getDynamic() const {
|
|
28
|
-
return folly::dynamic::object("height", height);
|
|
29
|
-
}
|
|
30
|
-
#endif
|
|
31
|
-
|
|
32
|
-
double height = 0;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
} // namespace facebook::react
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
#import <React/RCTViewComponentView.h>
|
|
2
|
-
#import <UIKit/UIKit.h>
|
|
3
|
-
|
|
4
|
-
NS_ASSUME_NONNULL_BEGIN
|
|
5
|
-
|
|
6
|
-
/// WYSIWYG markdown editor: hosts a UITextView, publishes its content
|
|
7
|
-
/// height into the shadow-node state (autogrow), and emits editing events.
|
|
8
|
-
@interface JetMarkdownEditor : RCTViewComponentView
|
|
9
|
-
|
|
10
|
-
@end
|
|
11
|
-
|
|
12
|
-
NS_ASSUME_NONNULL_END
|