@openeditor/react-native-prose-editor 0.0.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.
Files changed (91) hide show
  1. package/LICENSE +160 -0
  2. package/README.md +180 -0
  3. package/android/build.gradle +69 -0
  4. package/android/consumer-rules.pro +18 -0
  5. package/android/src/androidTest/AndroidManifest.xml +8 -0
  6. package/android/src/androidTest/java/com/apollohg/editor/MeasureHeightInstrumentedTest.kt +53 -0
  7. package/android/src/androidTest/java/com/apollohg/editor/NativeDeviceCollaborationInitialSyncTest.kt +241 -0
  8. package/android/src/androidTest/java/com/apollohg/editor/NativeDeviceImeRegressionTest.kt +338 -0
  9. package/android/src/androidTest/java/com/apollohg/editor/NativeDeviceOutsideTapTest.kt +789 -0
  10. package/android/src/androidTest/java/com/apollohg/editor/NativeDevicePerformanceTest.kt +350 -0
  11. package/android/src/androidTest/java/com/apollohg/editor/NativeEditorOutsideTapActivity.kt +5 -0
  12. package/android/src/main/assets/editor-icons/MaterialIcons.json +2236 -0
  13. package/android/src/main/assets/editor-icons/MaterialIcons.ttf +0 -0
  14. package/android/src/main/java/com/apollohg/editor/CaretGeometry.kt +50 -0
  15. package/android/src/main/java/com/apollohg/editor/EditorAddons.kt +135 -0
  16. package/android/src/main/java/com/apollohg/editor/EditorEditText.kt +4527 -0
  17. package/android/src/main/java/com/apollohg/editor/EditorHeightBehavior.kt +14 -0
  18. package/android/src/main/java/com/apollohg/editor/EditorInputConnection.kt +999 -0
  19. package/android/src/main/java/com/apollohg/editor/EditorTheme.kt +474 -0
  20. package/android/src/main/java/com/apollohg/editor/ImageResizeOverlayView.kt +199 -0
  21. package/android/src/main/java/com/apollohg/editor/NativeEditorExpoView.kt +3137 -0
  22. package/android/src/main/java/com/apollohg/editor/NativeEditorModule.kt +561 -0
  23. package/android/src/main/java/com/apollohg/editor/NativeProseViewerExpoView.kt +315 -0
  24. package/android/src/main/java/com/apollohg/editor/NativeToolbar.kt +1413 -0
  25. package/android/src/main/java/com/apollohg/editor/PositionBridge.kt +133 -0
  26. package/android/src/main/java/com/apollohg/editor/RemoteSelectionOverlayView.kt +315 -0
  27. package/android/src/main/java/com/apollohg/editor/RenderBridge.kt +2172 -0
  28. package/android/src/main/java/com/apollohg/editor/RichTextEditorView.kt +399 -0
  29. package/android/src/sharedTest/java/com/apollohg/editor/NativePerformanceSupport.kt +482 -0
  30. package/android/src/test/java/com/apollohg/editor/CaretGeometryTest.kt +137 -0
  31. package/android/src/test/java/com/apollohg/editor/EditorEditTextHardwareKeyTest.kt +321 -0
  32. package/android/src/test/java/com/apollohg/editor/EditorInputConnectionTest.kt +4202 -0
  33. package/android/src/test/java/com/apollohg/editor/NativeEditorExpoViewTest.kt +2581 -0
  34. package/android/src/test/java/com/apollohg/editor/NativeEditorModuleTest.kt +27 -0
  35. package/android/src/test/java/com/apollohg/editor/NativePerformanceTest.kt +197 -0
  36. package/android/src/test/java/com/apollohg/editor/NativeProseViewerExpoViewTest.kt +84 -0
  37. package/android/src/test/java/com/apollohg/editor/NativeToolbarTest.kt +544 -0
  38. package/android/src/test/java/com/apollohg/editor/PositionBridgeTest.kt +461 -0
  39. package/android/src/test/java/com/apollohg/editor/RenderBridgeTest.kt +2054 -0
  40. package/android/src/test/java/com/apollohg/editor/RichTextEditorViewTest.kt +1367 -0
  41. package/app.plugin.js +62 -0
  42. package/dist/EditorTheme.d.ts +113 -0
  43. package/dist/EditorTheme.js +29 -0
  44. package/dist/EditorToolbar.d.ts +191 -0
  45. package/dist/EditorToolbar.js +1095 -0
  46. package/dist/NativeEditorBridge.d.ts +325 -0
  47. package/dist/NativeEditorBridge.js +933 -0
  48. package/dist/NativeProseViewer.d.ts +53 -0
  49. package/dist/NativeProseViewer.js +480 -0
  50. package/dist/NativeRichTextEditor.d.ts +183 -0
  51. package/dist/NativeRichTextEditor.js +2574 -0
  52. package/dist/YjsCollaboration.d.ts +90 -0
  53. package/dist/YjsCollaboration.js +743 -0
  54. package/dist/addons.d.ts +100 -0
  55. package/dist/addons.js +82 -0
  56. package/dist/heightCache.d.ts +6 -0
  57. package/dist/heightCache.js +45 -0
  58. package/dist/index.d.ts +10 -0
  59. package/dist/index.js +30 -0
  60. package/dist/schemas.d.ts +37 -0
  61. package/dist/schemas.js +263 -0
  62. package/dist/useNativeEditor.d.ts +42 -0
  63. package/dist/useNativeEditor.js +124 -0
  64. package/expo-module.config.json +9 -0
  65. package/ios/EditorAddons.swift +327 -0
  66. package/ios/EditorCore.xcframework/Info.plist +44 -0
  67. package/ios/EditorCore.xcframework/ios-arm64/libeditor_core.a +0 -0
  68. package/ios/EditorCore.xcframework/ios-arm64_x86_64-simulator/libeditor_core.a +0 -0
  69. package/ios/EditorLayoutManager.swift +774 -0
  70. package/ios/EditorTheme.swift +515 -0
  71. package/ios/Generated_editor_core.swift +1513 -0
  72. package/ios/NativeEditorExpoView.swift +3593 -0
  73. package/ios/NativeEditorModule.swift +624 -0
  74. package/ios/NativeProseViewerExpoView.swift +276 -0
  75. package/ios/PositionBridge.swift +558 -0
  76. package/ios/ReactNativeProseEditor.podspec +49 -0
  77. package/ios/RenderBridge.swift +1708 -0
  78. package/ios/RichTextEditorView.swift +6150 -0
  79. package/ios/Tests/NativePerformanceTests.swift +687 -0
  80. package/ios/Tests/PositionBridgeTests.swift +706 -0
  81. package/ios/Tests/RenderBridgeTests.swift +2236 -0
  82. package/ios/Tests/RichTextEditorViewTests.swift +6548 -0
  83. package/ios/editor_coreFFI/editor_coreFFI.h +1289 -0
  84. package/ios/editor_coreFFI/module.modulemap +7 -0
  85. package/ios/editor_coreFFI.h +904 -0
  86. package/ios/editor_coreFFI.modulemap +7 -0
  87. package/package.json +74 -0
  88. package/rust/android/arm64-v8a/libeditor_core.so +0 -0
  89. package/rust/android/armeabi-v7a/libeditor_core.so +0 -0
  90. package/rust/android/x86_64/libeditor_core.so +0 -0
  91. package/rust/bindings/kotlin/uniffi/editor_core/editor_core.kt +2563 -0
