@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,624 @@
1
+ import ExpoModulesCore
2
+
3
+ private func nativeUInt64(_ value: Int) -> UInt64? {
4
+ guard value >= 0 else { return nil }
5
+ return UInt64(value)
6
+ }
7
+
8
+ private func nativeUInt32(_ value: Int) -> UInt32? {
9
+ guard value >= 0, value <= Int(UInt32.max) else { return nil }
10
+ return UInt32(value)
11
+ }
12
+
13
+ private func nativeArgumentError(_ field: String) -> String {
14
+ "{\"error\":\"invalid \(field)\"}"
15
+ }
16
+
17
+ public class NativeEditorModule: Module {
18
+ public func definition() -> ModuleDefinition {
19
+ Name("NativeEditor")
20
+
21
+ Function("editorCreate") { (configJson: String) -> Int in
22
+ let editorId = editorCreate(configJson: configJson)
23
+ NativeEditorViewRegistry.shared.markEditorCreated(editorId: editorId)
24
+ return Int(editorId)
25
+ }
26
+ Function("editorDestroy") { (id: Int) in
27
+ guard let editorId = nativeUInt64(id) else { return }
28
+ NativeEditorViewRegistry.shared.invalidateDestroyedEditor(editorId: editorId)
29
+ editorDestroy(id: editorId)
30
+ }
31
+ Function("editorPrepareForCommand") { (id: Int) -> String in
32
+ guard let editorId = nativeUInt64(id) else {
33
+ return nativeArgumentError("editor id")
34
+ }
35
+ return NativeEditorViewRegistry.shared.prepareForCommandJSON(editorId: editorId)
36
+ }
37
+ Function("collaborationSessionCreate") { (configJson: String) -> Int in
38
+ Int(collaborationSessionCreate(configJson: configJson))
39
+ }
40
+ Function("collaborationSessionDestroy") { (id: Int) in
41
+ guard let sessionId = nativeUInt64(id) else { return }
42
+ collaborationSessionDestroy(id: sessionId)
43
+ }
44
+ Function("collaborationSessionGetDocumentJson") { (id: Int) -> String in
45
+ guard let sessionId = nativeUInt64(id) else { return "{}" }
46
+ return collaborationSessionGetDocumentJson(id: sessionId)
47
+ }
48
+ Function("collaborationSessionGetEncodedState") { (id: Int) -> String in
49
+ guard let sessionId = nativeUInt64(id) else { return "[]" }
50
+ return collaborationSessionGetEncodedState(id: sessionId)
51
+ }
52
+ Function("collaborationSessionGetPeersJson") { (id: Int) -> String in
53
+ guard let sessionId = nativeUInt64(id) else { return "[]" }
54
+ return collaborationSessionGetPeersJson(id: sessionId)
55
+ }
56
+ Function("collaborationSessionStart") { (id: Int) -> String in
57
+ guard let sessionId = nativeUInt64(id) else { return nativeArgumentError("session id") }
58
+ return collaborationSessionStart(id: sessionId)
59
+ }
60
+ Function("collaborationSessionApplyLocalDocumentJson") { (id: Int, json: String) -> String in
61
+ guard let sessionId = nativeUInt64(id) else { return nativeArgumentError("session id") }
62
+ return collaborationSessionApplyLocalDocumentJson(id: sessionId, json: json)
63
+ }
64
+ Function("collaborationSessionApplyEncodedState") { (id: Int, encodedStateJson: String) -> String in
65
+ guard let sessionId = nativeUInt64(id) else { return nativeArgumentError("session id") }
66
+ return collaborationSessionApplyEncodedState(id: sessionId, encodedStateJson: encodedStateJson)
67
+ }
68
+ Function("collaborationSessionReplaceEncodedState") { (id: Int, encodedStateJson: String) -> String in
69
+ guard let sessionId = nativeUInt64(id) else { return nativeArgumentError("session id") }
70
+ return collaborationSessionReplaceEncodedState(id: sessionId, encodedStateJson: encodedStateJson)
71
+ }
72
+ Function("collaborationSessionHandleMessage") { (id: Int, messageJson: String) -> String in
73
+ guard let sessionId = nativeUInt64(id) else { return nativeArgumentError("session id") }
74
+ return collaborationSessionHandleMessage(id: sessionId, messageJson: messageJson)
75
+ }
76
+ Function("collaborationSessionSetLocalAwareness") { (id: Int, awarenessJson: String) -> String in
77
+ guard let sessionId = nativeUInt64(id) else { return nativeArgumentError("session id") }
78
+ return collaborationSessionSetLocalAwareness(id: sessionId, awarenessJson: awarenessJson)
79
+ }
80
+ Function("collaborationSessionClearLocalAwareness") { (id: Int) -> String in
81
+ guard let sessionId = nativeUInt64(id) else { return nativeArgumentError("session id") }
82
+ return collaborationSessionClearLocalAwareness(id: sessionId)
83
+ }
84
+ Function("editorSetHtml") { (id: Int, html: String) -> String in
85
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
86
+ return editorSetHtml(id: editorId, html: html)
87
+ }
88
+ Function("editorGetHtml") { (id: Int) -> String in
89
+ guard let editorId = nativeUInt64(id) else { return "" }
90
+ return editorGetHtml(id: editorId)
91
+ }
92
+ Function("editorSetJson") { (id: Int, json: String) -> String in
93
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
94
+ return editorSetJson(id: editorId, json: json)
95
+ }
96
+ Function("editorGetJson") { (id: Int) -> String in
97
+ guard let editorId = nativeUInt64(id) else { return "{}" }
98
+ return editorGetJson(id: editorId)
99
+ }
100
+ Function("editorGetContentSnapshot") { (id: Int) -> String in
101
+ guard let editorId = nativeUInt64(id) else { return "{\"html\":\"\",\"json\":{}}" }
102
+ return editorGetContentSnapshot(id: editorId)
103
+ }
104
+ Function("editorInsertText") { (id: Int, pos: Int, text: String) -> String in
105
+ guard let editorId = nativeUInt64(id),
106
+ let pos = nativeUInt32(pos)
107
+ else {
108
+ return nativeArgumentError("position")
109
+ }
110
+ return editorInsertText(id: editorId, pos: pos, text: text)
111
+ }
112
+ Function("editorInsertTextScalar") { (id: Int, scalarPos: Int, text: String) -> String in
113
+ guard let editorId = nativeUInt64(id),
114
+ let scalarPos = nativeUInt32(scalarPos)
115
+ else {
116
+ return nativeArgumentError("position")
117
+ }
118
+ return editorInsertTextScalar(id: editorId, scalarPos: scalarPos, text: text)
119
+ }
120
+ Function("editorReplaceSelectionText") { (id: Int, text: String) -> String in
121
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
122
+ return editorReplaceSelectionText(id: editorId, text: text)
123
+ }
124
+ Function("editorDeleteRange") { (id: Int, from: Int, to: Int) -> String in
125
+ guard let editorId = nativeUInt64(id),
126
+ let from = nativeUInt32(from),
127
+ let to = nativeUInt32(to)
128
+ else {
129
+ return nativeArgumentError("position")
130
+ }
131
+ return editorDeleteRange(id: editorId, from: from, to: to)
132
+ }
133
+ Function("editorDeleteScalarRange") { (id: Int, scalarFrom: Int, scalarTo: Int) -> String in
134
+ guard let editorId = nativeUInt64(id),
135
+ let scalarFrom = nativeUInt32(scalarFrom),
136
+ let scalarTo = nativeUInt32(scalarTo)
137
+ else {
138
+ return nativeArgumentError("position")
139
+ }
140
+ return editorDeleteScalarRange(
141
+ id: editorId,
142
+ scalarFrom: scalarFrom,
143
+ scalarTo: scalarTo
144
+ )
145
+ }
146
+ Function(
147
+ "editorReplaceTextScalar"
148
+ ) { (id: Int, scalarFrom: Int, scalarTo: Int, text: String) -> String in
149
+ guard let editorId = nativeUInt64(id),
150
+ let scalarFrom = nativeUInt32(scalarFrom),
151
+ let scalarTo = nativeUInt32(scalarTo)
152
+ else {
153
+ return nativeArgumentError("position")
154
+ }
155
+ return editorReplaceTextScalar(
156
+ id: editorId,
157
+ scalarFrom: scalarFrom,
158
+ scalarTo: scalarTo,
159
+ text: text
160
+ )
161
+ }
162
+ Function("editorSplitBlock") { (id: Int, pos: Int) -> String in
163
+ guard let editorId = nativeUInt64(id),
164
+ let pos = nativeUInt32(pos)
165
+ else {
166
+ return nativeArgumentError("position")
167
+ }
168
+ return editorSplitBlock(id: editorId, pos: pos)
169
+ }
170
+ Function("editorSplitBlockScalar") { (id: Int, scalarPos: Int) -> String in
171
+ guard let editorId = nativeUInt64(id),
172
+ let scalarPos = nativeUInt32(scalarPos)
173
+ else {
174
+ return nativeArgumentError("position")
175
+ }
176
+ return editorSplitBlockScalar(id: editorId, scalarPos: scalarPos)
177
+ }
178
+ Function("editorDeleteAndSplitScalar") { (id: Int, scalarFrom: Int, scalarTo: Int) -> String in
179
+ guard let editorId = nativeUInt64(id),
180
+ let scalarFrom = nativeUInt32(scalarFrom),
181
+ let scalarTo = nativeUInt32(scalarTo)
182
+ else {
183
+ return nativeArgumentError("position")
184
+ }
185
+ return editorDeleteAndSplitScalar(
186
+ id: editorId,
187
+ scalarFrom: scalarFrom,
188
+ scalarTo: scalarTo
189
+ )
190
+ }
191
+ Function("editorInsertContentHtml") { (id: Int, html: String) -> String in
192
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
193
+ return editorInsertContentHtml(id: editorId, html: html)
194
+ }
195
+ Function("editorToggleMark") { (id: Int, markName: String) -> String in
196
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
197
+ return editorToggleMark(id: editorId, markName: markName)
198
+ }
199
+ Function("editorSetMark") { (id: Int, markName: String, attrsJson: String) -> String in
200
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
201
+ return editorSetMark(id: editorId, markName: markName, attrsJson: attrsJson)
202
+ }
203
+ Function("editorUnsetMark") { (id: Int, markName: String) -> String in
204
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
205
+ return editorUnsetMark(id: editorId, markName: markName)
206
+ }
207
+ Function("editorToggleBlockquote") { (id: Int) -> String in
208
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
209
+ return editorToggleBlockquote(id: editorId)
210
+ }
211
+ Function("editorToggleHeading") { (id: Int, level: Int) -> String in
212
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
213
+ guard (1...6).contains(level) else {
214
+ return "{\"error\":\"invalid heading level\"}"
215
+ }
216
+ return editorToggleHeading(id: editorId, level: UInt8(level))
217
+ }
218
+ Function("editorSetSelection") { (id: Int, anchor: Int, head: Int) in
219
+ guard let editorId = nativeUInt64(id),
220
+ let anchor = nativeUInt32(anchor),
221
+ let head = nativeUInt32(head)
222
+ else {
223
+ return
224
+ }
225
+ editorSetSelection(id: editorId, anchor: anchor, head: head)
226
+ }
227
+ Function("editorSetSelectionScalar") { (id: Int, scalarAnchor: Int, scalarHead: Int) in
228
+ guard let editorId = nativeUInt64(id),
229
+ let scalarAnchor = nativeUInt32(scalarAnchor),
230
+ let scalarHead = nativeUInt32(scalarHead)
231
+ else {
232
+ return
233
+ }
234
+ editorSetSelectionScalar(
235
+ id: editorId,
236
+ scalarAnchor: scalarAnchor,
237
+ scalarHead: scalarHead
238
+ )
239
+ }
240
+ Function(
241
+ "editorToggleMarkAtSelectionScalar"
242
+ ) { (id: Int, scalarAnchor: Int, scalarHead: Int, markName: String) -> String in
243
+ guard let editorId = nativeUInt64(id),
244
+ let scalarAnchor = nativeUInt32(scalarAnchor),
245
+ let scalarHead = nativeUInt32(scalarHead)
246
+ else {
247
+ return nativeArgumentError("position")
248
+ }
249
+ return editorToggleMarkAtSelectionScalar(
250
+ id: editorId,
251
+ scalarAnchor: scalarAnchor,
252
+ scalarHead: scalarHead,
253
+ markName: markName
254
+ )
255
+ }
256
+ Function(
257
+ "editorSetMarkAtSelectionScalar"
258
+ ) { (id: Int, scalarAnchor: Int, scalarHead: Int, markName: String, attrsJson: String) -> String in
259
+ guard let editorId = nativeUInt64(id),
260
+ let scalarAnchor = nativeUInt32(scalarAnchor),
261
+ let scalarHead = nativeUInt32(scalarHead)
262
+ else {
263
+ return nativeArgumentError("position")
264
+ }
265
+ return editorSetMarkAtSelectionScalar(
266
+ id: editorId,
267
+ scalarAnchor: scalarAnchor,
268
+ scalarHead: scalarHead,
269
+ markName: markName,
270
+ attrsJson: attrsJson
271
+ )
272
+ }
273
+ Function(
274
+ "editorUnsetMarkAtSelectionScalar"
275
+ ) { (id: Int, scalarAnchor: Int, scalarHead: Int, markName: String) -> String in
276
+ guard let editorId = nativeUInt64(id),
277
+ let scalarAnchor = nativeUInt32(scalarAnchor),
278
+ let scalarHead = nativeUInt32(scalarHead)
279
+ else {
280
+ return nativeArgumentError("position")
281
+ }
282
+ return editorUnsetMarkAtSelectionScalar(
283
+ id: editorId,
284
+ scalarAnchor: scalarAnchor,
285
+ scalarHead: scalarHead,
286
+ markName: markName
287
+ )
288
+ }
289
+ Function(
290
+ "editorToggleBlockquoteAtSelectionScalar"
291
+ ) { (id: Int, scalarAnchor: Int, scalarHead: Int) -> String in
292
+ guard let editorId = nativeUInt64(id),
293
+ let scalarAnchor = nativeUInt32(scalarAnchor),
294
+ let scalarHead = nativeUInt32(scalarHead)
295
+ else {
296
+ return nativeArgumentError("position")
297
+ }
298
+ return editorToggleBlockquoteAtSelectionScalar(
299
+ id: editorId,
300
+ scalarAnchor: scalarAnchor,
301
+ scalarHead: scalarHead
302
+ )
303
+ }
304
+ Function(
305
+ "editorToggleHeadingAtSelectionScalar"
306
+ ) { (id: Int, scalarAnchor: Int, scalarHead: Int, level: Int) -> String in
307
+ guard let editorId = nativeUInt64(id),
308
+ let scalarAnchor = nativeUInt32(scalarAnchor),
309
+ let scalarHead = nativeUInt32(scalarHead)
310
+ else {
311
+ return nativeArgumentError("position")
312
+ }
313
+ guard (1...6).contains(level) else {
314
+ return "{\"error\":\"invalid heading level\"}"
315
+ }
316
+ return editorToggleHeadingAtSelectionScalar(
317
+ id: editorId,
318
+ scalarAnchor: scalarAnchor,
319
+ scalarHead: scalarHead,
320
+ level: UInt8(level)
321
+ )
322
+ }
323
+ Function(
324
+ "editorWrapInListAtSelectionScalar"
325
+ ) { (id: Int, scalarAnchor: Int, scalarHead: Int, listType: String) -> String in
326
+ guard let editorId = nativeUInt64(id),
327
+ let scalarAnchor = nativeUInt32(scalarAnchor),
328
+ let scalarHead = nativeUInt32(scalarHead)
329
+ else {
330
+ return nativeArgumentError("position")
331
+ }
332
+ return editorWrapInListAtSelectionScalar(
333
+ id: editorId,
334
+ scalarAnchor: scalarAnchor,
335
+ scalarHead: scalarHead,
336
+ listType: listType
337
+ )
338
+ }
339
+ Function(
340
+ "editorUnwrapFromListAtSelectionScalar"
341
+ ) { (id: Int, scalarAnchor: Int, scalarHead: Int) -> String in
342
+ guard let editorId = nativeUInt64(id),
343
+ let scalarAnchor = nativeUInt32(scalarAnchor),
344
+ let scalarHead = nativeUInt32(scalarHead)
345
+ else {
346
+ return nativeArgumentError("position")
347
+ }
348
+ return editorUnwrapFromListAtSelectionScalar(
349
+ id: editorId,
350
+ scalarAnchor: scalarAnchor,
351
+ scalarHead: scalarHead
352
+ )
353
+ }
354
+ Function(
355
+ "editorIndentListItemAtSelectionScalar"
356
+ ) { (id: Int, scalarAnchor: Int, scalarHead: Int) -> String in
357
+ guard let editorId = nativeUInt64(id),
358
+ let scalarAnchor = nativeUInt32(scalarAnchor),
359
+ let scalarHead = nativeUInt32(scalarHead)
360
+ else {
361
+ return nativeArgumentError("position")
362
+ }
363
+ return editorIndentListItemAtSelectionScalar(
364
+ id: editorId,
365
+ scalarAnchor: scalarAnchor,
366
+ scalarHead: scalarHead
367
+ )
368
+ }
369
+ Function(
370
+ "editorOutdentListItemAtSelectionScalar"
371
+ ) { (id: Int, scalarAnchor: Int, scalarHead: Int) -> String in
372
+ guard let editorId = nativeUInt64(id),
373
+ let scalarAnchor = nativeUInt32(scalarAnchor),
374
+ let scalarHead = nativeUInt32(scalarHead)
375
+ else {
376
+ return nativeArgumentError("position")
377
+ }
378
+ return editorOutdentListItemAtSelectionScalar(
379
+ id: editorId,
380
+ scalarAnchor: scalarAnchor,
381
+ scalarHead: scalarHead
382
+ )
383
+ }
384
+ Function(
385
+ "editorInsertNodeAtSelectionScalar"
386
+ ) { (id: Int, scalarAnchor: Int, scalarHead: Int, nodeType: String) -> String in
387
+ guard let editorId = nativeUInt64(id),
388
+ let scalarAnchor = nativeUInt32(scalarAnchor),
389
+ let scalarHead = nativeUInt32(scalarHead)
390
+ else {
391
+ return nativeArgumentError("position")
392
+ }
393
+ return editorInsertNodeAtSelectionScalar(
394
+ id: editorId,
395
+ scalarAnchor: scalarAnchor,
396
+ scalarHead: scalarHead,
397
+ nodeType: nodeType
398
+ )
399
+ }
400
+ Function("editorGetSelection") { (id: Int) -> String in
401
+ guard let editorId = nativeUInt64(id) else {
402
+ return "{\"type\":\"text\",\"anchor\":0,\"head\":0}"
403
+ }
404
+ return editorGetSelection(id: editorId)
405
+ }
406
+ Function("editorGetSelectionState") { (id: Int) -> String in
407
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
408
+ return editorGetSelectionState(id: editorId)
409
+ }
410
+ Function("editorDocToScalar") { (id: Int, docPos: Int) -> Int in
411
+ guard let editorId = nativeUInt64(id),
412
+ let docPos = nativeUInt32(docPos)
413
+ else {
414
+ return 0
415
+ }
416
+ return Int(editorDocToScalar(id: editorId, docPos: docPos))
417
+ }
418
+ Function("editorScalarToDoc") { (id: Int, scalar: Int) -> Int in
419
+ guard let editorId = nativeUInt64(id),
420
+ let scalar = nativeUInt32(scalar)
421
+ else {
422
+ return 0
423
+ }
424
+ return Int(editorScalarToDoc(id: editorId, scalar: scalar))
425
+ }
426
+ Function("editorGetCurrentState") { (id: Int) -> String in
427
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
428
+ return editorGetCurrentState(id: editorId)
429
+ }
430
+ Function("editorUndo") { (id: Int) -> String in
431
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
432
+ return editorUndo(id: editorId)
433
+ }
434
+ Function("editorRedo") { (id: Int) -> String in
435
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
436
+ return editorRedo(id: editorId)
437
+ }
438
+ Function("editorCanUndo") { (id: Int) -> Bool in
439
+ guard let editorId = nativeUInt64(id) else { return false }
440
+ return editorCanUndo(id: editorId)
441
+ }
442
+ Function("editorCanRedo") { (id: Int) -> Bool in
443
+ guard let editorId = nativeUInt64(id) else { return false }
444
+ return editorCanRedo(id: editorId)
445
+ }
446
+ Function("renderDocumentJson") { (configJson: String, json: String) -> String in
447
+ let editorId = editorCreate(configJson: configJson)
448
+ defer {
449
+ editorDestroy(id: editorId)
450
+ }
451
+ return editorSetJson(id: editorId, json: json)
452
+ }
453
+ Function("measureContentHeight") { (renderJson: String, themeJson: String?, width: Double) -> Double in
454
+ let height = RenderBridge.measureHeight(
455
+ forRenderJSON: renderJson,
456
+ themeJSON: themeJson,
457
+ width: CGFloat(width)
458
+ )
459
+ return Double(height)
460
+ }
461
+ Function("renderDocumentHtml") { (configJson: String, html: String) -> String in
462
+ let editorId = editorCreate(configJson: configJson)
463
+ defer {
464
+ editorDestroy(id: editorId)
465
+ }
466
+ return editorSetHtml(id: editorId, html: html)
467
+ }
468
+ Function("editorReplaceHtml") { (id: Int, html: String) -> String in
469
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
470
+ return editorReplaceHtml(id: editorId, html: html)
471
+ }
472
+ Function("editorReplaceJson") { (id: Int, json: String) -> String in
473
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
474
+ return editorReplaceJson(id: editorId, json: json)
475
+ }
476
+ Function("editorInsertContentJson") { (id: Int, json: String) -> String in
477
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
478
+ return editorInsertContentJson(id: editorId, json: json)
479
+ }
480
+ Function(
481
+ "editorInsertContentJsonAtSelectionScalar"
482
+ ) { (id: Int, scalarAnchor: Int, scalarHead: Int, json: String) -> String in
483
+ guard let editorId = nativeUInt64(id),
484
+ let scalarAnchor = nativeUInt32(scalarAnchor),
485
+ let scalarHead = nativeUInt32(scalarHead)
486
+ else {
487
+ return nativeArgumentError("position")
488
+ }
489
+ return editorInsertContentJsonAtSelectionScalar(
490
+ id: editorId,
491
+ scalarAnchor: scalarAnchor,
492
+ scalarHead: scalarHead,
493
+ json: json
494
+ )
495
+ }
496
+ Function("editorWrapInList") { (id: Int, listType: String) -> String in
497
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
498
+ return editorWrapInList(id: editorId, listType: listType)
499
+ }
500
+ Function("editorUnwrapFromList") { (id: Int) -> String in
501
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
502
+ return editorUnwrapFromList(id: editorId)
503
+ }
504
+ Function("editorIndentListItem") { (id: Int) -> String in
505
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
506
+ return editorIndentListItem(id: editorId)
507
+ }
508
+ Function("editorOutdentListItem") { (id: Int) -> String in
509
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
510
+ return editorOutdentListItem(id: editorId)
511
+ }
512
+ Function("editorInsertNode") { (id: Int, nodeType: String) -> String in
513
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
514
+ return editorInsertNode(id: editorId, nodeType: nodeType)
515
+ }
516
+
517
+ View(NativeEditorExpoView.self) {
518
+ Events(
519
+ "onEditorUpdate",
520
+ "onSelectionChange",
521
+ "onFocusChange",
522
+ "onContentHeightChange",
523
+ "onToolbarAction",
524
+ "onAddonEvent"
525
+ )
526
+
527
+ Prop("editorId") { (view: NativeEditorExpoView, id: Int) in
528
+ view.setEditorId(nativeUInt64(id) ?? 0)
529
+ }
530
+ Prop("editable") { (view: NativeEditorExpoView, editable: Bool) in
531
+ view.setEditable(editable)
532
+ }
533
+ Prop("placeholder") { (view: NativeEditorExpoView, placeholder: String) in
534
+ view.richTextView.textView.placeholder = placeholder
535
+ }
536
+ Prop("autoFocus") { (view: NativeEditorExpoView, autoFocus: Bool) in
537
+ view.setAutoFocus(autoFocus)
538
+ }
539
+ Prop("autoCapitalize") { (view: NativeEditorExpoView, autoCapitalize: String?) in
540
+ view.setAutoCapitalize(autoCapitalize)
541
+ }
542
+ Prop("autoCorrect") { (view: NativeEditorExpoView, autoCorrect: Bool?) in
543
+ view.setAutoCorrect(autoCorrect)
544
+ }
545
+ Prop("keyboardType") { (view: NativeEditorExpoView, keyboardType: String?) in
546
+ view.setKeyboardType(keyboardType)
547
+ }
548
+ Prop("keyboardAppearance") { (view: NativeEditorExpoView, keyboardAppearance: String?) in
549
+ view.setKeyboardAppearance(keyboardAppearance)
550
+ }
551
+ Prop("showToolbar") { (view: NativeEditorExpoView, showToolbar: Bool) in
552
+ view.setShowToolbar(showToolbar)
553
+ }
554
+ Prop("toolbarPlacement") { (view: NativeEditorExpoView, toolbarPlacement: String?) in
555
+ view.setToolbarPlacement(toolbarPlacement)
556
+ }
557
+ Prop("heightBehavior") { (view: NativeEditorExpoView, heightBehavior: String) in
558
+ view.setHeightBehavior(heightBehavior)
559
+ }
560
+ Prop("allowImageResizing") { (view: NativeEditorExpoView, allowImageResizing: Bool) in
561
+ view.setAllowImageResizing(allowImageResizing)
562
+ }
563
+ Prop("themeJson") { (view: NativeEditorExpoView, themeJson: String?) in
564
+ view.setThemeJson(themeJson)
565
+ }
566
+ Prop("addonsJson") { (view: NativeEditorExpoView, addonsJson: String?) in
567
+ view.setAddonsJson(addonsJson)
568
+ }
569
+ Prop("remoteSelectionsJson") { (view: NativeEditorExpoView, remoteSelectionsJson: String?) in
570
+ view.setRemoteSelectionsJson(remoteSelectionsJson)
571
+ }
572
+ Prop("toolbarItemsJson") { (view: NativeEditorExpoView, toolbarItemsJson: String?) in
573
+ view.setToolbarButtonsJson(toolbarItemsJson)
574
+ }
575
+ Prop("toolbarFrameJson") { (view: NativeEditorExpoView, toolbarFrameJson: String?) in
576
+ view.setToolbarFrameJson(toolbarFrameJson)
577
+ }
578
+ Prop("editorUpdateJson") { (view: NativeEditorExpoView, editorUpdateJson: String?) in
579
+ view.setPendingEditorUpdateJson(editorUpdateJson)
580
+ }
581
+ Prop("editorUpdateRevision") { (view: NativeEditorExpoView, editorUpdateRevision: Int) in
582
+ view.setPendingEditorUpdateRevision(editorUpdateRevision)
583
+ }
584
+ OnViewDidUpdateProps { (view: NativeEditorExpoView) in
585
+ view.applyPendingEditorUpdateIfNeeded()
586
+ }
587
+
588
+ AsyncFunction("applyEditorUpdate") { (view: NativeEditorExpoView, updateJson: String) -> Bool in
589
+ view.applyEditorUpdate(updateJson)
590
+ }
591
+ AsyncFunction("focus") { (view: NativeEditorExpoView) in
592
+ view.focus()
593
+ }
594
+ AsyncFunction("blur") { (view: NativeEditorExpoView) in
595
+ view.blur()
596
+ }
597
+ AsyncFunction("getCaretRect") { (view: NativeEditorExpoView) -> String? in
598
+ view.getCaretRectJson()
599
+ }
600
+ }
601
+
602
+ View(NativeProseViewerExpoView.self) {
603
+ ViewName("NativeProseViewer")
604
+ Events("onContentHeightChange", "onPressLink", "onPressMention")
605
+
606
+ Prop("renderJson") { (view: NativeProseViewerExpoView, renderJson: String?) in
607
+ view.setRenderJson(renderJson)
608
+ }
609
+ Prop("themeJson") { (view: NativeProseViewerExpoView, themeJson: String?) in
610
+ view.setThemeJson(themeJson)
611
+ }
612
+ Prop("collapsesWhenEmpty") {
613
+ (view: NativeProseViewerExpoView, collapsesWhenEmpty: Bool?) in
614
+ view.setCollapsesWhenEmpty(collapsesWhenEmpty)
615
+ }
616
+ Prop("enableLinkTaps") { (view: NativeProseViewerExpoView, enableLinkTaps: Bool?) in
617
+ view.setEnableLinkTaps(enableLinkTaps)
618
+ }
619
+ Prop("interceptLinkTaps") { (view: NativeProseViewerExpoView, interceptLinkTaps: Bool?) in
620
+ view.setInterceptLinkTaps(interceptLinkTaps)
621
+ }
622
+ }
623
+ }
624
+ }