automerge / automerge-swift

Swift language bindings presenting Automerge

Home Page:https://automerge.org/automerge-swift/documentation/automerge/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

expose Blocks API to Swift

heckj opened this issue · comments

The core API:

  • split_block
  • join_block
  • update_block
  • spans
  • updateSpans

For docs (Rust) ref: automerge/automerge@806ef43

The rust commit that added most of the core: automerge/automerge@1d987cd
The commit that exposed through to WASM: automerge/automerge@5068143
The commit that exposed through to JavaScript: automerge/automerge@e7b090a

The blocks API should allow us to provide mapping from some common JavaScript-based rich-text editors through to Swift's AttributedString type.

Digging through existing tests, code, etc -

Looks like the types to expose from Rust over into swift include BlockOrText - an enum that holds either the block structure or a string value (from automerge/tests/block_tests.rs)

The map inside block has:

  • String(type) => String
  • String(parents) => [String]
  • String(attrs) => [String:?? something - ScalarValue? ints?]
    • For the attrs map, the example in the test showed a key of a string and a value of an int

A lot of those parts are using functions: hydrate_map, hydrate_list, hydrate_text that may be useful to expose and leverage, haven't read through them all yet.

The exposed WASM tests illustrate potentially more of how this might be better exposed:

UniFFI exposes a Hashmap as a default type (https://mozilla.github.io/uniffi-rs/udl/builtin_types.html), which it looks like we'll need to use for some of this API which accepts (and returns) maps. the hydrate.rs module features prominently in the api, and it's Value type (enum) has cases for List and Map in addition to Object and ScalarValue. We may want/need to expand that in the Automerge-swift Value type - or accomodate that in some form (a different type to avoid futzing with existing API?) to accomodate the more complex structures in spans and blocks