@apollohg/react-native-prose-editor 0.5.16 → 0.5.17

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.
@@ -1,156 +1,271 @@
1
1
  import ExpoModulesCore
2
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
+
3
17
  public class NativeEditorModule: Module {
4
18
  public func definition() -> ModuleDefinition {
5
19
  Name("NativeEditor")
6
20
 
7
21
  Function("editorCreate") { (configJson: String) -> Int in
8
- Int(editorCreate(configJson: configJson))
22
+ let editorId = editorCreate(configJson: configJson)
23
+ NativeEditorViewRegistry.shared.markEditorCreated(editorId: editorId)
24
+ return Int(editorId)
9
25
  }
10
26
  Function("editorDestroy") { (id: Int) in
11
- editorDestroy(id: UInt64(id))
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)
12
36
  }
13
37
  Function("collaborationSessionCreate") { (configJson: String) -> Int in
14
38
  Int(collaborationSessionCreate(configJson: configJson))
15
39
  }
16
40
  Function("collaborationSessionDestroy") { (id: Int) in
17
- collaborationSessionDestroy(id: UInt64(id))
41
+ guard let sessionId = nativeUInt64(id) else { return }
42
+ collaborationSessionDestroy(id: sessionId)
18
43
  }
19
44
  Function("collaborationSessionGetDocumentJson") { (id: Int) -> String in
20
- collaborationSessionGetDocumentJson(id: UInt64(id))
45
+ guard let sessionId = nativeUInt64(id) else { return "{}" }
46
+ return collaborationSessionGetDocumentJson(id: sessionId)
21
47
  }
22
48
  Function("collaborationSessionGetEncodedState") { (id: Int) -> String in
23
- collaborationSessionGetEncodedState(id: UInt64(id))
49
+ guard let sessionId = nativeUInt64(id) else { return "[]" }
50
+ return collaborationSessionGetEncodedState(id: sessionId)
24
51
  }
25
52
  Function("collaborationSessionGetPeersJson") { (id: Int) -> String in
26
- collaborationSessionGetPeersJson(id: UInt64(id))
53
+ guard let sessionId = nativeUInt64(id) else { return "[]" }
54
+ return collaborationSessionGetPeersJson(id: sessionId)
27
55
  }
28
56
  Function("collaborationSessionStart") { (id: Int) -> String in
29
- collaborationSessionStart(id: UInt64(id))
57
+ guard let sessionId = nativeUInt64(id) else { return nativeArgumentError("session id") }
58
+ return collaborationSessionStart(id: sessionId)
30
59
  }
31
60
  Function("collaborationSessionApplyLocalDocumentJson") { (id: Int, json: String) -> String in
32
- collaborationSessionApplyLocalDocumentJson(id: UInt64(id), json: json)
61
+ guard let sessionId = nativeUInt64(id) else { return nativeArgumentError("session id") }
62
+ return collaborationSessionApplyLocalDocumentJson(id: sessionId, json: json)
33
63
  }
34
64
  Function("collaborationSessionApplyEncodedState") { (id: Int, encodedStateJson: String) -> String in
35
- collaborationSessionApplyEncodedState(id: UInt64(id), encodedStateJson: encodedStateJson)
65
+ guard let sessionId = nativeUInt64(id) else { return nativeArgumentError("session id") }
66
+ return collaborationSessionApplyEncodedState(id: sessionId, encodedStateJson: encodedStateJson)
36
67
  }
37
68
  Function("collaborationSessionReplaceEncodedState") { (id: Int, encodedStateJson: String) -> String in
38
- collaborationSessionReplaceEncodedState(id: UInt64(id), encodedStateJson: encodedStateJson)
69
+ guard let sessionId = nativeUInt64(id) else { return nativeArgumentError("session id") }
70
+ return collaborationSessionReplaceEncodedState(id: sessionId, encodedStateJson: encodedStateJson)
39
71
  }
40
72
  Function("collaborationSessionHandleMessage") { (id: Int, messageJson: String) -> String in
41
- collaborationSessionHandleMessage(id: UInt64(id), messageJson: messageJson)
73
+ guard let sessionId = nativeUInt64(id) else { return nativeArgumentError("session id") }
74
+ return collaborationSessionHandleMessage(id: sessionId, messageJson: messageJson)
42
75
  }
43
76
  Function("collaborationSessionSetLocalAwareness") { (id: Int, awarenessJson: String) -> String in
44
- collaborationSessionSetLocalAwareness(id: UInt64(id), awarenessJson: awarenessJson)
77
+ guard let sessionId = nativeUInt64(id) else { return nativeArgumentError("session id") }
78
+ return collaborationSessionSetLocalAwareness(id: sessionId, awarenessJson: awarenessJson)
45
79
  }
46
80
  Function("collaborationSessionClearLocalAwareness") { (id: Int) -> String in
47
- collaborationSessionClearLocalAwareness(id: UInt64(id))
81
+ guard let sessionId = nativeUInt64(id) else { return nativeArgumentError("session id") }
82
+ return collaborationSessionClearLocalAwareness(id: sessionId)
48
83
  }
49
84
  Function("editorSetHtml") { (id: Int, html: String) -> String in
50
- editorSetHtml(id: UInt64(id), html: html)
85
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
86
+ return editorSetHtml(id: editorId, html: html)
51
87
  }
52
88
  Function("editorGetHtml") { (id: Int) -> String in
53
- editorGetHtml(id: UInt64(id))
89
+ guard let editorId = nativeUInt64(id) else { return "" }
90
+ return editorGetHtml(id: editorId)
54
91
  }
55
92
  Function("editorSetJson") { (id: Int, json: String) -> String in
56
- editorSetJson(id: UInt64(id), json: json)
93
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
94
+ return editorSetJson(id: editorId, json: json)
57
95
  }
58
96
  Function("editorGetJson") { (id: Int) -> String in
59
- editorGetJson(id: UInt64(id))
97
+ guard let editorId = nativeUInt64(id) else { return "{}" }
98
+ return editorGetJson(id: editorId)
60
99
  }
61
100
  Function("editorGetContentSnapshot") { (id: Int) -> String in
62
- editorGetContentSnapshot(id: UInt64(id))
101
+ guard let editorId = nativeUInt64(id) else { return "{\"html\":\"\",\"json\":{}}" }
102
+ return editorGetContentSnapshot(id: editorId)
63
103
  }
64
104
  Function("editorInsertText") { (id: Int, pos: Int, text: String) -> String in
65
- editorInsertText(id: UInt64(id), pos: UInt32(pos), text: text)
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)
66
111
  }
