@apollohg/react-native-prose-editor 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 +160 -0
- package/README.md +143 -0
- package/android/build.gradle +39 -0
- package/android/src/main/assets/editor-icons/MaterialIcons.json +2236 -0
- package/android/src/main/assets/editor-icons/MaterialIcons.ttf +0 -0
- package/android/src/main/java/com/apollohg/editor/EditorAddons.kt +131 -0
- package/android/src/main/java/com/apollohg/editor/EditorEditText.kt +1057 -0
- package/android/src/main/java/com/apollohg/editor/EditorHeightBehavior.kt +14 -0
- package/android/src/main/java/com/apollohg/editor/EditorInputConnection.kt +191 -0
- package/android/src/main/java/com/apollohg/editor/EditorTheme.kt +325 -0
- package/android/src/main/java/com/apollohg/editor/NativeEditorExpoView.kt +647 -0
- package/android/src/main/java/com/apollohg/editor/NativeEditorModule.kt +257 -0
- package/android/src/main/java/com/apollohg/editor/NativeToolbar.kt +714 -0
- package/android/src/main/java/com/apollohg/editor/PositionBridge.kt +76 -0
- package/android/src/main/java/com/apollohg/editor/RenderBridge.kt +1044 -0
- package/android/src/main/java/com/apollohg/editor/RichTextEditorView.kt +211 -0
- package/expo-module.config.json +9 -0
- package/ios/EditorAddons.swift +228 -0
- package/ios/EditorCore.xcframework/Info.plist +44 -0
- package/ios/EditorCore.xcframework/ios-arm64/libeditor_core.a +0 -0
- package/ios/EditorCore.xcframework/ios-arm64_x86_64-simulator/libeditor_core.a +0 -0
- package/ios/EditorLayoutManager.swift +254 -0
- package/ios/EditorTheme.swift +372 -0
- package/ios/Generated_editor_core.swift +1143 -0
- package/ios/NativeEditorExpoView.swift +1417 -0
- package/ios/NativeEditorModule.swift +263 -0
- package/ios/PositionBridge.swift +278 -0
- package/ios/ReactNativeProseEditor.podspec +49 -0
- package/ios/RenderBridge.swift +825 -0
- package/ios/RichTextEditorView.swift +1559 -0
- package/ios/editor_coreFFI/editor_coreFFI.h +1014 -0
- package/ios/editor_coreFFI/module.modulemap +7 -0
- package/ios/editor_coreFFI.h +904 -0
- package/ios/editor_coreFFI.modulemap +7 -0
- package/package.json +66 -0
- package/rust/android/arm64-v8a/libeditor_core.so +0 -0
- package/rust/android/armeabi-v7a/libeditor_core.so +0 -0
- package/rust/android/x86_64/libeditor_core.so +0 -0
- package/rust/bindings/kotlin/uniffi/editor_core/editor_core.kt +2014 -0
- package/src/EditorTheme.ts +130 -0
- package/src/EditorToolbar.tsx +620 -0
- package/src/NativeEditorBridge.ts +607 -0
- package/src/NativeRichTextEditor.tsx +951 -0
- package/src/addons.ts +158 -0
- package/src/index.ts +63 -0
- package/src/schemas.ts +153 -0
- package/src/useNativeEditor.ts +173 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction, and
|
|
10
|
+
distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright
|
|
13
|
+
owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities
|
|
16
|
+
that control, are controlled by, or are under common control with that entity.
|
|
17
|
+
For the purposes of this definition, "control" means (i) the power, direct or
|
|
18
|
+
indirect, to cause the direction or management of such entity, whether by
|
|
19
|
+
contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
20
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
21
|
+
|
|
22
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
|
23
|
+
permissions granted by this License.
|
|
24
|
+
|
|
25
|
+
"Source" form shall mean the preferred form for making modifications, including
|
|
26
|
+
but not limited to software source code, documentation source, and
|
|
27
|
+
configuration files.
|
|
28
|
+
|
|
29
|
+
"Object" form shall mean any form resulting from mechanical transformation or
|
|
30
|
+
translation of a Source form, including but not limited to compiled object
|
|
31
|
+
code, generated documentation, and conversions to other media types.
|
|
32
|
+
|
|
33
|
+
"Work" shall mean the work of authorship, whether in Source or Object form,
|
|
34
|
+
made available under the License, as indicated by a copyright notice that is
|
|
35
|
+
included in or attached to the work (an example is provided in the Appendix
|
|
36
|
+
below).
|
|
37
|
+
|
|
38
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that
|
|
39
|
+
is based on (or derived from) the Work and for which the editorial revisions,
|
|
40
|
+
annotations, elaborations, or other modifications represent, as a whole, an
|
|
41
|
+
original work of authorship. For the purposes of this License, Derivative Works
|
|
42
|
+
shall not include works that remain separable from, or merely link (or bind by
|
|
43
|
+
name) to the interfaces of, the Work and Derivative Works thereof.
|
|
44
|
+
|
|
45
|
+
"Contribution" shall mean any work of authorship, including the original
|
|
46
|
+
version of the Work and any modifications or additions to that Work or
|
|
47
|
+
Derivative Works thereof, that is intentionally submitted to Licensor for
|
|
48
|
+
inclusion in the Work by the copyright owner or by an individual or Legal
|
|
49
|
+
Entity authorized to submit on behalf of the copyright owner. For the purposes
|
|
50
|
+
of this definition, "submitted" means any form of electronic, verbal, or
|
|
51
|
+
written communication sent to the Licensor or its representatives, including
|
|
52
|
+
but not limited to communication on electronic mailing lists, source code
|
|
53
|
+
control systems, and issue tracking systems that are managed by, or on behalf
|
|
54
|
+
of, the Licensor for the purpose of discussing and improving the Work, but
|
|
55
|
+
excluding communication that is conspicuously marked or otherwise designated in
|
|
56
|
+
writing by the copyright owner as "Not a Contribution."
|
|
57
|
+
|
|
58
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
|
|
59
|
+
of whom a Contribution has been received by Licensor and subsequently
|
|
60
|
+
incorporated within the Work.
|
|
61
|
+
|
|
62
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this
|
|
63
|
+
License, each Contributor hereby grants to You a perpetual, worldwide,
|
|
64
|
+
non-exclusive, no-charge, royalty-free, irrevocable copyright license to
|
|
65
|
+
reproduce, prepare Derivative Works of, publicly display, publicly perform,
|
|
66
|
+
sublicense, and distribute the Work and such Derivative Works in Source or
|
|
67
|
+
Object form.
|
|
68
|
+
|
|
69
|
+
3. Grant of Patent License. Subject to the terms and conditions of this
|
|
70
|
+
License, each Contributor hereby grants to You a perpetual, worldwide,
|
|
71
|
+
non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this
|
|
72
|
+
section) patent license to make, have made, use, offer to sell, sell, import,
|
|
73
|
+
and otherwise transfer the Work, where such license applies only to those
|
|
74
|
+
patent claims licensable by such Contributor that are necessarily infringed by
|
|
75
|
+
their Contribution(s) alone or by combination of their Contribution(s) with the
|
|
76
|
+
Work to which such Contribution(s) was submitted. If You institute patent
|
|
77
|
+
litigation against any entity (including a cross-claim or counterclaim in a
|
|
78
|
+
lawsuit) alleging that the Work or a Contribution incorporated within the Work
|
|
79
|
+
constitutes direct or contributory patent infringement, then any patent
|
|
80
|
+
licenses granted to You under this License for that Work shall terminate as of
|
|
81
|
+
the date such litigation is filed.
|
|
82
|
+
|
|
83
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or
|
|
84
|
+
Derivative Works thereof in any medium, with or without modifications, and in
|
|
85
|
+
Source or Object form, provided that You meet the following conditions:
|
|
86
|
+
|
|
87
|
+
(a) You must give any other recipients of the Work or Derivative Works a copy
|
|
88
|
+
of this License; and
|
|
89
|
+
|
|
90
|
+
(b) You must cause any modified files to carry prominent notices stating that
|
|
91
|
+
You changed the files; and
|
|
92
|
+
|
|
93
|
+
(c) You must retain, in the Source form of any Derivative Works that You
|
|
94
|
+
distribute, all copyright, patent, trademark, and attribution notices from the
|
|
95
|
+
Source form of the Work, excluding those notices that do not pertain to any
|
|
96
|
+
part of the Derivative Works; and
|
|
97
|
+
|
|
98
|
+
(d) If the Work includes a "NOTICE" text file as part of its distribution, then
|
|
99
|
+
any Derivative Works that You distribute must include a readable copy of the
|
|
100
|
+
attribution notices contained within such NOTICE file, excluding those notices
|
|
101
|
+
that do not pertain to any part of the Derivative Works, in at least one of the
|
|
102
|
+
following places: within a NOTICE text file distributed as part of the
|
|
103
|
+
Derivative Works; within the Source form or documentation, if provided along
|
|
104
|
+
with the Derivative Works; or, within a display generated by the Derivative
|
|
105
|
+
Works, if and wherever such third-party notices normally appear. The contents
|
|
106
|
+
of the NOTICE file are for informational purposes only and do not modify the
|
|
107
|
+
License. You may add Your own attribution notices within Derivative Works that
|
|
108
|
+
You distribute, alongside or as an addendum to the NOTICE text from the Work,
|
|
109
|
+
provided that such additional attribution notices cannot be construed as
|
|
110
|
+
modifying the License.
|
|
111
|
+
|
|
112
|
+
You may add Your own copyright statement to Your modifications and may provide
|
|
113
|
+
additional or different license terms and conditions for use, reproduction, or
|
|
114
|
+
distribution of Your modifications, or for any such Derivative Works as a
|
|
115
|
+
whole, provided Your use, reproduction, and distribution of the Work otherwise
|
|
116
|
+
complies with the conditions stated in this License.
|
|
117
|
+
|
|
118
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any
|
|
119
|
+
Contribution intentionally submitted for inclusion in the Work by You to the
|
|
120
|
+
Licensor shall be under the terms and conditions of this License, without any
|
|
121
|
+
additional terms or conditions. Notwithstanding the above, nothing herein shall
|
|
122
|
+
supersede or modify the terms of any separate license agreement you may have
|
|
123
|
+
executed with Licensor regarding such Contributions.
|
|
124
|
+
|
|
125
|
+
6. Trademarks. This License does not grant permission to use the trade names,
|
|
126
|
+
trademarks, service marks, or product names of the Licensor, except as required
|
|
127
|
+
for reasonable and customary use in describing the origin of the Work and
|
|
128
|
+
reproducing the content of the NOTICE file.
|
|
129
|
+
|
|
130
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
|
|
131
|
+
writing, Licensor provides the Work (and each Contributor provides its
|
|
132
|
+
Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
133
|
+
KIND, either express or implied, including, without limitation, any warranties
|
|
134
|
+
or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
135
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
136
|
+
appropriateness of using or redistributing the Work and assume any risks
|
|
137
|
+
associated with Your exercise of permissions under this License.
|
|
138
|
+
|
|
139
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in
|
|
140
|
+
tort (including negligence), contract, or otherwise, unless required by
|
|
141
|
+
applicable law (such as deliberate and grossly negligent acts) or agreed to in
|
|
142
|
+
writing, shall any Contributor be liable to You for damages, including any
|
|
143
|
+
direct, indirect, special, incidental, or consequential damages of any
|
|
144
|
+
character arising as a result of this License or out of the use or inability to
|
|
145
|
+
use the Work (including but not limited to damages for loss of goodwill, work
|
|
146
|
+
stoppage, computer failure or malfunction, or any and all other commercial
|
|
147
|
+
damages or losses), even if such Contributor has been advised of the
|
|
148
|
+
possibility of such damages.
|
|
149
|
+
|
|
150
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or
|
|
151
|
+
Derivative Works thereof, You may choose to offer, and charge a fee for,
|
|
152
|
+
acceptance of support, warranty, indemnity, or other liability obligations
|
|
153
|
+
and/or rights consistent with this License. However, in accepting such
|
|
154
|
+
obligations, You may act only on Your own behalf and on Your sole
|
|
155
|
+
responsibility, not on behalf of any other Contributor, and only if You agree
|
|
156
|
+
to indemnify, defend, and hold each Contributor harmless for any liability
|
|
157
|
+
incurred by, or claims asserted against, such Contributor by reason of your
|
|
158
|
+
accepting any such warranty or additional liability.
|
|
159
|
+
|
|
160
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# React Native Prose Editor
|
|
2
|
+
|
|
3
|
+
`@apollohg/react-native-prose-editor` is a native rich text editor for React Native with a Rust document core, native iOS and Android rendering, configurable schemas, and a React-facing toolbar and theme API.
|
|
4
|
+
|
|
5
|
+
This project is currently in alpha and the API, behavior, and packaging may still change.
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<img src="./docs/images/example-1.PNG" alt="Example editor screen" width="45%" />
|
|
9
|
+
<img src="./docs/images/example-2.PNG" alt="Example editor theme screen" width="45%" />
|
|
10
|
+
</p>
|
|
11
|
+
|
|
12
|
+
This repository contains three main pieces:
|
|
13
|
+
|
|
14
|
+
- the editor package itself under [`src`](./src), [`ios`](./ios), [`android`](./android), and [`rust`](./rust)
|
|
15
|
+
- an Expo SDK 54 development app under [`example`](./example)
|
|
16
|
+
- a runnable iOS XCTest harness for native regression coverage
|
|
17
|
+
|
|
18
|
+
## Features
|
|
19
|
+
|
|
20
|
+
The editor already supports:
|
|
21
|
+
|
|
22
|
+
- HTML and ProseMirror JSON content input/output
|
|
23
|
+
- configurable schemas
|
|
24
|
+
- marks such as bold, italic, underline, and strike
|
|
25
|
+
- bullet and ordered lists with indent/outdent behavior
|
|
26
|
+
- hard breaks and horizontal rules
|
|
27
|
+
- native @-mentions with themed suggestion UI in the toolbar area
|
|
28
|
+
- native theming for text, lists, horizontal rules, mentions, and the toolbar
|
|
29
|
+
- configurable toolbar items, including app-defined actions
|
|
30
|
+
- auto-grow height behavior for parent-managed scroll containers
|
|
31
|
+
- a Rust-backed undo/redo history model
|
|
32
|
+
|
|
33
|
+
## Repository Layout
|
|
34
|
+
|
|
35
|
+
- [`src`](./src): React Native component API, toolbar, schemas, and TypeScript types
|
|
36
|
+
- [`ios`](./ios): iOS native view, toolbar accessory, rendering bridge, and generated Rust bindings
|
|
37
|
+
- [`android`](./android): Android native view, rendering bridge, and Expo module wiring
|
|
38
|
+
- [`Rust Editor Core`](./rust/editor-core): document model, transforms, schema system, selection, history, serialization, and tests
|
|
39
|
+
- [`example`](./example): Expo 54 app for manual QA and development
|
|
40
|
+
- [`docs`](./docs): project documentation
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
This package currently requires Expo Modules. Use it in an Expo development build or in a bare React Native app that has Expo Modules configured.
|
|
45
|
+
|
|
46
|
+
The minimum tested Expo version is SDK 54.
|
|
47
|
+
|
|
48
|
+
Required peer dependencies:
|
|
49
|
+
|
|
50
|
+
- `expo`
|
|
51
|
+
- `expo-modules-core`
|
|
52
|
+
- `react`
|
|
53
|
+
- `react-native`
|
|
54
|
+
- `@expo/vector-icons`
|
|
55
|
+
|
|
56
|
+
Install the package:
|
|
57
|
+
|
|
58
|
+
```sh
|
|
59
|
+
npm install @apollohg/react-native-prose-editor
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
For local package development in this repo:
|
|
63
|
+
|
|
64
|
+
```sh
|
|
65
|
+
npm install
|
|
66
|
+
npm --prefix example install
|
|
67
|
+
npm run example:prebuild
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
For full setup details, including peer dependencies, example app setup, and iOS pods, see the [Installation Guide](./docs/guides/installation.md).
|
|
71
|
+
|
|
72
|
+
## Basic Usage
|
|
73
|
+
|
|
74
|
+
```tsx
|
|
75
|
+
import React, { useRef } from 'react';
|
|
76
|
+
import {
|
|
77
|
+
NativeRichTextEditor,
|
|
78
|
+
type NativeRichTextEditorRef,
|
|
79
|
+
} from '@apollohg/react-native-prose-editor';
|
|
80
|
+
|
|
81
|
+
export function EditorScreen() {
|
|
82
|
+
const editorRef = useRef<NativeRichTextEditorRef>(null);
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
<NativeRichTextEditor
|
|
86
|
+
ref={editorRef}
|
|
87
|
+
initialContent="<p>Hello world</p>"
|
|
88
|
+
placeholder="Start typing..."
|
|
89
|
+
onContentChange={(html) => {
|
|
90
|
+
console.log(html);
|
|
91
|
+
}}
|
|
92
|
+
/>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Customization
|
|
98
|
+
|
|
99
|
+
The main extension points today are:
|
|
100
|
+
|
|
101
|
+
- `schema`: provide a custom schema definition
|
|
102
|
+
- `theme`: style text blocks, lists, horizontal rules, background, and toolbar chrome
|
|
103
|
+
- `toolbarItems`: define the visible toolbar controls and order
|
|
104
|
+
- `onToolbarAction`: handle app-defined toolbar buttons
|
|
105
|
+
- `addons`: configure optional features like @-mentions
|
|
106
|
+
- `heightBehavior`: switch between internal scrolling and auto-grow
|
|
107
|
+
|
|
108
|
+
For setup and customization details, start with the [Documentation Index](./docs/README.md).
|
|
109
|
+
|
|
110
|
+
## Development
|
|
111
|
+
|
|
112
|
+
Common commands:
|
|
113
|
+
|
|
114
|
+
```sh
|
|
115
|
+
npm run typecheck
|
|
116
|
+
npm run example:start
|
|
117
|
+
npm run example:ios
|
|
118
|
+
npm run example:android
|
|
119
|
+
npm run build:rust
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Tests:
|
|
123
|
+
|
|
124
|
+
```sh
|
|
125
|
+
npm test # TypeScript unit tests
|
|
126
|
+
cargo test --manifest-path rust/editor-core/Cargo.toml # Rust core tests
|
|
127
|
+
npm run android:test # Android Robolectric tests
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Documentation
|
|
131
|
+
|
|
132
|
+
- [Documentation Index](./docs/README.md): main documentation index
|
|
133
|
+
- [Installation Guide](./docs/guides/installation.md): installation and local setup
|
|
134
|
+
- [Getting Started](./docs/guides/getting-started.md): first setup and first editor
|
|
135
|
+
- [Toolbar Setup](./docs/guides/toolbar-setup.md): toolbar setup patterns and examples
|
|
136
|
+
- [Mentions Guide](./docs/guides/mentions.md): @-mentions addon setup and configuration
|
|
137
|
+
- [Styling Guide](./docs/guides/styling.md): content, toolbar, and mention styling
|
|
138
|
+
- [NativeRichTextEditor Reference](./docs/reference/native-rich-text-editor.md): component props and ref methods
|
|
139
|
+
- [Design Decisions](./docs/explanations/design-decisions.md): rationale for key API and architecture decisions
|
|
140
|
+
|
|
141
|
+
## Project Status
|
|
142
|
+
|
|
143
|
+
The project is usable and already covers the core editing flows, but the API and documentation are still evolving as the package moves toward wider use.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
plugins {
|
|
2
|
+
id 'com.android.library'
|
|
3
|
+
id 'expo-module-gradle-plugin'
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
group = 'com.apollohg'
|
|
7
|
+
version = '0.1.0'
|
|
8
|
+
|
|
9
|
+
android {
|
|
10
|
+
namespace "com.apollohg.editor"
|
|
11
|
+
testOptions {
|
|
12
|
+
unitTests.includeAndroidResources = true
|
|
13
|
+
}
|
|
14
|
+
defaultConfig {
|
|
15
|
+
versionCode 1
|
|
16
|
+
versionName '0.1.0'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Include prebuilt Rust .so files from the package's rust/android/ directory
|
|
20
|
+
sourceSets {
|
|
21
|
+
main {
|
|
22
|
+
jniLibs.srcDirs = [
|
|
23
|
+
"${project.projectDir}/../rust/android"
|
|
24
|
+
]
|
|
25
|
+
// Include the generated Kotlin UniFFI bindings
|
|
26
|
+
java.srcDirs += [
|
|
27
|
+
"${project.projectDir}/../rust/bindings/kotlin"
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
dependencies {
|
|
34
|
+
implementation "androidx.appcompat:appcompat:1.7.0"
|
|
35
|
+
implementation "net.java.dev.jna:jna:5.14.0@aar"
|
|
36
|
+
|
|
37
|
+
testImplementation "junit:junit:4.13.2"
|
|
38
|
+
testImplementation "org.robolectric:robolectric:4.14.1"
|
|
39
|
+
}
|