Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose Blocks API to Swift #156

Open
heckj opened this issue May 1, 2024 · 2 comments
Open

expose Blocks API to Swift #156

heckj opened this issue May 1, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@heckj
Copy link
Collaborator

heckj commented May 1, 2024

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.

@heckj heckj added the enhancement New feature or request label May 1, 2024
@heckj
Copy link
Collaborator Author

heckj commented May 16, 2024

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:

@heckj
Copy link
Collaborator Author

heckj commented May 16, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant