diff --git a/packages/crdt-loro/src/loro.ts b/packages/crdt-loro/src/loro.ts index a9e534cd..6b42e3a1 100644 --- a/packages/crdt-loro/src/loro.ts +++ b/packages/crdt-loro/src/loro.ts @@ -1,7 +1,9 @@ export { CrdtLoroDoc, doc } from "./doc"; export { list } from "./list"; export { map } from "./map"; +export { movableList } from "./movableList"; export { object } from "./object"; export { text } from "./text"; +export { tree } from "./tree"; export type { LoroType } from "./types"; export const kind = "loro" as const; diff --git a/packages/crdt-loro/src/movableList.ts b/packages/crdt-loro/src/movableList.ts new file mode 100644 index 00000000..becd2cd2 --- /dev/null +++ b/packages/crdt-loro/src/movableList.ts @@ -0,0 +1,13 @@ +import type { Container } from "loro-crdt"; +import { isContainer, LoroMovableList } from "loro-crdt"; +import type { LoroType } from "./types"; + +export const movableList = (value: T[] | readonly T[] = []) => { + const container = new LoroMovableList(); + + value.forEach((item, i) => { + isContainer(item) ? container.insertContainer(i, item) : container.insert(i, item as Exclude); + }); + + return container as unknown as LoroType, T[]>; +}; diff --git a/packages/crdt-loro/src/tree.ts b/packages/crdt-loro/src/tree.ts new file mode 100644 index 00000000..156447cc --- /dev/null +++ b/packages/crdt-loro/src/tree.ts @@ -0,0 +1,7 @@ +import { LoroTree } from "loro-crdt"; + +export const tree = >() => { + const container = new LoroTree(); + + return container; +};