67
112
  Function("editorInsertTextScalar") { (id: Int, scalarPos: Int, text: String) -> String in
68
- editorInsertTextScalar(id: UInt64(id), scalarPos: UInt32(scalarPos), text: text)
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)
69
119
  }
70
120
  Function("editorReplaceSelectionText") { (id: Int, text: String) -> String in
71
- editorReplaceSelectionText(id: UInt64(id), text: text)
121
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
122
+ return editorReplaceSelectionText(id: editorId, text: text)
72
123
  }
73
124
  Function("editorDeleteRange") { (id: Int, from: Int, to: Int) -> String in
74
- editorDeleteRange(id: UInt64(id), from: UInt32(from), to: UInt32(to))
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)
75
132
  }
76
133
  Function("editorDeleteScalarRange") { (id: Int, scalarFrom: Int, scalarTo: Int) -> String in
77
- editorDeleteScalarRange(
78
- id: UInt64(id),
79
- scalarFrom: UInt32(scalarFrom),
80
- scalarTo: UInt32(scalarTo)
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
81
144
  )
82
145
  }
83
146
  Function(
84
147
  "editorReplaceTextScalar"
85
148
  ) { (id: Int, scalarFrom: Int, scalarTo: Int, text: String) -> String in
86
- editorReplaceTextScalar(
87
- id: UInt64(id),
88
- scalarFrom: UInt32(scalarFrom),
89
- scalarTo: UInt32(scalarTo),
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,
90
159
  text: text
91
160
  )
92
161
  }
93
162
  Function("editorSplitBlock") { (id: Int, pos: Int) -> String in
94
- editorSplitBlock(id: UInt64(id), pos: UInt32(pos))
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)
95
169
  }
96
170
  Function("editorSplitBlockScalar") { (id: Int, scalarPos: Int) -> String in
97
- editorSplitBlockScalar(id: UInt64(id), scalarPos: UInt32(scalarPos))
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)
98
177
  }
99
178
  Function("editorDeleteAndSplitScalar") { (id: Int, scalarFrom: Int, scalarTo: Int) -> String in
100
- editorDeleteAndSplitScalar(
101
- id: UInt64(id),
102
- scalarFrom: UInt32(scalarFrom),
103
- scalarTo: UInt32(scalarTo)
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
104
189
  )
105
190
  }
