|
| 1 | +import type { |
| 2 | + AutomergeUrl, |
| 3 | + Doc, |
| 4 | + DocHandle, |
| 5 | + DocHandleChangePayload, |
| 6 | + Repo, |
| 7 | +} from "@automerge/automerge-repo/slim" |
| 8 | +import type {MaybeAccessor} from "@solid-primitives/utils" |
| 9 | +import type {Context} from "solid-js" |
| 10 | +import type {Resource} from "solid-js" |
| 11 | +import type {Accessor} from "solid-js" |
| 12 | + |
| 13 | +/** |
| 14 | + * convert automerge patches to solid producer operations |
| 15 | + * @param payload the |
| 16 | + * [DocHandleChangePayload](https://automerge.org/automerge-repo/interfaces/_automerge_automerge_repo.DocHandleChangePayload.html) |
| 17 | + * from the handle.on("change |
| 18 | + * @returns a callback for an immer-like function. e.g. |
| 19 | + * [produce](https://docs.solidjs.com/reference/store-utilities/produce) for |
| 20 | + * [Solid |
| 21 | + * Stores](https://docs.solidjs.com/reference/store-utilities/create-store) |
| 22 | + */ |
| 23 | +export default function autoproduce<T>( |
| 24 | + payload: DocHandleChangePayload<T> |
| 25 | +): (doc: T) => void |
| 26 | +/** |
| 27 | + * a [context](https://docs.solidjs.com/concepts/context) that provides access |
| 28 | + * to an Automerge Repo. you don't need this, you can pass the repo in the |
| 29 | + * second arg to the functions that need it. |
| 30 | + */ |
| 31 | +export declare const RepoContext: Context<Repo | null> |
| 32 | + |
| 33 | +/** |
| 34 | + * get a fine-grained live view of a document from a handle. works with |
| 35 | + * {@link useDocHandle}. |
| 36 | + * @param handle an accessor (signal/resource) of a |
| 37 | + * [DocHandle](https://automerge.org/automerge-repo/classes/_automerge_automerge_repo.DocHandle.html) |
| 38 | + */ |
| 39 | +export default function createDocumentProjection<T>( |
| 40 | + handle: Accessor<DocHandle<T> | undefined> |
| 41 | +): Accessor<Doc<T> | undefined> |
| 42 | + |
| 43 | +export interface UseDocHandleOptions { |
| 44 | + repo?: Repo |
| 45 | + "~skipInitialValue"?: boolean |
| 46 | +} |
| 47 | +/** |
| 48 | + * get a |
| 49 | + * [DocHandle](https://automerge.org/automerge-repo/classes/_automerge_automerge_repo.DocHandle.html) |
| 50 | + * from an |
| 51 | + * [AutomergeUrl](https://automerge.org/automerge-repo/types/_automerge_automerge_repo.AutomergeUrl.html) |
| 52 | + * as a |
| 53 | + * [Resource](https://docs.solidjs.com/reference/basic-reactivity/create-resource). |
| 54 | + * Waits for the handle to be |
| 55 | + * [ready](https://automerge.org/automerge-repo/variables/_automerge_automerge_repo.HandleState-1.html). |
| 56 | + */ |
| 57 | +export default function useDocHandle<T>( |
| 58 | + url: MaybeAccessor<AutomergeUrl | undefined>, |
| 59 | + options?: UseDocHandleOptions |
| 60 | +): Resource<DocHandle<T> | undefined> |
| 61 | +/** |
| 62 | + * get a fine-grained live view of a document, and its handle, from a URL. |
| 63 | + * @param url a function that returns a url |
| 64 | + */ |
| 65 | +export default function useDocument<T>( |
| 66 | + url: MaybeAccessor<AutomergeUrl | undefined>, |
| 67 | + options?: UseDocHandleOptions |
| 68 | +): [Accessor<Doc<T> | undefined>, Resource<DocHandle<T> | undefined>] |
| 69 | +/** grab the repo from the {@link RepoContext} */ |
| 70 | +export default function useRepo(): Repo |
0 commit comments