@@ -0,0 +1,561 @@
1
+ package com.openeditor.editor
2
+
3
+ import expo.modules.kotlin.modules.Module
4
+ import expo.modules.kotlin.modules.ModuleDefinition
5
+ import uniffi.editor_core.*
6
+
7
+ internal fun nativeULong(value: Int): ULong? =
8
+ if (value >= 0) value.toULong() else null
9
+
10
+ internal fun nativeUInt(value: Int): UInt? =
11
+ if (value >= 0) value.toUInt() else null
12
+
13
+ internal fun nativeArgumentError(field: String): String =
14
+ "{\"error\":\"invalid $field\"}"
15
+
16
+ class NativeEditorModule : Module() {
17
+ override fun definition() = ModuleDefinition {
18
+ Name("NativeEditor")
19
+
20
+ Function("editorCreate") { configJson: String ->
21
+ editorCreate(configJson).toLong().also { id ->
22
+ NativeEditorViewRegistry.markEditorCreated(id)
23
+ }
24
+ }
25
+ Function("editorDestroy") { id: Int ->
26
+ val editorId = nativeULong(id) ?: return@Function
27
+ NativeEditorViewRegistry.invalidateDestroyedEditor(id.toLong())
28
+ editorDestroy(editorId)
29
+ }
30
+ Function("editorPrepareForCommand") { id: Int ->
31
+ nativeULong(id) ?: return@Function nativeArgumentError("editor id")
32
+ NativeEditorViewRegistry.prepareForCommandJSON(id.toLong())
33
+ }
34
+ Function("collaborationSessionCreate") { configJson: String ->
35
+ collaborationSessionCreate(configJson).toLong()
36
+ }
37
+ Function("collaborationSessionDestroy") { id: Int ->
38
+ val sessionId = nativeULong(id) ?: return@Function
39
+ collaborationSessionDestroy(sessionId)
40
+ }
41
+ Function("collaborationSessionGetDocumentJson") { id: Int ->
42
+ val sessionId = nativeULong(id) ?: return@Function "{}"
43
+ collaborationSessionGetDocumentJson(sessionId)
44
+ }
45
+ Function("collaborationSessionGetEncodedState") { id: Int ->
46
+ val sessionId = nativeULong(id) ?: return@Function "[]"
47
+ collaborationSessionGetEncodedState(sessionId)
48
+ }
49
+ Function("collaborationSessionGetPeersJson") { id: Int ->
50
+ val sessionId = nativeULong(id) ?: return@Function "[]"
51
+ collaborationSessionGetPeersJson(sessionId)
52
+ }
53
+ Function("collaborationSessionStart") { id: Int ->
54
+ val sessionId = nativeULong(id) ?: return@Function nativeArgumentError("session id")
55
+ collaborationSessionStart(sessionId)
56
+ }
57
+ Function("collaborationSessionApplyLocalDocumentJson") { id: Int, json: String ->
58
+ val sessionId = nativeULong(id) ?: return@Function nativeArgumentError("session id")
59
+ collaborationSessionApplyLocalDocumentJson(sessionId, json)
60
+ }
61
+ Function("collaborationSessionApplyEncodedState") { id: Int, encodedStateJson: String ->
62
+ val sessionId = nativeULong(id) ?: return@Function nativeArgumentError("session id")
63
+ collaborationSessionApplyEncodedState(sessionId, encodedStateJson)
64
+ }
65
+ Function("collaborationSessionReplaceEncodedState") { id: Int, encodedStateJson: String ->
66
+ val sessionId = nativeULong(id) ?: return@Function nativeArgumentError("session id")
67
+ collaborationSessionReplaceEncodedState(sessionId, encodedStateJson)
68
+ }
69
+ Function("collaborationSessionHandleMessage") { id: Int, messageJson: String ->
70
+ val sessionId = nativeULong(id) ?: return@Function nativeArgumentError("session id")
71
+ collaborationSessionHandleMessage(sessionId, messageJson)
72
+ }
73
+ Function("collaborationSessionSetLocalAwareness") { id: Int, awarenessJson: String ->
74
+ val sessionId = nativeULong(id) ?: return@Function nativeArgumentError("session id")
75
+ collaborationSessionSetLocalAwareness(sessionId, awarenessJson)
76
+ }
77
+ Function("collaborationSessionClearLocalAwareness") { id: Int ->
78
+ val sessionId = nativeULong(id) ?: return@Function nativeArgumentError("session id")
79
+ collaborationSessionClearLocalAwareness(sessionId)
80
+ }
81
+
82
+ Function("editorSetHtml") { id: Int, html: String ->
83
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
84
+ editorSetHtml(editorId, html)
85
+ }
86
+ Function("editorGetHtml") { id: Int ->
87
+ val editorId = nativeULong(id) ?: return@Function ""
88
+ editorGetHtml(editorId)
89
+ }
90
+ Function("editorSetJson") { id: Int, json: String ->
91
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
92
+ editorSetJson(editorId, json)
93
+ }
94
+ Function("editorGetJson") { id: Int ->
95
+ val editorId = nativeULong(id) ?: return@Function "{}"
96
+ editorGetJson(editorId)
97
+ }
98
+ Function("editorGetContentSnapshot") { id: Int ->
99
+ val editorId = nativeULong(id) ?: return@Function "{\"html\":\"\",\"json\":{}}"
100
+ editorGetContentSnapshot(editorId)
101
+ }
102
+
103
+ Function("editorInsertText") { id: Int, pos: Int, text: String ->
104
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
105
+ val position = nativeUInt(pos) ?: return@Function nativeArgumentError("position")
106
+ editorInsertText(editorId, position, text)
107
+ }
108
+ Function("editorReplaceSelectionText") { id: Int, text: String ->
109
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
110
+ editorReplaceSelectionText(editorId, text)
111
+ }
112
+ Function("editorDeleteRange") { id: Int, from: Int, to: Int ->
113
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
114
+ val fromPosition = nativeUInt(from) ?: return@Function nativeArgumentError("position")
115
+ val toPosition = nativeUInt(to) ?: return@Function nativeArgumentError("position")
116
+ editorDeleteRange(editorId, fromPosition, toPosition)
117
+ }
118
+ Function("editorSplitBlock") { id: Int, pos: Int ->
119
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
120
+ val position = nativeUInt(pos) ?: return@Function nativeArgumentError("position")
121
+ editorSplitBlock(editorId, position)
122
+ }
123
+ Function("editorInsertContentHtml") { id: Int, html: String ->
124
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
125
+ editorInsertContentHtml(editorId, html)
126
+ }
127
+ Function("editorReplaceHtml") { id: Int, html: String ->
128
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
129
+ editorReplaceHtml(editorId, html)
130
+ }
131
+ Function("editorReplaceJson") { id: Int, json: String ->
132
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
133
+ editorReplaceJson(editorId, json)
134
+ }
135
+ Function("editorInsertContentJson") { id: Int, json: String ->
136
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
137
+ editorInsertContentJson(editorId, json)
138
+ }
139
+ Function(
140
+ "editorInsertContentJsonAtSelectionScalar"
141
+ ) { id: Int, scalarAnchor: Int, scalarHead: Int, json: String ->
142
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
143
+ val anchor = nativeUInt(scalarAnchor) ?: return@Function nativeArgumentError("position")
144
+ val head = nativeUInt(scalarHead) ?: return@Function nativeArgumentError("position")
145
+ editorInsertContentJsonAtSelectionScalar(
146
+ editorId,
147
+ anchor,
148
+ head,
149
+ json
150
+ )
151
+ }
152
+ Function("editorWrapInList") { id: Int, listType: String ->
153
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
154
+ editorWrapInList(editorId, listType)
155
+ }
156
+ Function("editorUnwrapFromList") { id: Int ->
157
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
158
+ editorUnwrapFromList(editorId)
159
+ }
160
+ Function("editorIndentListItem") { id: Int ->
161
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
162
+ editorIndentListItem(editorId)
163
+ }
164
+ Function("editorOutdentListItem") { id: Int ->
165
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
166
+ editorOutdentListItem(editorId)
167
+ }
168
+ Function("editorInsertNode") { id: Int, nodeType: String ->
169
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
170
+ editorInsertNode(editorId, nodeType)
171
+ }
172
+
173
+ Function("editorInsertTextScalar") { id: Int, scalarPos: Int, text: String ->
174
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
175
+ val position = nativeUInt(scalarPos) ?: return@Function nativeArgumentError("position")
176
+ editorInsertTextScalar(editorId, position, text)
177
+ }
178
+ Function("editorDeleteScalarRange") { id: Int, scalarFrom: Int, scalarTo: Int ->
179
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
180
+ val fromPosition = nativeUInt(scalarFrom) ?: return@Function nativeArgumentError("position")
181
+ val toPosition = nativeUInt(scalarTo) ?: return@Function nativeArgumentError("position")
182
+ editorDeleteScalarRange(editorId, fromPosition, toPosition)
183
+ }
184
+ Function("editorReplaceTextScalar") { id: Int, scalarFrom: Int, scalarTo: Int, text: String ->
185
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
186
+ val fromPosition = nativeUInt(scalarFrom) ?: return@Function nativeArgumentError("position")
187
+ val toPosition = nativeUInt(scalarTo) ?: return@Function nativeArgumentError("position")
188
+ editorReplaceTextScalar(editorId, fromPosition, toPosition, text)
189
+ }
190
+ Function("editorSplitBlockScalar") { id: Int, scalarPos: Int ->
191
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
192
+ val position = nativeUInt(scalarPos) ?: return@Function nativeArgumentError("position")
193
+ editorSplitBlockScalar(editorId, position)
194
+ }
195
+ Function("editorDeleteAndSplitScalar") { id: Int, scalarFrom: Int, scalarTo: Int ->
196
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
197
+ val fromPosition = nativeUInt(scalarFrom) ?: return@Function nativeArgumentError("position")
198
+ val toPosition = nativeUInt(scalarTo) ?: return@Function nativeArgumentError("position")
199
+ editorDeleteAndSplitScalar(editorId, fromPosition, toPosition)
200
+ }
201
+ Function(
202
+ "editorToggleMarkAtSelectionScalar"
203
+ ) { id: Int, scalarAnchor: Int, scalarHead: Int, markName: String ->
204
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
205
+ val anchor = nativeUInt(scalarAnchor) ?: return@Function nativeArgumentError("position")
206
+ val head = nativeUInt(scalarHead) ?: return@Function nativeArgumentError("position")
207
+ editorToggleMarkAtSelectionScalar(
208
+ editorId,
209
+ anchor,
210
+ head,
211
+ markName
212
+ )
213
+ }
214
+ Function(
215
+ "editorSetMarkAtSelectionScalar"
216
+ ) { id: Int, scalarAnchor: Int, scalarHead: Int, markName: String, attrsJson: String ->
217
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
218
+ val anchor = nativeUInt(scalarAnchor) ?: return@Function nativeArgumentError("position")
219
+ val head = nativeUInt(scalarHead) ?: return@Function nativeArgumentError("position")
220
+ editorSetMarkAtSelectionScalar(
221
+ editorId,
222
+ anchor,
223
+ head,
224
+ markName,
225
+ attrsJson
226
+ )
227
+ }
228
+ Function(
229
+ "editorUnsetMarkAtSelectionScalar"
230
+ ) { id: Int, scalarAnchor: Int, scalarHead: Int, markName: String ->
231
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
232
+ val anchor = nativeUInt(scalarAnchor) ?: return@Function nativeArgumentError("position")
233
+ val head = nativeUInt(scalarHead) ?: return@Function nativeArgumentError("position")
234
+ editorUnsetMarkAtSelectionScalar(
235
+ editorId,
236
+ anchor,
237
+ head,
238
+ markName
239
+ )
240
+ }
241
+ Function(
242
+ "editorToggleBlockquoteAtSelectionScalar"
243
+ ) { id: Int, scalarAnchor: Int, scalarHead: Int ->
244
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
245
+ val anchor = nativeUInt(scalarAnchor) ?: return@Function nativeArgumentError("position")
246
+ val head = nativeUInt(scalarHead) ?: return@Function nativeArgumentError("position")
247
+ editorToggleBlockquoteAtSelectionScalar(
248
+ editorId,
249
+ anchor,
250
+ head
251
+ )
252
+ }
253
+ Function(
254
+ "editorToggleHeadingAtSelectionScalar"
255
+ ) { id: Int, scalarAnchor: Int, scalarHead: Int, level: Int ->
256
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
257
+ val anchor = nativeUInt(scalarAnchor) ?: return@Function nativeArgumentError("position")
258
+ val head = nativeUInt(scalarHead) ?: return@Function nativeArgumentError("position")
259
+ if (level !in 1..6) {
260
+ return@Function "{\"error\":\"invalid heading level\"}"
261
+ }
262
+ editorToggleHeadingAtSelectionScalar(
263
+ editorId,
264
+ anchor,
265
+ head,
266
+ level.toUByte()
267
+ )
268
+ }
269
+ Function(
270
+ "editorWrapInListAtSelectionScalar"
271
+ ) { id: Int, scalarAnchor: Int, scalarHead: Int, listType: String ->
272
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
273
+ val anchor = nativeUInt(scalarAnchor) ?: return@Function nativeArgumentError("position")
274
+ val head = nativeUInt(scalarHead) ?: return@Function nativeArgumentError("position")
275
+ editorWrapInListAtSelectionScalar(
276
+ editorId,
277
+ anchor,
278
+ head,
279
+ listType
280
+ )
281
+ }
282
+ Function(
283
+ "editorUnwrapFromListAtSelectionScalar"
284
+ ) { id: Int, scalarAnchor: Int, scalarHead: Int ->
285
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
286
+ val anchor = nativeUInt(scalarAnchor) ?: return@Function nativeArgumentError("position")
287
+ val head = nativeUInt(scalarHead) ?: return@Function nativeArgumentError("position")
288
+ editorUnwrapFromListAtSelectionScalar(
289
+ editorId,
290
+ anchor,
291
+ head
292
+ )
293
+ }
294
+ Function(
295
+ "editorIndentListItemAtSelectionScalar"
296
+ ) { id: Int, scalarAnchor: Int, scalarHead: Int ->
297
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
298
+ val anchor = nativeUInt(scalarAnchor) ?: return@Function nativeArgumentError("position")
299
+ val head = nativeUInt(scalarHead) ?: return@Function nativeArgumentError("position")
300
+ editorIndentListItemAtSelectionScalar(
301
+ editorId,
302
+ anchor,
303
+ head
304
+ )
305
+ }
306
+ Function(
307
+ "editorOutdentListItemAtSelectionScalar"
308
+ ) { id: Int, scalarAnchor: Int, scalarHead: Int ->
309
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
310
+ val anchor = nativeUInt(scalarAnchor) ?: return@Function nativeArgumentError("position")
311
+ val head = nativeUInt(scalarHead) ?: return@Function nativeArgumentError("position")
312
+ editorOutdentListItemAtSelectionScalar(
313
+ editorId,
314
+ anchor,
315
+ head
316
+ )
317
+ }
318
+ Function(
319
+ "editorInsertNodeAtSelectionScalar"
320
+ ) { id: Int, scalarAnchor: Int, scalarHead: Int, nodeType: String ->
321
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
322
+ val anchor = nativeUInt(scalarAnchor) ?: return@Function nativeArgumentError("position")
323
+ val head = nativeUInt(scalarHead) ?: return@Function nativeArgumentError("position")
324
+ editorInsertNodeAtSelectionScalar(
325
+ editorId,
326
+ anchor,
327
+ head,
328
+ nodeType
329
+ )
330
+ }
331
+
332
+ Function("editorToggleMark") { id: Int, markName: String ->
333
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
334
+ editorToggleMark(editorId, markName)
335
+ }
336
+ Function("editorSetMark") { id: Int, markName: String, attrsJson: String ->
337
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
338
+ editorSetMark(editorId, markName, attrsJson)
339
+ }
340
+ Function("editorUnsetMark") { id: Int, markName: String ->
341
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
342
+ editorUnsetMark(editorId, markName)
343
+ }
344
+ Function("editorToggleBlockquote") { id: Int ->
345
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
346
+ editorToggleBlockquote(editorId)
347
+ }
348
+ Function("editorToggleHeading") { id: Int, level: Int ->
349
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
350
+ if (level !in 1..6) {
351
+ return@Function "{\"error\":\"invalid heading level\"}"
352
+ }
353
+ editorToggleHeading(editorId, level.toUByte())
354
+ }
355
+
356
+ Function("editorSetSelection") { id: Int, anchor: Int, head: Int ->
357
+ val editorId = nativeULong(id) ?: return@Function
358
+ val anchorPosition = nativeUInt(anchor) ?: return@Function
359
+ val headPosition = nativeUInt(head) ?: return@Function
360
+ editorSetSelection(editorId, anchorPosition, headPosition)
361
+ }
362
+ Function("editorSetSelectionScalar") { id: Int, scalarAnchor: Int, scalarHead: Int ->
363
+ val editorId = nativeULong(id) ?: return@Function
364
+ val anchor = nativeUInt(scalarAnchor) ?: return@Function
365
+ val head = nativeUInt(scalarHead) ?: return@Function
366
+ editorSetSelectionScalar(editorId, anchor, head)
367
+ }
368
+ Function("editorGetSelection") { id: Int ->
369
+ val editorId = nativeULong(id) ?: return@Function "{\"type\":\"text\",\"anchor\":0,\"head\":0}"
370
+ editorGetSelection(editorId)
371
+ }
372
+ Function("editorGetSelectionState") { id: Int ->
373
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
374
+ editorGetSelectionState(editorId)
375
+ }
376
+ Function("editorDocToScalar") { id: Int, docPos: Int ->
377
+ val editorId = nativeULong(id) ?: return@Function 0
378
+ val position = nativeUInt(docPos) ?: return@Function 0
379
+ editorDocToScalar(editorId, position).toInt()
380
+ }
381
+ Function("editorScalarToDoc") { id: Int, scalar: Int ->
382
+ val editorId = nativeULong(id) ?: return@Function 0
383
+ val position = nativeUInt(scalar) ?: return@Function 0
384
+ editorScalarToDoc(editorId, position).toInt()
385
+ }
386
+
387
+ Function("editorGetCurrentState") { id: Int ->
388
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
389
+ editorGetCurrentState(editorId)
390
+ }
391
+
392
+ Function("editorUndo") { id: Int ->
393
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
394
+ editorUndo(editorId)
395
+ }
396
+ Function("editorRedo") { id: Int ->
397
+ val editorId = nativeULong(id) ?: return@Function nativeArgumentError("editor id")
398
+ editorRedo(editorId)
399
+ }
400
+ Function("editorCanUndo") { id: Int ->
401
+ val editorId = nativeULong(id) ?: return@Function false
402
+ editorCanUndo(editorId)
403
+ }
404
+ Function("editorCanRedo") { id: Int ->
405
+ val editorId = nativeULong(id) ?: return@Function false
406
+ editorCanRedo(editorId)
407
+ }
408
+ Function("renderDocumentJson") { configJson: String, json: String ->
409
+ val editorId = editorCreate(configJson)
410
+ try {
411
+ editorSetJson(editorId, json)
412
+ } finally {
413
+ editorDestroy(editorId)
414
+ }
415
+ }
416
+ Function("measureContentHeight") { renderJson: String, themeJson: String?, width: Double ->
417
+ val density = appContext.reactContext?.resources?.displayMetrics?.density ?: 1f
418
+ val height = RenderBridge.measureHeight(
419
+ json = renderJson,
420
+ themeJson = themeJson,
421
+ width = width.toFloat(),
422
+ density = density
423
+ )
424
+ height.toDouble()
425
+ }
426
+ Function("renderDocumentHtml") { configJson: String, html: String ->
427
+ val editorId = editorCreate(configJson)
428
+ try {
429
+ editorSetHtml(editorId, html)
430
+ } finally {
431
+ editorDestroy(editorId)
432
+ }
433
+ }
434
+
435
+ View(NativeEditorExpoView::class) {
436
+ Events(
437
+ "onEditorUpdate",
438
+ "onSelectionChange",
439
+ "onFocusChange",
440
+ "onContentHeightChange",
441
+ "onEditorReady",
442
+ "onToolbarAction",
443
+ "onAddonEvent"
444
+ )
445
+
446
+ Prop("editorId") { view: NativeEditorExpoView, id: Int ->
447
+ view.setEditorId(nativeULong(id)?.toLong() ?: 0L)
448
+ }
449
+ Prop("editable") { view: NativeEditorExpoView, editable: Boolean ->
450
+ view.setEditable(editable)
451
+ }
452
+ Prop("placeholder") { view: NativeEditorExpoView, placeholder: String ->
453
+ view.richTextView.editorEditText.placeholderText = placeholder
454
+ }
455
+ Prop("autoFocus") { view: NativeEditorExpoView, autoFocus: Boolean ->
456
+ view.setAutoFocus(autoFocus)
457
+ }
458
+ Prop("autoCapitalize") { view: NativeEditorExpoView, autoCapitalize: String? ->
459
+ view.setAutoCapitalize(autoCapitalize)
460
+ }
461
+ Prop("autoCorrect") { view: NativeEditorExpoView, autoCorrect: Boolean? ->
462
+ view.setAutoCorrect(autoCorrect)
463
+ }
464
+ Prop("keyboardType") { view: NativeEditorExpoView, keyboardType: String? ->
465
+ view.setKeyboardType(keyboardType)
466
+ }
467
+ Prop("showToolbar") { view: NativeEditorExpoView, showToolbar: Boolean ->
468
+ view.setShowToolbar(showToolbar)
469
+ }
470
+ Prop("toolbarPlacement") { view: NativeEditorExpoView, toolbarPlacement: String? ->
471
+ view.setToolbarPlacement(toolbarPlacement)
472
+ }
473
+ Prop("heightBehavior") { view: NativeEditorExpoView, heightBehavior: String ->
474
+ view.setHeightBehavior(heightBehavior)
475
+ }
476
+ Prop("allowImageResizing") { view: NativeEditorExpoView, allowImageResizing: Boolean ->
477
+ view.setAllowImageResizing(allowImageResizing)
478
+ }
479
+ Prop("themeJson") { view: NativeEditorExpoView, themeJson: String? ->
480
+ view.setThemeJson(themeJson)
481
+ }
482
+ Prop("addonsJson") { view: NativeEditorExpoView, addonsJson: String? ->
483
+ view.setAddonsJson(addonsJson)
484
+ }
485
+ Prop("remoteSelectionsJson") { view: NativeEditorExpoView, remoteSelectionsJson: String? ->
486
+ view.setRemoteSelectionsJson(remoteSelectionsJson)
487
+ }
488
+ Prop("toolbarItemsJson") { view: NativeEditorExpoView, toolbarItemsJson: String? ->
489
+ view.setToolbarItemsJson(toolbarItemsJson)
490
+ }
491
+ Prop("toolbarFrameJson") { view: NativeEditorExpoView, toolbarFrameJson: String? ->
492
+ view.setToolbarFrameJson(toolbarFrameJson)
493
+ }
494
+ Prop("editorUpdateJson") { view: NativeEditorExpoView, editorUpdateJson: String? ->
495
+ view.setPendingEditorUpdateJson(editorUpdateJson)
496
+ }
497
+ Prop("editorUpdateEditorId") { view: NativeEditorExpoView, editorUpdateEditorId: Int? ->
498
+ view.setPendingEditorUpdateEditorId(editorUpdateEditorId?.let { nativeULong(it)?.toLong() })
499
+ }
500
+ Prop("editorUpdateRevision") { view: NativeEditorExpoView, editorUpdateRevision: Int ->
501
+ view.setPendingEditorUpdateRevision(editorUpdateRevision)
502
+ }
503
+ Prop("editorResetUpdateJson") { view: NativeEditorExpoView, editorResetUpdateJson: String? ->
504
+ view.setPendingEditorResetUpdateJson(editorResetUpdateJson)
505
+ }
506
+ Prop("editorResetUpdateEditorId") { view: NativeEditorExpoView, editorResetUpdateEditorId: Int? ->
507
+ view.setPendingEditorResetUpdateEditorId(editorResetUpdateEditorId?.let { nativeULong(it)?.toLong() })
508
+ }
509
+ Prop("editorResetUpdateRevision") { view: NativeEditorExpoView, editorResetUpdateRevision: Int ->
510
+ view.setPendingEditorResetUpdateRevision(editorResetUpdateRevision)
511
+ }
512
+ OnViewDidUpdateProps { view: NativeEditorExpoView ->
513
+ view.applyPendingEditorResetUpdateIfNeeded()
514
+ view.applyPendingEditorUpdateIfNeeded()
515
+ }
516
+
517
+ AsyncFunction("focus") { view: NativeEditorExpoView ->
518
+ view.focus()
519
+ }
520
+ AsyncFunction("blur") { view: NativeEditorExpoView ->
521
+ view.blur()
522
+ }
523
+
524
+ AsyncFunction("getCaretRect") { view: NativeEditorExpoView ->
525
+ view.getCaretRectJson()
526
+ }
527
+
528
+ AsyncFunction("applyEditorUpdate") { view: NativeEditorExpoView, updateJson: String ->
529
+ view.applyEditorUpdate(updateJson)
530
+ }
531
+
532
+ AsyncFunction("applyEditorResetUpdate") { view: NativeEditorExpoView, updateJson: String ->
533
+ view.applyEditorResetUpdate(updateJson)
534
+ }
535
+
536
+ }
537
+
538
+ View(NativeProseViewerExpoView::class) {
539
+ Name("NativeProseViewer")
540
+ Events("onContentHeightChange", "onPressLink", "onPressMention")
541
+
542
+ Prop("renderJson") { view: NativeProseViewerExpoView, renderJson: String? ->
543
+ view.setRenderJson(renderJson)
544
+ }
545
+ Prop("themeJson") { view: NativeProseViewerExpoView, themeJson: String? ->
546
+ view.setThemeJson(themeJson)
547
+ }
548
+ Prop("collapsesWhenEmpty") {
549
+ view: NativeProseViewerExpoView,
550
+ collapsesWhenEmpty: Boolean? ->
551
+ view.setCollapsesWhenEmpty(collapsesWhenEmpty)
552
+ }
553
+ Prop("enableLinkTaps") { view: NativeProseViewerExpoView, enableLinkTaps: Boolean? ->
554
+ view.setEnableLinkTaps(enableLinkTaps)
555
+ }
556
+ Prop("interceptLinkTaps") { view: NativeProseViewerExpoView, interceptLinkTaps: Boolean? ->
557
+ view.setInterceptLinkTaps(interceptLinkTaps)
558
+ }
559
+ }
560
+ }
561
+ }