106
191
  Function("editorInsertContentHtml") { (id: Int, html: String) -> String in
107
- editorInsertContentHtml(id: UInt64(id), html: html)
192
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
193
+ return editorInsertContentHtml(id: editorId, html: html)
108
194
  }
109
195
  Function("editorToggleMark") { (id: Int, markName: String) -> String in
110
- editorToggleMark(id: UInt64(id), markName: markName)
196
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
197
+ return editorToggleMark(id: editorId, markName: markName)
111
198
  }
112
199
  Function("editorSetMark") { (id: Int, markName: String, attrsJson: String) -> String in
113
- editorSetMark(id: UInt64(id), markName: markName, attrsJson: attrsJson)
200
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
201
+ return editorSetMark(id: editorId, markName: markName, attrsJson: attrsJson)
114
202
  }
115
203
  Function("editorUnsetMark") { (id: Int, markName: String) -> String in
116
- editorUnsetMark(id: UInt64(id), markName: markName)
204
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
205
+ return editorUnsetMark(id: editorId, markName: markName)
117
206
  }
118
207
  Function("editorToggleBlockquote") { (id: Int) -> String in
119
- editorToggleBlockquote(id: UInt64(id))
208
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
209
+ return editorToggleBlockquote(id: editorId)
120
210
  }
121
211
  Function("editorToggleHeading") { (id: Int, level: Int) -> String in
212
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
122
213
  guard (1...6).contains(level) else {
123
214
  return "{\"error\":\"invalid heading level\"}"
124
215
  }
125
- return editorToggleHeading(id: UInt64(id), level: UInt8(level))
216
+ return editorToggleHeading(id: editorId, level: UInt8(level))
126
217
  }
127
218
  Function("editorSetSelection") { (id: Int, anchor: Int, head: Int) in
128
- editorSetSelection(id: UInt64(id), anchor: UInt32(anchor), head: UInt32(head))
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)
129
226
  }
130
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
+ }
131
234
  editorSetSelectionScalar(
132
- id: UInt64(id),
133
- scalarAnchor: UInt32(scalarAnchor),
134
- scalarHead: UInt32(scalarHead)
235
+ id: editorId,
236
+ scalarAnchor: scalarAnchor,
237
+ scalarHead: scalarHead
135
238
  )
136
239
  }
137
240
  Function(
138
241
  "editorToggleMarkAtSelectionScalar"
139
242
  ) { (id: Int, scalarAnchor: Int, scalarHead: Int, markName: String) -> String in
140
- editorToggleMarkAtSelectionScalar(
141
- id: UInt64(id),
142
- scalarAnchor: UInt32(scalarAnchor),
143
- scalarHead: UInt32(scalarHead),
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,
144
253
  markName: markName
145
254
  )
146
255
  }
