@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
|
@@ -0,0 +1,1143 @@
|
|
|
1
|
+
// This file was autogenerated by some hot garbage in the `uniffi` crate.
|
|
2
|
+
// Trust me, you don't want to mess with it!
|
|
3
|
+
|
|
4
|
+
// swiftlint:disable all
|
|
5
|
+
import Foundation
|
|
6
|
+
|
|
7
|
+
// Depending on the consumer's build setup, the low-level FFI code
|
|
8
|
+
// might be in a separate module, or it might be compiled inline into
|
|
9
|
+
// this module. This is a bit of light hackery to work with both.
|
|
10
|
+
#if canImport(editor_coreFFI)
|
|
11
|
+
import editor_coreFFI
|
|
12
|
+
#endif
|
|
13
|
+
|
|
14
|
+
fileprivate extension RustBuffer {
|
|
15
|
+
// Allocate a new buffer, copying the contents of a `UInt8` array.
|
|
16
|
+
init(bytes: [UInt8]) {
|
|
17
|
+
let rbuf = bytes.withUnsafeBufferPointer { ptr in
|
|
18
|
+
RustBuffer.from(ptr)
|
|
19
|
+
}
|
|
20
|
+
self.init(capacity: rbuf.capacity, len: rbuf.len, data: rbuf.data)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static func empty() -> RustBuffer {
|
|
24
|
+
RustBuffer(capacity: 0, len:0, data: nil)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static func from(_ ptr: UnsafeBufferPointer<UInt8>) -> RustBuffer {
|
|
28
|
+
try! rustCall { ffi_editor_core_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Frees the buffer in place.
|
|
32
|
+
// The buffer must not be used after this is called.
|
|
33
|
+
func deallocate() {
|
|
34
|
+
try! rustCall { ffi_editor_core_rustbuffer_free(self, $0) }
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
fileprivate extension ForeignBytes {
|
|
39
|
+
init(bufferPointer: UnsafeBufferPointer<UInt8>) {
|
|
40
|
+
self.init(len: Int32(bufferPointer.count), data: bufferPointer.baseAddress)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// For every type used in the interface, we provide helper methods for conveniently
|
|
45
|
+
// lifting and lowering that type from C-compatible data, and for reading and writing
|
|
46
|
+
// values of that type in a buffer.
|
|
47
|
+
|
|
48
|
+
// Helper classes/extensions that don't change.
|
|
49
|
+
// Someday, this will be in a library of its own.
|
|
50
|
+
|
|
51
|
+
fileprivate extension Data {
|
|
52
|
+
init(rustBuffer: RustBuffer) {
|
|
53
|
+
self.init(
|
|
54
|
+
bytesNoCopy: rustBuffer.data!,
|
|
55
|
+
count: Int(rustBuffer.len),
|
|
56
|
+
deallocator: .none
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Define reader functionality. Normally this would be defined in a class or
|
|
62
|
+
// struct, but we use standalone functions instead in order to make external
|
|
63
|
+
// types work.
|
|
64
|
+
//
|
|
65
|
+
// With external types, one swift source file needs to be able to call the read
|
|
66
|
+
// method on another source file's FfiConverter, but then what visibility
|
|
67
|
+
// should Reader have?
|
|
68
|
+
// - If Reader is fileprivate, then this means the read() must also
|
|
69
|
+
// be fileprivate, which doesn't work with external types.
|
|
70
|
+
// - If Reader is internal/public, we'll get compile errors since both source
|
|
71
|
+
// files will try define the same type.
|
|
72
|
+
//
|
|
73
|
+
// Instead, the read() method and these helper functions input a tuple of data
|
|
74
|
+
|
|
75
|
+
fileprivate func createReader(data: Data) -> (data: Data, offset: Data.Index) {
|
|
76
|
+
(data: data, offset: 0)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Reads an integer at the current offset, in big-endian order, and advances
|
|
80
|
+
// the offset on success. Throws if reading the integer would move the
|
|
81
|
+
// offset past the end of the buffer.
|
|
82
|
+
fileprivate func readInt<T: FixedWidthInteger>(_ reader: inout (data: Data, offset: Data.Index)) throws -> T {
|
|
83
|
+
let range = reader.offset..<reader.offset + MemoryLayout<T>.size
|
|
84
|
+
guard reader.data.count >= range.upperBound else {
|
|
85
|
+
throw UniffiInternalError.bufferOverflow
|
|
86
|
+
}
|
|
87
|
+
if T.self == UInt8.self {
|
|
88
|
+
let value = reader.data[reader.offset]
|
|
89
|
+
reader.offset += 1
|
|
90
|
+
return value as! T
|
|
91
|
+
}
|
|
92
|
+
var value: T = 0
|
|
93
|
+
let _ = withUnsafeMutableBytes(of: &value, { reader.data.copyBytes(to: $0, from: range)})
|
|
94
|
+
reader.offset = range.upperBound
|
|
95
|
+
return value.bigEndian
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Reads an arbitrary number of bytes, to be used to read
|
|
99
|
+
// raw bytes, this is useful when lifting strings
|
|
100
|
+
fileprivate func readBytes(_ reader: inout (data: Data, offset: Data.Index), count: Int) throws -> Array<UInt8> {
|
|
101
|
+
let range = reader.offset..<(reader.offset+count)
|
|
102
|
+
guard reader.data.count >= range.upperBound else {
|
|
103
|
+
throw UniffiInternalError.bufferOverflow
|
|
104
|
+
}
|
|
105
|
+
var value = [UInt8](repeating: 0, count: count)
|
|
106
|
+
value.withUnsafeMutableBufferPointer({ buffer in
|
|
107
|
+
reader.data.copyBytes(to: buffer, from: range)
|
|
108
|
+
})
|
|
109
|
+
reader.offset = range.upperBound
|
|
110
|
+
return value
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Reads a float at the current offset.
|
|
114
|
+
fileprivate func readFloat(_ reader: inout (data: Data, offset: Data.Index)) throws -> Float {
|
|
115
|
+
return Float(bitPattern: try readInt(&reader))
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Reads a float at the current offset.
|
|
119
|
+
fileprivate func readDouble(_ reader: inout (data: Data, offset: Data.Index)) throws -> Double {
|
|
120
|
+
return Double(bitPattern: try readInt(&reader))
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Indicates if the offset has reached the end of the buffer.
|
|
124
|
+
fileprivate func hasRemaining(_ reader: (data: Data, offset: Data.Index)) -> Bool {
|
|
125
|
+
return reader.offset < reader.data.count
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Define writer functionality. Normally this would be defined in a class or
|
|
129
|
+
// struct, but we use standalone functions instead in order to make external
|
|
130
|
+
// types work. See the above discussion on Readers for details.
|
|
131
|
+
|
|
132
|
+
fileprivate func createWriter() -> [UInt8] {
|
|
133
|
+
return []
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
fileprivate func writeBytes<S>(_ writer: inout [UInt8], _ byteArr: S) where S: Sequence, S.Element == UInt8 {
|
|
137
|
+
writer.append(contentsOf: byteArr)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Writes an integer in big-endian order.
|
|
141
|
+
//
|
|
142
|
+
// Warning: make sure what you are trying to write
|
|
143
|
+
// is in the correct type!
|
|
144
|
+
fileprivate func writeInt<T: FixedWidthInteger>(_ writer: inout [UInt8], _ value: T) {
|
|
145
|
+
var value = value.bigEndian
|
|
146
|
+
withUnsafeBytes(of: &value) { writer.append(contentsOf: $0) }
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
fileprivate func writeFloat(_ writer: inout [UInt8], _ value: Float) {
|
|
150
|
+
writeInt(&writer, value.bitPattern)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
fileprivate func writeDouble(_ writer: inout [UInt8], _ value: Double) {
|
|
154
|
+
writeInt(&writer, value.bitPattern)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Protocol for types that transfer other types across the FFI. This is
|
|
158
|
+
// analogous to the Rust trait of the same name.
|
|
159
|
+
fileprivate protocol FfiConverter {
|
|
160
|
+
associatedtype FfiType
|
|
161
|
+
associatedtype SwiftType
|
|
162
|
+
|
|
163
|
+
static func lift(_ value: FfiType) throws -> SwiftType
|
|
164
|
+
static func lower(_ value: SwiftType) -> FfiType
|
|
165
|
+
static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType
|
|
166
|
+
static func write(_ value: SwiftType, into buf: inout [UInt8])
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Types conforming to `Primitive` pass themselves directly over the FFI.
|
|
170
|
+
fileprivate protocol FfiConverterPrimitive: FfiConverter where FfiType == SwiftType { }
|
|
171
|
+
|
|
172
|
+
extension FfiConverterPrimitive {
|
|
173
|
+
#if swift(>=5.8)
|
|
174
|
+
@_documentation(visibility: private)
|
|
175
|
+
#endif
|
|
176
|
+
public static func lift(_ value: FfiType) throws -> SwiftType {
|
|
177
|
+
return value
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
#if swift(>=5.8)
|
|
181
|
+
@_documentation(visibility: private)
|
|
182
|
+
#endif
|
|
183
|
+
public static func lower(_ value: SwiftType) -> FfiType {
|
|
184
|
+
return value
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Types conforming to `FfiConverterRustBuffer` lift and lower into a `RustBuffer`.
|
|
189
|
+
// Used for complex types where it's hard to write a custom lift/lower.
|
|
190
|
+
fileprivate protocol FfiConverterRustBuffer: FfiConverter where FfiType == RustBuffer {}
|
|
191
|
+
|
|
192
|
+
extension FfiConverterRustBuffer {
|
|
193
|
+
#if swift(>=5.8)
|
|
194
|
+
@_documentation(visibility: private)
|
|
195
|
+
#endif
|
|
196
|
+
public static func lift(_ buf: RustBuffer) throws -> SwiftType {
|
|
197
|
+
var reader = createReader(data: Data(rustBuffer: buf))
|
|
198
|
+
let value = try read(from: &reader)
|
|
199
|
+
if hasRemaining(reader) {
|
|
200
|
+
throw UniffiInternalError.incompleteData
|
|
201
|
+
}
|
|
202
|
+
buf.deallocate()
|
|
203
|
+
return value
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
#if swift(>=5.8)
|
|
207
|
+
@_documentation(visibility: private)
|
|
208
|
+
#endif
|
|
209
|
+
public static func lower(_ value: SwiftType) -> RustBuffer {
|
|
210
|
+
var writer = createWriter()
|
|
211
|
+
write(value, into: &writer)
|
|
212
|
+
return RustBuffer(bytes: writer)
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
// An error type for FFI errors. These errors occur at the UniFFI level, not
|
|
216
|
+
// the library level.
|
|
217
|
+
fileprivate enum UniffiInternalError: LocalizedError {
|
|
218
|
+
case bufferOverflow
|
|
219
|
+
case incompleteData
|
|
220
|
+
case unexpectedOptionalTag
|
|
221
|
+
case unexpectedEnumCase
|
|
222
|
+
case unexpectedNullPointer
|
|
223
|
+
case unexpectedRustCallStatusCode
|
|
224
|
+
case unexpectedRustCallError
|
|
225
|
+
case unexpectedStaleHandle
|
|
226
|
+
case rustPanic(_ message: String)
|
|
227
|
+
|
|
228
|
+
public var errorDescription: String? {
|
|
229
|
+
switch self {
|
|
230
|
+
case .bufferOverflow: return "Reading the requested value would read past the end of the buffer"
|
|
231
|
+
case .incompleteData: return "The buffer still has data after lifting its containing value"
|
|
232
|
+
case .unexpectedOptionalTag: return "Unexpected optional tag; should be 0 or 1"
|
|
233
|
+
case .unexpectedEnumCase: return "Raw enum value doesn't match any cases"
|
|
234
|
+
case .unexpectedNullPointer: return "Raw pointer value was null"
|
|
235
|
+
case .unexpectedRustCallStatusCode: return "Unexpected RustCallStatus code"
|
|
236
|
+
case .unexpectedRustCallError: return "CALL_ERROR but no errorClass specified"
|
|
237
|
+
case .unexpectedStaleHandle: return "The object in the handle map has been dropped already"
|
|
238
|
+
case let .rustPanic(message): return message
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
fileprivate extension NSLock {
|
|
244
|
+
func withLock<T>(f: () throws -> T) rethrows -> T {
|
|
245
|
+
self.lock()
|
|
246
|
+
defer { self.unlock() }
|
|
247
|
+
return try f()
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
fileprivate let CALL_SUCCESS: Int8 = 0
|
|
252
|
+
fileprivate let CALL_ERROR: Int8 = 1
|
|
253
|
+
fileprivate let CALL_UNEXPECTED_ERROR: Int8 = 2
|
|
254
|
+
fileprivate let CALL_CANCELLED: Int8 = 3
|
|
255
|
+
|
|
256
|
+
fileprivate extension RustCallStatus {
|
|
257
|
+
init() {
|
|
258
|
+
self.init(
|
|
259
|
+
code: CALL_SUCCESS,
|
|
260
|
+
errorBuf: RustBuffer.init(
|
|
261
|
+
capacity: 0,
|
|
262
|
+
len: 0,
|
|
263
|
+
data: nil
|
|
264
|
+
)
|
|
265
|
+
)
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
private func rustCall<T>(_ callback: (UnsafeMutablePointer<RustCallStatus>) -> T) throws -> T {
|
|
270
|
+
let neverThrow: ((RustBuffer) throws -> Never)? = nil
|
|
271
|
+
return try makeRustCall(callback, errorHandler: neverThrow)
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
private func rustCallWithError<T, E: Swift.Error>(
|
|
275
|
+
_ errorHandler: @escaping (RustBuffer) throws -> E,
|
|
276
|
+
_ callback: (UnsafeMutablePointer<RustCallStatus>) -> T) throws -> T {
|
|
277
|
+
try makeRustCall(callback, errorHandler: errorHandler)
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
private func makeRustCall<T, E: Swift.Error>(
|
|
281
|
+
_ callback: (UnsafeMutablePointer<RustCallStatus>) -> T,
|
|
282
|
+
errorHandler: ((RustBuffer) throws -> E)?
|
|
283
|
+
) throws -> T {
|
|
284
|
+
uniffiEnsureEditorCoreInitialized()
|
|
285
|
+
var callStatus = RustCallStatus.init()
|
|
286
|
+
let returnedVal = callback(&callStatus)
|
|
287
|
+
try uniffiCheckCallStatus(callStatus: callStatus, errorHandler: errorHandler)
|
|
288
|
+
return returnedVal
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
private func uniffiCheckCallStatus<E: Swift.Error>(
|
|
292
|
+
callStatus: RustCallStatus,
|
|
293
|
+
errorHandler: ((RustBuffer) throws -> E)?
|
|
294
|
+
) throws {
|
|
295
|
+
switch callStatus.code {
|
|
296
|
+
case CALL_SUCCESS:
|
|
297
|
+
return
|
|
298
|
+
|
|
299
|
+
case CALL_ERROR:
|
|
300
|
+
if let errorHandler = errorHandler {
|
|
301
|
+
throw try errorHandler(callStatus.errorBuf)
|
|
302
|
+
} else {
|
|
303
|
+
callStatus.errorBuf.deallocate()
|
|
304
|
+
throw UniffiInternalError.unexpectedRustCallError
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
case CALL_UNEXPECTED_ERROR:
|
|
308
|
+
// When the rust code sees a panic, it tries to construct a RustBuffer
|
|
309
|
+
// with the message. But if that code panics, then it just sends back
|
|
310
|
+
// an empty buffer.
|
|
311
|
+
if callStatus.errorBuf.len > 0 {
|
|
312
|
+
throw UniffiInternalError.rustPanic(try FfiConverterString.lift(callStatus.errorBuf))
|
|
313
|
+
} else {
|
|
314
|
+
callStatus.errorBuf.deallocate()
|
|
315
|
+
throw UniffiInternalError.rustPanic("Rust panic")
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
case CALL_CANCELLED:
|
|
319
|
+
fatalError("Cancellation not supported yet")
|
|
320
|
+
|
|
321
|
+
default:
|
|
322
|
+
throw UniffiInternalError.unexpectedRustCallStatusCode
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
private func uniffiTraitInterfaceCall<T>(
|
|
327
|
+
callStatus: UnsafeMutablePointer<RustCallStatus>,
|
|
328
|
+
makeCall: () throws -> T,
|
|
329
|
+
writeReturn: (T) -> ()
|
|
330
|
+
) {
|
|
331
|
+
do {
|
|
332
|
+
try writeReturn(makeCall())
|
|
333
|
+
} catch let error {
|
|
334
|
+
callStatus.pointee.code = CALL_UNEXPECTED_ERROR
|
|
335
|
+
callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error))
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
private func uniffiTraitInterfaceCallWithError<T, E>(
|
|
340
|
+
callStatus: UnsafeMutablePointer<RustCallStatus>,
|
|
341
|
+
makeCall: () throws -> T,
|
|
342
|
+
writeReturn: (T) -> (),
|
|
343
|
+
lowerError: (E) -> RustBuffer
|
|
344
|
+
) {
|
|
345
|
+
do {
|
|
346
|
+
try writeReturn(makeCall())
|
|
347
|
+
} catch let error as E {
|
|
348
|
+
callStatus.pointee.code = CALL_ERROR
|
|
349
|
+
callStatus.pointee.errorBuf = lowerError(error)
|
|
350
|
+
} catch {
|
|
351
|
+
callStatus.pointee.code = CALL_UNEXPECTED_ERROR
|
|
352
|
+
callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error))
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
fileprivate final class UniffiHandleMap<T>: @unchecked Sendable {
|
|
356
|
+
// All mutation happens with this lock held, which is why we implement @unchecked Sendable.
|
|
357
|
+
private let lock = NSLock()
|
|
358
|
+
private var map: [UInt64: T] = [:]
|
|
359
|
+
private var currentHandle: UInt64 = 1
|
|
360
|
+
|
|
361
|
+
func insert(obj: T) -> UInt64 {
|
|
362
|
+
lock.withLock {
|
|
363
|
+
let handle = currentHandle
|
|
364
|
+
currentHandle += 1
|
|
365
|
+
map[handle] = obj
|
|
366
|
+
return handle
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
func get(handle: UInt64) throws -> T {
|
|
371
|
+
try lock.withLock {
|
|
372
|
+
guard let obj = map[handle] else {
|
|
373
|
+
throw UniffiInternalError.unexpectedStaleHandle
|
|
374
|
+
}
|
|
375
|
+
return obj
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
@discardableResult
|
|
380
|
+
func remove(handle: UInt64) throws -> T {
|
|
381
|
+
try lock.withLock {
|
|
382
|
+
guard let obj = map.removeValue(forKey: handle) else {
|
|
383
|
+
throw UniffiInternalError.unexpectedStaleHandle
|
|
384
|
+
}
|
|
385
|
+
return obj
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
var count: Int {
|
|
390
|
+
get {
|
|
391
|
+
map.count
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
// Public interface members begin here.
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
#if swift(>=5.8)
|
|
401
|
+
@_documentation(visibility: private)
|
|
402
|
+
#endif
|
|
403
|
+
fileprivate struct FfiConverterUInt32: FfiConverterPrimitive {
|
|
404
|
+
typealias FfiType = UInt32
|
|
405
|
+
typealias SwiftType = UInt32
|
|
406
|
+
|
|
407
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt32 {
|
|
408
|
+
return try lift(readInt(&buf))
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
|
|
412
|
+
writeInt(&buf, lower(value))
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
#if swift(>=5.8)
|
|
417
|
+
@_documentation(visibility: private)
|
|
418
|
+
#endif
|
|
419
|
+
fileprivate struct FfiConverterUInt64: FfiConverterPrimitive {
|
|
420
|
+
typealias FfiType = UInt64
|
|
421
|
+
typealias SwiftType = UInt64
|
|
422
|
+
|
|
423
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt64 {
|
|
424
|
+
return try lift(readInt(&buf))
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
|
|
428
|
+
writeInt(&buf, lower(value))
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
#if swift(>=5.8)
|
|
433
|
+
@_documentation(visibility: private)
|
|
434
|
+
#endif
|
|
435
|
+
fileprivate struct FfiConverterBool : FfiConverter {
|
|
436
|
+
typealias FfiType = Int8
|
|
437
|
+
typealias SwiftType = Bool
|
|
438
|
+
|
|
439
|
+
public static func lift(_ value: Int8) throws -> Bool {
|
|
440
|
+
return value != 0
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
public static func lower(_ value: Bool) -> Int8 {
|
|
444
|
+
return value ? 1 : 0
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Bool {
|
|
448
|
+
return try lift(readInt(&buf))
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
public static func write(_ value: Bool, into buf: inout [UInt8]) {
|
|
452
|
+
writeInt(&buf, lower(value))
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
#if swift(>=5.8)
|
|
457
|
+
@_documentation(visibility: private)
|
|
458
|
+
#endif
|
|
459
|
+
fileprivate struct FfiConverterString: FfiConverter {
|
|
460
|
+
typealias SwiftType = String
|
|
461
|
+
typealias FfiType = RustBuffer
|
|
462
|
+
|
|
463
|
+
public static func lift(_ value: RustBuffer) throws -> String {
|
|
464
|
+
defer {
|
|
465
|
+
value.deallocate()
|
|
466
|
+
}
|
|
467
|
+
if value.data == nil {
|
|
468
|
+
return String()
|
|
469
|
+
}
|
|
470
|
+
let bytes = UnsafeBufferPointer<UInt8>(start: value.data!, count: Int(value.len))
|
|
471
|
+
return String(bytes: bytes, encoding: String.Encoding.utf8)!
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
public static func lower(_ value: String) -> RustBuffer {
|
|
475
|
+
return value.utf8CString.withUnsafeBufferPointer { ptr in
|
|
476
|
+
// The swift string gives us int8_t, we want uint8_t.
|
|
477
|
+
ptr.withMemoryRebound(to: UInt8.self) { ptr in
|
|
478
|
+
// The swift string gives us a trailing null byte, we don't want it.
|
|
479
|
+
let buf = UnsafeBufferPointer(rebasing: ptr.prefix(upTo: ptr.count - 1))
|
|
480
|
+
return RustBuffer.from(buf)
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> String {
|
|
486
|
+
let len: Int32 = try readInt(&buf)
|
|
487
|
+
return String(bytes: try readBytes(&buf, count: Int(len)), encoding: String.Encoding.utf8)!
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
public static func write(_ value: String, into buf: inout [UInt8]) {
|
|
491
|
+
let len = Int32(value.utf8.count)
|
|
492
|
+
writeInt(&buf, len)
|
|
493
|
+
writeBytes(&buf, value.utf8)
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Check if redo is available.
|
|
498
|
+
*/
|
|
499
|
+
public func editorCanRedo(id: UInt64) -> Bool {
|
|
500
|
+
return try! FfiConverterBool.lift(try! rustCall() {
|
|
501
|
+
uniffi_editor_core_fn_func_editor_can_redo(
|
|
502
|
+
FfiConverterUInt64.lower(id),$0
|
|
503
|
+
)
|
|
504
|
+
})
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Check if undo is available.
|
|
508
|
+
*/
|
|
509
|
+
public func editorCanUndo(id: UInt64) -> Bool {
|
|
510
|
+
return try! FfiConverterBool.lift(try! rustCall() {
|
|
511
|
+
uniffi_editor_core_fn_func_editor_can_undo(
|
|
512
|
+
FfiConverterUInt64.lower(id),$0
|
|
513
|
+
)
|
|
514
|
+
})
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Return the crate version string.
|
|
518
|
+
*/
|
|
519
|
+
public func editorCoreVersion() -> String {
|
|
520
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
521
|
+
uniffi_editor_core_fn_func_editor_core_version($0
|
|
522
|
+
)
|
|
523
|
+
})
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Create a new editor from a JSON config object.
|
|
527
|
+
*
|
|
528
|
+
* Config fields (all optional — empty object `{}` creates a default editor):
|
|
529
|
+
* - `"schema"`: custom schema definition (see `Schema::from_json`)
|
|
530
|
+
* - `"maxLength"`: maximum document length in characters
|
|
531
|
+
* - `"readOnly"`: if `true`, rejects non-API mutations
|
|
532
|
+
* - `"inputFilter"`: regex pattern; only matching characters are inserted
|
|
533
|
+
*
|
|
534
|
+
* Falls back to the default Tiptap schema when `"schema"` is absent or invalid.
|
|
535
|
+
*/
|
|
536
|
+
public func editorCreate(configJson: String) -> UInt64 {
|
|
537
|
+
return try! FfiConverterUInt64.lift(try! rustCall() {
|
|
538
|
+
uniffi_editor_core_fn_func_editor_create(
|
|
539
|
+
FfiConverterString.lower(configJson),$0
|
|
540
|
+
)
|
|
541
|
+
})
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* Delete a scalar range then split the block (Enter with selection). Returns an update.
|
|
545
|
+
*/
|
|
546
|
+
public func editorDeleteAndSplitScalar(id: UInt64, scalarFrom: UInt32, scalarTo: UInt32) -> String {
|
|
547
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
548
|
+
uniffi_editor_core_fn_func_editor_delete_and_split_scalar(
|
|
549
|
+
FfiConverterUInt64.lower(id),
|
|
550
|
+
FfiConverterUInt32.lower(scalarFrom),
|
|
551
|
+
FfiConverterUInt32.lower(scalarTo),$0
|
|
552
|
+
)
|
|
553
|
+
})
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* Delete a range. Returns an update JSON string.
|
|
557
|
+
*/
|
|
558
|
+
public func editorDeleteRange(id: UInt64, from: UInt32, to: UInt32) -> String {
|
|
559
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
560
|
+
uniffi_editor_core_fn_func_editor_delete_range(
|
|
561
|
+
FfiConverterUInt64.lower(id),
|
|
562
|
+
FfiConverterUInt32.lower(from),
|
|
563
|
+
FfiConverterUInt32.lower(to),$0
|
|
564
|
+
)
|
|
565
|
+
})
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Delete content between two scalar offsets. Returns an update JSON string.
|
|
569
|
+
*/
|
|
570
|
+
public func editorDeleteScalarRange(id: UInt64, scalarFrom: UInt32, scalarTo: UInt32) -> String {
|
|
571
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
572
|
+
uniffi_editor_core_fn_func_editor_delete_scalar_range(
|
|
573
|
+
FfiConverterUInt64.lower(id),
|
|
574
|
+
FfiConverterUInt32.lower(scalarFrom),
|
|
575
|
+
FfiConverterUInt32.lower(scalarTo),$0
|
|
576
|
+
)
|
|
577
|
+
})
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* Destroy an editor instance, freeing its resources.
|
|
581
|
+
*/
|
|
582
|
+
public func editorDestroy(id: UInt64) {try! rustCall() {
|
|
583
|
+
uniffi_editor_core_fn_func_editor_destroy(
|
|
584
|
+
FfiConverterUInt64.lower(id),$0
|
|
585
|
+
)
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* Convert a document position to a rendered-text scalar offset.
|
|
590
|
+
*/
|
|
591
|
+
public func editorDocToScalar(id: UInt64, docPos: UInt32) -> UInt32 {
|
|
592
|
+
return try! FfiConverterUInt32.lift(try! rustCall() {
|
|
593
|
+
uniffi_editor_core_fn_func_editor_doc_to_scalar(
|
|
594
|
+
FfiConverterUInt64.lower(id),
|
|
595
|
+
FfiConverterUInt32.lower(docPos),$0
|
|
596
|
+
)
|
|
597
|
+
})
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Get the current editor state (render elements, selection, active state,
|
|
601
|
+
* history state) without performing any edits. Used by native views to pull
|
|
602
|
+
* initial state when binding to an already-loaded editor.
|
|
603
|
+
*/
|
|
604
|
+
public func editorGetCurrentState(id: UInt64) -> String {
|
|
605
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
606
|
+
uniffi_editor_core_fn_func_editor_get_current_state(
|
|
607
|
+
FfiConverterUInt64.lower(id),$0
|
|
608
|
+
)
|
|
609
|
+
})
|
|
610
|
+
}
|
|
611
|
+
/**
|
|
612
|
+
* Get the editor's content as HTML.
|
|
613
|
+
*/
|
|
614
|
+
public func editorGetHtml(id: UInt64) -> String {
|
|
615
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
616
|
+
uniffi_editor_core_fn_func_editor_get_html(
|
|
617
|
+
FfiConverterUInt64.lower(id),$0
|
|
618
|
+
)
|
|
619
|
+
})
|
|
620
|
+
}
|
|
621
|
+
/**
|
|
622
|
+
* Get the editor's content as ProseMirror JSON.
|
|
623
|
+
*/
|
|
624
|
+
public func editorGetJson(id: UInt64) -> String {
|
|
625
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
626
|
+
uniffi_editor_core_fn_func_editor_get_json(
|
|
627
|
+
FfiConverterUInt64.lower(id),$0
|
|
628
|
+
)
|
|
629
|
+
})
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* Get the current selection as JSON.
|
|
633
|
+
*/
|
|
634
|
+
public func editorGetSelection(id: UInt64) -> String {
|
|
635
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
636
|
+
uniffi_editor_core_fn_func_editor_get_selection(
|
|
637
|
+
FfiConverterUInt64.lower(id),$0
|
|
638
|
+
)
|
|
639
|
+
})
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* Indent the current list item into a nested list. Returns an update JSON string.
|
|
643
|
+
*/
|
|
644
|
+
public func editorIndentListItem(id: UInt64) -> String {
|
|
645
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
646
|
+
uniffi_editor_core_fn_func_editor_indent_list_item(
|
|
647
|
+
FfiConverterUInt64.lower(id),$0
|
|
648
|
+
)
|
|
649
|
+
})
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* Indent the list item at an explicit scalar selection. Returns an update JSON string.
|
|
653
|
+
*/
|
|
654
|
+
public func editorIndentListItemAtSelectionScalar(id: UInt64, scalarAnchor: UInt32, scalarHead: UInt32) -> String {
|
|
655
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
656
|
+
uniffi_editor_core_fn_func_editor_indent_list_item_at_selection_scalar(
|
|
657
|
+
FfiConverterUInt64.lower(id),
|
|
658
|
+
FfiConverterUInt32.lower(scalarAnchor),
|
|
659
|
+
FfiConverterUInt32.lower(scalarHead),$0
|
|
660
|
+
)
|
|
661
|
+
})
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* Insert HTML content at the current selection. Returns an update JSON string.
|
|
665
|
+
*/
|
|
666
|
+
public func editorInsertContentHtml(id: UInt64, html: String) -> String {
|
|
667
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
668
|
+
uniffi_editor_core_fn_func_editor_insert_content_html(
|
|
669
|
+
FfiConverterUInt64.lower(id),
|
|
670
|
+
FfiConverterString.lower(html),$0
|
|
671
|
+
)
|
|
672
|
+
})
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Insert JSON content at the current selection. Returns an update JSON string.
|
|
676
|
+
*/
|
|
677
|
+
public func editorInsertContentJson(id: UInt64, json: String) -> String {
|
|
678
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
679
|
+
uniffi_editor_core_fn_func_editor_insert_content_json(
|
|
680
|
+
FfiConverterUInt64.lower(id),
|
|
681
|
+
FfiConverterString.lower(json),$0
|
|
682
|
+
)
|
|
683
|
+
})
|
|
684
|
+
}
|
|
685
|
+
/**
|
|
686
|
+
* Insert JSON content at an explicit scalar selection. Returns an update JSON string.
|
|
687
|
+
*/
|
|
688
|
+
public func editorInsertContentJsonAtSelectionScalar(id: UInt64, scalarAnchor: UInt32, scalarHead: UInt32, json: String) -> String {
|
|
689
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
690
|
+
uniffi_editor_core_fn_func_editor_insert_content_json_at_selection_scalar(
|
|
691
|
+
FfiConverterUInt64.lower(id),
|
|
692
|
+
FfiConverterUInt32.lower(scalarAnchor),
|
|
693
|
+
FfiConverterUInt32.lower(scalarHead),
|
|
694
|
+
FfiConverterString.lower(json),$0
|
|
695
|
+
)
|
|
696
|
+
})
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
* Insert a void node at the current selection. Returns an update JSON string.
|
|
700
|
+
*/
|
|
701
|
+
public func editorInsertNode(id: UInt64, nodeType: String) -> String {
|
|
702
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
703
|
+
uniffi_editor_core_fn_func_editor_insert_node(
|
|
704
|
+
FfiConverterUInt64.lower(id),
|
|
705
|
+
FfiConverterString.lower(nodeType),$0
|
|
706
|
+
)
|
|
707
|
+
})
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* Insert a node at an explicit scalar selection. Returns an update JSON string.
|
|
711
|
+
*/
|
|
712
|
+
public func editorInsertNodeAtSelectionScalar(id: UInt64, scalarAnchor: UInt32, scalarHead: UInt32, nodeType: String) -> String {
|
|
713
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
714
|
+
uniffi_editor_core_fn_func_editor_insert_node_at_selection_scalar(
|
|
715
|
+
FfiConverterUInt64.lower(id),
|
|
716
|
+
FfiConverterUInt32.lower(scalarAnchor),
|
|
717
|
+
FfiConverterUInt32.lower(scalarHead),
|
|
718
|
+
FfiConverterString.lower(nodeType),$0
|
|
719
|
+
)
|
|
720
|
+
})
|
|
721
|
+
}
|
|
722
|
+
/**
|
|
723
|
+
* Insert text at a position. Returns an update JSON string.
|
|
724
|
+
*/
|
|
725
|
+
public func editorInsertText(id: UInt64, pos: UInt32, text: String) -> String {
|
|
726
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
727
|
+
uniffi_editor_core_fn_func_editor_insert_text(
|
|
728
|
+
FfiConverterUInt64.lower(id),
|
|
729
|
+
FfiConverterUInt32.lower(pos),
|
|
730
|
+
FfiConverterString.lower(text),$0
|
|
731
|
+
)
|
|
732
|
+
})
|
|
733
|
+
}
|
|
734
|
+
/**
|
|
735
|
+
* Insert text at a scalar offset. Returns an update JSON string.
|
|
736
|
+
*/
|
|
737
|
+
public func editorInsertTextScalar(id: UInt64, scalarPos: UInt32, text: String) -> String {
|
|
738
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
739
|
+
uniffi_editor_core_fn_func_editor_insert_text_scalar(
|
|
740
|
+
FfiConverterUInt64.lower(id),
|
|
741
|
+
FfiConverterUInt32.lower(scalarPos),
|
|
742
|
+
FfiConverterString.lower(text),$0
|
|
743
|
+
)
|
|
744
|
+
})
|
|
745
|
+
}
|
|
746
|
+
/**
|
|
747
|
+
* Outdent the current list item to the parent list level. Returns an update JSON string.
|
|
748
|
+
*/
|
|
749
|
+
public func editorOutdentListItem(id: UInt64) -> String {
|
|
750
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
751
|
+
uniffi_editor_core_fn_func_editor_outdent_list_item(
|
|
752
|
+
FfiConverterUInt64.lower(id),$0
|
|
753
|
+
)
|
|
754
|
+
})
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* Outdent the list item at an explicit scalar selection. Returns an update JSON string.
|
|
758
|
+
*/
|
|
759
|
+
public func editorOutdentListItemAtSelectionScalar(id: UInt64, scalarAnchor: UInt32, scalarHead: UInt32) -> String {
|
|
760
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
761
|
+
uniffi_editor_core_fn_func_editor_outdent_list_item_at_selection_scalar(
|
|
762
|
+
FfiConverterUInt64.lower(id),
|
|
763
|
+
FfiConverterUInt32.lower(scalarAnchor),
|
|
764
|
+
FfiConverterUInt32.lower(scalarHead),$0
|
|
765
|
+
)
|
|
766
|
+
})
|
|
767
|
+
}
|
|
768
|
+
/**
|
|
769
|
+
* Redo. Returns an update JSON string, or empty string if nothing to redo.
|
|
770
|
+
*/
|
|
771
|
+
public func editorRedo(id: UInt64) -> String {
|
|
772
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
773
|
+
uniffi_editor_core_fn_func_editor_redo(
|
|
774
|
+
FfiConverterUInt64.lower(id),$0
|
|
775
|
+
)
|
|
776
|
+
})
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* Replace entire document content with HTML via a transaction (preserves history).
|
|
780
|
+
*/
|
|
781
|
+
public func editorReplaceHtml(id: UInt64, html: String) -> String {
|
|
782
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
783
|
+
uniffi_editor_core_fn_func_editor_replace_html(
|
|
784
|
+
FfiConverterUInt64.lower(id),
|
|
785
|
+
FfiConverterString.lower(html),$0
|
|
786
|
+
)
|
|
787
|
+
})
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* Replace entire document content with JSON via a transaction (preserves history).
|
|
791
|
+
*/
|
|
792
|
+
public func editorReplaceJson(id: UInt64, json: String) -> String {
|
|
793
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
794
|
+
uniffi_editor_core_fn_func_editor_replace_json(
|
|
795
|
+
FfiConverterUInt64.lower(id),
|
|
796
|
+
FfiConverterString.lower(json),$0
|
|
797
|
+
)
|
|
798
|
+
})
|
|
799
|
+
}
|
|
800
|
+
/**
|
|
801
|
+
* Replace the current selection with plain text. Returns an update JSON string.
|
|
802
|
+
*/
|
|
803
|
+
public func editorReplaceSelectionText(id: UInt64, text: String) -> String {
|
|
804
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
805
|
+
uniffi_editor_core_fn_func_editor_replace_selection_text(
|
|
806
|
+
FfiConverterUInt64.lower(id),
|
|
807
|
+
FfiConverterString.lower(text),$0
|
|
808
|
+
)
|
|
809
|
+
})
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* Replace a scalar range with text (atomic delete + insert). Returns an update JSON string.
|
|
813
|
+
*/
|
|
814
|
+
public func editorReplaceTextScalar(id: UInt64, scalarFrom: UInt32, scalarTo: UInt32, text: String) -> String {
|
|
815
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
816
|
+
uniffi_editor_core_fn_func_editor_replace_text_scalar(
|
|
817
|
+
FfiConverterUInt64.lower(id),
|
|
818
|
+
FfiConverterUInt32.lower(scalarFrom),
|
|
819
|
+
FfiConverterUInt32.lower(scalarTo),
|
|
820
|
+
FfiConverterString.lower(text),$0
|
|
821
|
+
)
|
|
822
|
+
})
|
|
823
|
+
}
|
|
824
|
+
/**
|
|
825
|
+
* Convert a rendered-text scalar offset to a document position.
|
|
826
|
+
*/
|
|
827
|
+
public func editorScalarToDoc(id: UInt64, scalar: UInt32) -> UInt32 {
|
|
828
|
+
return try! FfiConverterUInt32.lift(try! rustCall() {
|
|
829
|
+
uniffi_editor_core_fn_func_editor_scalar_to_doc(
|
|
830
|
+
FfiConverterUInt64.lower(id),
|
|
831
|
+
FfiConverterUInt32.lower(scalar),$0
|
|
832
|
+
)
|
|
833
|
+
})
|
|
834
|
+
}
|
|
835
|
+
/**
|
|
836
|
+
* Set the editor's content from an HTML string. Returns render elements as JSON.
|
|
837
|
+
*/
|
|
838
|
+
public func editorSetHtml(id: UInt64, html: String) -> String {
|
|
839
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
840
|
+
uniffi_editor_core_fn_func_editor_set_html(
|
|
841
|
+
FfiConverterUInt64.lower(id),
|
|
842
|
+
FfiConverterString.lower(html),$0
|
|
843
|
+
)
|
|
844
|
+
})
|
|
845
|
+
}
|
|
846
|
+
/**
|
|
847
|
+
* Set the editor's content from a ProseMirror JSON string.
|
|
848
|
+
*/
|
|
849
|
+
public func editorSetJson(id: UInt64, json: String) -> String {
|
|
850
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
851
|
+
uniffi_editor_core_fn_func_editor_set_json(
|
|
852
|
+
FfiConverterUInt64.lower(id),
|
|
853
|
+
FfiConverterString.lower(json),$0
|
|
854
|
+
)
|
|
855
|
+
})
|
|
856
|
+
}
|
|
857
|
+
/**
|
|
858
|
+
* Set the selection. Anchor and head are document positions.
|
|
859
|
+
*/
|
|
860
|
+
public func editorSetSelection(id: UInt64, anchor: UInt32, head: UInt32) {try! rustCall() {
|
|
861
|
+
uniffi_editor_core_fn_func_editor_set_selection(
|
|
862
|
+
FfiConverterUInt64.lower(id),
|
|
863
|
+
FfiConverterUInt32.lower(anchor),
|
|
864
|
+
FfiConverterUInt32.lower(head),$0
|
|
865
|
+
)
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
/**
|
|
869
|
+
* Set the selection from scalar offsets, converting to document positions internally.
|
|
870
|
+
*/
|
|
871
|
+
public func editorSetSelectionScalar(id: UInt64, scalarAnchor: UInt32, scalarHead: UInt32) {try! rustCall() {
|
|
872
|
+
uniffi_editor_core_fn_func_editor_set_selection_scalar(
|
|
873
|
+
FfiConverterUInt64.lower(id),
|
|
874
|
+
FfiConverterUInt32.lower(scalarAnchor),
|
|
875
|
+
FfiConverterUInt32.lower(scalarHead),$0
|
|
876
|
+
)
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
/**
|
|
880
|
+
* Split the block at a position (Enter key). Returns an update JSON string.
|
|
881
|
+
*/
|
|
882
|
+
public func editorSplitBlock(id: UInt64, pos: UInt32) -> String {
|
|
883
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
884
|
+
uniffi_editor_core_fn_func_editor_split_block(
|
|
885
|
+
FfiConverterUInt64.lower(id),
|
|
886
|
+
FfiConverterUInt32.lower(pos),$0
|
|
887
|
+
)
|
|
888
|
+
})
|
|
889
|
+
}
|
|
890
|
+
/**
|
|
891
|
+
* Split a block at a scalar offset. Returns an update JSON string.
|
|
892
|
+
*/
|
|
893
|
+
public func editorSplitBlockScalar(id: UInt64, scalarPos: UInt32) -> String {
|
|
894
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
895
|
+
uniffi_editor_core_fn_func_editor_split_block_scalar(
|
|
896
|
+
FfiConverterUInt64.lower(id),
|
|
897
|
+
FfiConverterUInt32.lower(scalarPos),$0
|
|
898
|
+
)
|
|
899
|
+
})
|
|
900
|
+
}
|
|
901
|
+
/**
|
|
902
|
+
* Toggle a mark on the current selection. Returns an update JSON string.
|
|
903
|
+
*/
|
|
904
|
+
public func editorToggleMark(id: UInt64, markName: String) -> String {
|
|
905
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
906
|
+
uniffi_editor_core_fn_func_editor_toggle_mark(
|
|
907
|
+
FfiConverterUInt64.lower(id),
|
|
908
|
+
FfiConverterString.lower(markName),$0
|
|
909
|
+
)
|
|
910
|
+
})
|
|
911
|
+
}
|
|
912
|
+
/**
|
|
913
|
+
* Toggle a mark at an explicit scalar selection. Returns an update JSON string.
|
|
914
|
+
*/
|
|
915
|
+
public func editorToggleMarkAtSelectionScalar(id: UInt64, scalarAnchor: UInt32, scalarHead: UInt32, markName: String) -> String {
|
|
916
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
917
|
+
uniffi_editor_core_fn_func_editor_toggle_mark_at_selection_scalar(
|
|
918
|
+
FfiConverterUInt64.lower(id),
|
|
919
|
+
FfiConverterUInt32.lower(scalarAnchor),
|
|
920
|
+
FfiConverterUInt32.lower(scalarHead),
|
|
921
|
+
FfiConverterString.lower(markName),$0
|
|
922
|
+
)
|
|
923
|
+
})
|
|
924
|
+
}
|
|
925
|
+
/**
|
|
926
|
+
* Undo. Returns an update JSON string, or empty string if nothing to undo.
|
|
927
|
+
*/
|
|
928
|
+
public func editorUndo(id: UInt64) -> String {
|
|
929
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
930
|
+
uniffi_editor_core_fn_func_editor_undo(
|
|
931
|
+
FfiConverterUInt64.lower(id),$0
|
|
932
|
+
)
|
|
933
|
+
})
|
|
934
|
+
}
|
|
935
|
+
/**
|
|
936
|
+
* Unwrap the current list item back to a paragraph. Returns an update JSON string.
|
|
937
|
+
*/
|
|
938
|
+
public func editorUnwrapFromList(id: UInt64) -> String {
|
|
939
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
940
|
+
uniffi_editor_core_fn_func_editor_unwrap_from_list(
|
|
941
|
+
FfiConverterUInt64.lower(id),$0
|
|
942
|
+
)
|
|
943
|
+
})
|
|
944
|
+
}
|
|
945
|
+
/**
|
|
946
|
+
* Unwrap the list item at an explicit scalar selection. Returns an update JSON string.
|
|
947
|
+
*/
|
|
948
|
+
public func editorUnwrapFromListAtSelectionScalar(id: UInt64, scalarAnchor: UInt32, scalarHead: UInt32) -> String {
|
|
949
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
950
|
+
uniffi_editor_core_fn_func_editor_unwrap_from_list_at_selection_scalar(
|
|
951
|
+
FfiConverterUInt64.lower(id),
|
|
952
|
+
FfiConverterUInt32.lower(scalarAnchor),
|
|
953
|
+
FfiConverterUInt32.lower(scalarHead),$0
|
|
954
|
+
)
|
|
955
|
+
})
|
|
956
|
+
}
|
|
957
|
+
/**
|
|
958
|
+
* Wrap the current selection in a list. Returns an update JSON string.
|
|
959
|
+
*/
|
|
960
|
+
public func editorWrapInList(id: UInt64, listType: String) -> String {
|
|
961
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
962
|
+
uniffi_editor_core_fn_func_editor_wrap_in_list(
|
|
963
|
+
FfiConverterUInt64.lower(id),
|
|
964
|
+
FfiConverterString.lower(listType),$0
|
|
965
|
+
)
|
|
966
|
+
})
|
|
967
|
+
}
|
|
968
|
+
/**
|
|
969
|
+
* Wrap or convert a list at an explicit scalar selection. Returns an update JSON string.
|
|
970
|
+
*/
|
|
971
|
+
public func editorWrapInListAtSelectionScalar(id: UInt64, scalarAnchor: UInt32, scalarHead: UInt32, listType: String) -> String {
|
|
972
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
973
|
+
uniffi_editor_core_fn_func_editor_wrap_in_list_at_selection_scalar(
|
|
974
|
+
FfiConverterUInt64.lower(id),
|
|
975
|
+
FfiConverterUInt32.lower(scalarAnchor),
|
|
976
|
+
FfiConverterUInt32.lower(scalarHead),
|
|
977
|
+
FfiConverterString.lower(listType),$0
|
|
978
|
+
)
|
|
979
|
+
})
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
private enum InitializationResult {
|
|
983
|
+
case ok
|
|
984
|
+
case contractVersionMismatch
|
|
985
|
+
case apiChecksumMismatch
|
|
986
|
+
}
|
|
987
|
+
// Use a global variable to perform the versioning checks. Swift ensures that
|
|
988
|
+
// the code inside is only computed once.
|
|
989
|
+
private let initializationResult: InitializationResult = {
|
|
990
|
+
// Get the bindings contract version from our ComponentInterface
|
|
991
|
+
let bindings_contract_version = 29
|
|
992
|
+
// Get the scaffolding contract version by calling the into the dylib
|
|
993
|
+
let scaffolding_contract_version = ffi_editor_core_uniffi_contract_version()
|
|
994
|
+
if bindings_contract_version != scaffolding_contract_version {
|
|
995
|
+
return InitializationResult.contractVersionMismatch
|
|
996
|
+
}
|
|
997
|
+
if (uniffi_editor_core_checksum_func_editor_can_redo() != 15854) {
|
|
998
|
+
return InitializationResult.apiChecksumMismatch
|
|
999
|
+
}
|
|
1000
|
+
if (uniffi_editor_core_checksum_func_editor_can_undo() != 52062) {
|
|
1001
|
+
return InitializationResult.apiChecksumMismatch
|
|
1002
|
+
}
|
|
1003
|
+
if (uniffi_editor_core_checksum_func_editor_core_version() != 41638) {
|
|
1004
|
+
return InitializationResult.apiChecksumMismatch
|
|
1005
|
+
}
|
|
1006
|
+
if (uniffi_editor_core_checksum_func_editor_create() != 23908) {
|
|
1007
|
+
return InitializationResult.apiChecksumMismatch
|
|
1008
|
+
}
|
|
1009
|
+
if (uniffi_editor_core_checksum_func_editor_delete_and_split_scalar() != 13764) {
|
|
1010
|
+
return InitializationResult.apiChecksumMismatch
|
|
1011
|
+
}
|
|
1012
|
+
if (uniffi_editor_core_checksum_func_editor_delete_range() != 6109) {
|
|
1013
|
+
return InitializationResult.apiChecksumMismatch
|
|
1014
|
+
}
|
|
1015
|
+
if (uniffi_editor_core_checksum_func_editor_delete_scalar_range() != 60098) {
|
|
1016
|
+
return InitializationResult.apiChecksumMismatch
|
|
1017
|
+
}
|
|
1018
|
+
if (uniffi_editor_core_checksum_func_editor_destroy() != 35774) {
|
|
1019
|
+
return InitializationResult.apiChecksumMismatch
|
|
1020
|
+
}
|
|
1021
|
+
if (uniffi_editor_core_checksum_func_editor_doc_to_scalar() != 48291) {
|
|
1022
|
+
return InitializationResult.apiChecksumMismatch
|
|
1023
|
+
}
|
|
1024
|
+
if (uniffi_editor_core_checksum_func_editor_get_current_state() != 13946) {
|
|
1025
|
+
return InitializationResult.apiChecksumMismatch
|
|
1026
|
+
}
|
|
1027
|
+
if (uniffi_editor_core_checksum_func_editor_get_html() != 28868) {
|
|
1028
|
+
return InitializationResult.apiChecksumMismatch
|
|
1029
|
+
}
|
|
1030
|
+
if (uniffi_editor_core_checksum_func_editor_get_json() != 8212) {
|
|
1031
|
+
return InitializationResult.apiChecksumMismatch
|
|
1032
|
+
}
|
|
1033
|
+
if (uniffi_editor_core_checksum_func_editor_get_selection() != 20571) {
|
|
1034
|
+
return InitializationResult.apiChecksumMismatch
|
|
1035
|
+
}
|
|
1036
|
+
if (uniffi_editor_core_checksum_func_editor_indent_list_item() != 10818) {
|
|
1037
|
+
return InitializationResult.apiChecksumMismatch
|
|
1038
|
+
}
|
|
1039
|
+
if (uniffi_editor_core_checksum_func_editor_indent_list_item_at_selection_scalar() != 13664) {
|
|
1040
|
+
return InitializationResult.apiChecksumMismatch
|
|
1041
|
+
}
|
|
1042
|
+
if (uniffi_editor_core_checksum_func_editor_insert_content_html() != 62700) {
|
|
1043
|
+
return InitializationResult.apiChecksumMismatch
|
|
1044
|
+
}
|
|
1045
|
+
if (uniffi_editor_core_checksum_func_editor_insert_content_json() != 56904) {
|
|
1046
|
+
return InitializationResult.apiChecksumMismatch
|
|
1047
|
+
}
|
|
1048
|
+
if (uniffi_editor_core_checksum_func_editor_insert_content_json_at_selection_scalar() != 51362) {
|
|
1049
|
+
return InitializationResult.apiChecksumMismatch
|
|
1050
|
+
}
|
|
1051
|
+
if (uniffi_editor_core_checksum_func_editor_insert_node() != 22371) {
|
|
1052
|
+
return InitializationResult.apiChecksumMismatch
|
|
1053
|
+
}
|
|
1054
|
+
if (uniffi_editor_core_checksum_func_editor_insert_node_at_selection_scalar() != 32254) {
|
|
1055
|
+
return InitializationResult.apiChecksumMismatch
|
|
1056
|
+
}
|
|
1057
|
+
if (uniffi_editor_core_checksum_func_editor_insert_text() != 22584) {
|
|
1058
|
+
return InitializationResult.apiChecksumMismatch
|
|
1059
|
+
}
|
|
1060
|
+
if (uniffi_editor_core_checksum_func_editor_insert_text_scalar() != 30263) {
|
|
1061
|
+
return InitializationResult.apiChecksumMismatch
|
|
1062
|
+
}
|
|
1063
|
+
if (uniffi_editor_core_checksum_func_editor_outdent_list_item() != 55796) {
|
|
1064
|
+
return InitializationResult.apiChecksumMismatch
|
|
1065
|
+
}
|
|
1066
|
+
if (uniffi_editor_core_checksum_func_editor_outdent_list_item_at_selection_scalar() != 32672) {
|
|
1067
|
+
return InitializationResult.apiChecksumMismatch
|
|
1068
|
+
}
|
|
1069
|
+
if (uniffi_editor_core_checksum_func_editor_redo() != 26508) {
|
|
1070
|
+
return InitializationResult.apiChecksumMismatch
|
|
1071
|
+
}
|
|
1072
|
+
if (uniffi_editor_core_checksum_func_editor_replace_html() != 41778) {
|
|
1073
|
+
return InitializationResult.apiChecksumMismatch
|
|
1074
|
+
}
|
|
1075
|
+
if (uniffi_editor_core_checksum_func_editor_replace_json() != 28738) {
|
|
1076
|
+
return InitializationResult.apiChecksumMismatch
|
|
1077
|
+
}
|
|
1078
|
+
if (uniffi_editor_core_checksum_func_editor_replace_selection_text() != 11138) {
|
|
1079
|
+
return InitializationResult.apiChecksumMismatch
|
|
1080
|
+
}
|
|
1081
|
+
if (uniffi_editor_core_checksum_func_editor_replace_text_scalar() != 45475) {
|
|
1082
|
+
return InitializationResult.apiChecksumMismatch
|
|
1083
|
+
}
|
|
1084
|
+
if (uniffi_editor_core_checksum_func_editor_scalar_to_doc() != 40126) {
|
|
1085
|
+
return InitializationResult.apiChecksumMismatch
|
|
1086
|
+
}
|
|
1087
|
+
if (uniffi_editor_core_checksum_func_editor_set_html() != 11045) {
|
|
1088
|
+
return InitializationResult.apiChecksumMismatch
|
|
1089
|
+
}
|
|
1090
|
+
if (uniffi_editor_core_checksum_func_editor_set_json() != 18497) {
|
|
1091
|
+
return InitializationResult.apiChecksumMismatch
|
|
1092
|
+
}
|
|
1093
|
+
if (uniffi_editor_core_checksum_func_editor_set_selection() != 28236) {
|
|
1094
|
+
return InitializationResult.apiChecksumMismatch
|
|
1095
|
+
}
|
|
1096
|
+
if (uniffi_editor_core_checksum_func_editor_set_selection_scalar() != 16443) {
|
|
1097
|
+
return InitializationResult.apiChecksumMismatch
|
|
1098
|
+
}
|
|
1099
|
+
if (uniffi_editor_core_checksum_func_editor_split_block() != 52038) {
|
|
1100
|
+
return InitializationResult.apiChecksumMismatch
|
|
1101
|
+
}
|
|
1102
|
+
if (uniffi_editor_core_checksum_func_editor_split_block_scalar() != 47554) {
|
|
1103
|
+
return InitializationResult.apiChecksumMismatch
|
|
1104
|
+
}
|
|
1105
|
+
if (uniffi_editor_core_checksum_func_editor_toggle_mark() != 30661) {
|
|
1106
|
+
return InitializationResult.apiChecksumMismatch
|
|
1107
|
+
}
|
|
1108
|
+
if (uniffi_editor_core_checksum_func_editor_toggle_mark_at_selection_scalar() != 61751) {
|
|
1109
|
+
return InitializationResult.apiChecksumMismatch
|
|
1110
|
+
}
|
|
1111
|
+
if (uniffi_editor_core_checksum_func_editor_undo() != 28689) {
|
|
1112
|
+
return InitializationResult.apiChecksumMismatch
|
|
1113
|
+
}
|
|
1114
|
+
if (uniffi_editor_core_checksum_func_editor_unwrap_from_list() != 41875) {
|
|
1115
|
+
return InitializationResult.apiChecksumMismatch
|
|
1116
|
+
}
|
|
1117
|
+
if (uniffi_editor_core_checksum_func_editor_unwrap_from_list_at_selection_scalar() != 57899) {
|
|
1118
|
+
return InitializationResult.apiChecksumMismatch
|
|
1119
|
+
}
|
|
1120
|
+
if (uniffi_editor_core_checksum_func_editor_wrap_in_list() != 32846) {
|
|
1121
|
+
return InitializationResult.apiChecksumMismatch
|
|
1122
|
+
}
|
|
1123
|
+
if (uniffi_editor_core_checksum_func_editor_wrap_in_list_at_selection_scalar() != 6459) {
|
|
1124
|
+
return InitializationResult.apiChecksumMismatch
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
return InitializationResult.ok
|
|
1128
|
+
}()
|
|
1129
|
+
|
|
1130
|
+
// Make the ensure init function public so that other modules which have external type references to
|
|
1131
|
+
// our types can call it.
|
|
1132
|
+
public func uniffiEnsureEditorCoreInitialized() {
|
|
1133
|
+
switch initializationResult {
|
|
1134
|
+
case .ok:
|
|
1135
|
+
break
|
|
1136
|
+
case .contractVersionMismatch:
|
|
1137
|
+
fatalError("UniFFI contract version mismatch: try cleaning and rebuilding your project")
|
|
1138
|
+
case .apiChecksumMismatch:
|
|
1139
|
+
fatalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
// swiftlint:enable all
|