147
256
  Function(
148
257
  "editorSetMarkAtSelectionScalar"
149
258
  ) { (id: Int, scalarAnchor: Int, scalarHead: Int, markName: String, attrsJson: String) -> String in
150
- editorSetMarkAtSelectionScalar(
151
- id: UInt64(id),
152
- scalarAnchor: UInt32(scalarAnchor),
153
- scalarHead: UInt32(scalarHead),
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,
154
269
  markName: markName,
155
270
  attrsJson: attrsJson
156
271
  )
@@ -158,108 +273,175 @@ public class NativeEditorModule: Module {
158
273
  Function(
159
274
  "editorUnsetMarkAtSelectionScalar"
160
275
  ) { (id: Int, scalarAnchor: Int, scalarHead: Int, markName: String) -> String in
161
- editorUnsetMarkAtSelectionScalar(
162
- id: UInt64(id),
163
- scalarAnchor: UInt32(scalarAnchor),
164
- scalarHead: UInt32(scalarHead),
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,
165
286
  markName: markName
166
287
  )
167
288
  }
168
289
  Function(
169
290
  "editorToggleBlockquoteAtSelectionScalar"
170
291
  ) { (id: Int, scalarAnchor: Int, scalarHead: Int) -> String in
171
- editorToggleBlockquoteAtSelectionScalar(
172
- id: UInt64(id),
173
- scalarAnchor: UInt32(scalarAnchor),
174
- scalarHead: UInt32(scalarHead)
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
175
302
  )
176
303
  }
177
304
  Function(
178
305
  "editorToggleHeadingAtSelectionScalar"
179
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
+ }
180
313
  guard (1...6).contains(level) else {
181
314
  return "{\"error\":\"invalid heading level\"}"
182
315
  }
183
316
  return editorToggleHeadingAtSelectionScalar(
184
- id: UInt64(id),
185
- scalarAnchor: UInt32(scalarAnchor),
186
- scalarHead: UInt32(scalarHead),
317
+ id: editorId,
318
+ scalarAnchor: scalarAnchor,
319
+ scalarHead: scalarHead,
187
320
  level: UInt8(level)
188
321
  )
189
322
  }
190
323
  Function(
191
324
  "editorWrapInListAtSelectionScalar"
192
325
  ) { (id: Int, scalarAnchor: Int, scalarHead: Int, listType: String) -> String in
193
- editorWrapInListAtSelectionScalar(
194
- id: UInt64(id),
195
- scalarAnchor: UInt32(scalarAnchor),
196
- scalarHead: UInt32(scalarHead),
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,
197
336
  listType: listType
198
337
  )
199
338
  }
200
339
  Function(
201
340
  "editorUnwrapFromListAtSelectionScalar"
202
341
  ) { (id: Int, scalarAnchor: Int, scalarHead: Int) -> String in
203
- editorUnwrapFromListAtSelectionScalar(
204
- id: UInt64(id),
205
- scalarAnchor: UInt32(scalarAnchor),
206
- scalarHead: UInt32(scalarHead)
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
207
352
  )
208
353
  }
209
354
  Function(
210
355
  "editorIndentListItemAtSelectionScalar"
211
356
  ) { (id: Int, scalarAnchor: Int, scalarHead: Int) -> String in
212
- editorIndentListItemAtSelectionScalar(
213
- id: UInt64(id),
214
- scalarAnchor: UInt32(scalarAnchor),
215
- scalarHead: UInt32(scalarHead)
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
216
367
  )
217
368
  }
218
369
  Function(
219
370
  "editorOutdentListItemAtSelectionScalar"
220
371
  ) { (id: Int, scalarAnchor: Int, scalarHead: Int) -> String in
221
- editorOutdentListItemAtSelectionScalar(
222
- id: UInt64(id),
223
- scalarAnchor: UInt32(scalarAnchor),
224
- scalarHead: UInt32(scalarHead)
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
225
382
  )
226
383
  }
227
384
  Function(
228
385
  "editorInsertNodeAtSelectionScalar"
229
386
  ) { (id: Int, scalarAnchor: Int, scalarHead: Int, nodeType: String) -> String in
230
- editorInsertNodeAtSelectionScalar(
231
- id: UInt64(id),
232
- scalarAnchor: UInt32(scalarAnchor),
233
- scalarHead: UInt32(scalarHead),
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,
234
397
  nodeType: nodeType
235
398
  )
236
399
  }
237
400
  Function("editorGetSelection") { (id: Int) -> String in
238
- editorGetSelection(id: UInt64(id))
401
+ guard let editorId = nativeUInt64(id) else {
402
+ return "{\"type\":\"text\",\"anchor\":0,\"head\":0}"
403
+ }
404
+ return editorGetSelection(id: editorId)
239
405
  }
240
406
  Function("editorGetSelectionState") { (id: Int) -> String in
241
- editorGetSelectionState(id: UInt64(id))
407
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
408
+ return editorGetSelectionState(id: editorId)
242
409
  }
243
410
  Function("editorDocToScalar") { (id: Int, docPos: Int) -> Int in
244
- Int(editorDocToScalar(id: UInt64(id), docPos: UInt32(docPos)))
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))
245
417
  }
246
418
  Function("editorScalarToDoc") { (id: Int, scalar: Int) -> Int in
247
- Int(editorScalarToDoc(id: UInt64(id), scalar: UInt32(scalar)))
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))
248
425
  }
249
426
  Function("editorGetCurrentState") { (id: Int) -> String in
250
- editorGetCurrentState(id: UInt64(id))
427
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
428
+ return editorGetCurrentState(id: editorId)
251
429
  }
252
430
  Function("editorUndo") { (id: Int) -> String in
253
- editorUndo(id: UInt64(id))
431
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
432
+ return editorUndo(id: editorId)
254
433
  }
255
434
  Function("editorRedo") { (id: Int) -> String in
256
- editorRedo(id: UInt64(id))
435
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
436
+ return editorRedo(id: editorId)
257
437
  }
258
438
  Function("editorCanUndo") { (id: Int) -> Bool in
259
- editorCanUndo(id: UInt64(id))
439
+ guard let editorId = nativeUInt64(id) else { return false }
440
+ return editorCanUndo(id: editorId)
260
441
  }
261
442
  Function("editorCanRedo") { (id: Int) -> Bool in
262
- editorCanRedo(id: UInt64(id))
443
+ guard let editorId = nativeUInt64(id) else { return false }
444
+ return editorCanRedo(id: editorId)
263
445
  }
264
446
  Function("renderDocumentJson") { (configJson: String, json: String) -> String in
265
447
  let editorId = editorCreate(configJson: configJson)
@@ -284,38 +466,52 @@ public class NativeEditorModule: Module {
284
466
  return editorSetHtml(id: editorId, html: html)
285
467
  }
286
468
  Function("editorReplaceHtml") { (id: Int, html: String) -> String in
287
- editorReplaceHtml(id: UInt64(id), html: html)
469
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
470
+ return editorReplaceHtml(id: editorId, html: html)
288
471
  }
289
472
  Function("editorReplaceJson") { (id: Int, json: String) -> String in
290
- editorReplaceJson(id: UInt64(id), json: json)
473
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
474
+ return editorReplaceJson(id: editorId, json: json)
291
475
  }
292
476
  Function("editorInsertContentJson") { (id: Int, json: String) -> String in
293
- editorInsertContentJson(id: UInt64(id), json: json)
477
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
478
+ return editorInsertContentJson(id: editorId, json: json)
294
479
  }
295
480
  Function(
296
481
  "editorInsertContentJsonAtSelectionScalar"
297
482
  ) { (id: Int, scalarAnchor: Int, scalarHead: Int, json: String) -> String in
298
- editorInsertContentJsonAtSelectionScalar(
299
- id: UInt64(id),
300
- scalarAnchor: UInt32(scalarAnchor),
301
- scalarHead: UInt32(scalarHead),
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,
302
493
  json: json
303
494
  )
304
495
  }
305
496
  Function("editorWrapInList") { (id: Int, listType: String) -> String in
306
- editorWrapInList(id: UInt64(id), listType: listType)
497
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
498
+ return editorWrapInList(id: editorId, listType: listType)
307
499
  }
308
500
  Function("editorUnwrapFromList") { (id: Int) -> String in
309
- editorUnwrapFromList(id: UInt64(id))
501
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
502
+ return editorUnwrapFromList(id: editorId)
310
503
  }
311
504
  Function("editorIndentListItem") { (id: Int) -> String in
312
- editorIndentListItem(id: UInt64(id))
505
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
506
+ return editorIndentListItem(id: editorId)
313
507
  }
314
508
  Function("editorOutdentListItem") { (id: Int) -> String in
315
- editorOutdentListItem(id: UInt64(id))
509
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
510
+ return editorOutdentListItem(id: editorId)
316
511
  }
317
512
  Function("editorInsertNode") { (id: Int, nodeType: String) -> String in
318
- editorInsertNode(id: UInt64(id), nodeType: nodeType)
513
+ guard let editorId = nativeUInt64(id) else { return nativeArgumentError("editor id") }
514
+ return editorInsertNode(id: editorId, nodeType: nodeType)
319
515
  }
320
516
 
321
517
  View(NativeEditorExpoView.self) {
@@ -329,7 +525,7 @@ public class NativeEditorModule: Module {
329
525
  )
330
526
 
331
527
  Prop("editorId") { (view: NativeEditorExpoView, id: Int) in
332
- view.setEditorId(UInt64(id))
528
+ view.setEditorId(nativeUInt64(id) ?? 0)
333
529
  }
334
530
  Prop("editable") { (view: NativeEditorExpoView, editable: Bool) in
335
531
  view.setEditable(editable)
@@ -386,7 +582,7 @@ public class NativeEditorModule: Module {
386
582
  view.applyPendingEditorUpdateIfNeeded()
387
583
  }
388
584
 
389
- AsyncFunction("applyEditorUpdate") { (view: NativeEditorExpoView, updateJson: String) in
585
+ AsyncFunction("applyEditorUpdate") { (view: NativeEditorExpoView, updateJson: String) -> Bool in
390
586
  view.applyEditorUpdate(updateJson)
391
587
  }
392
588
  AsyncFunction("focus") { (view: NativeEditorExpoView) in