@pylonsync/loro 0.22.44 → 0.22.47

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pylonsync/loro",
3
- "version": "0.22.44",
3
+ "version": "0.22.47",
4
4
  "description": "Pylon's local-first React layer — wraps loro-crdt with a registry, useLoroDoc hook, and the binary WS wire-format decoder that mirrors crates/router/encode_crdt_frame.",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -16,14 +16,15 @@
16
16
  "./prosemirror/react": "./src/prosemirror/react.ts",
17
17
  "./prosemirror/sync": "./src/prosemirror/sync.ts",
18
18
  "./server": "./src/server.ts",
19
- "./prosemirror/cursors": "./src/prosemirror/cursors.ts"
19
+ "./prosemirror/cursors": "./src/prosemirror/cursors.ts",
20
+ "./prosemirror/ranges": "./src/prosemirror/ranges.ts"
20
21
  },
21
22
  "scripts": {
22
23
  "check": "tsc -p tsconfig.json --noEmit"
23
24
  },
24
25
  "dependencies": {
25
- "@pylonsync/react": "0.22.44",
26
- "@pylonsync/sync": "0.22.44",
26
+ "@pylonsync/react": "0.22.47",
27
+ "@pylonsync/sync": "0.22.47",
27
28
  "loro-crdt": "^1.10.6"
28
29
  },
29
30
  "peerDependencies": {
@@ -48,6 +48,20 @@ export interface ProseMirrorCursorsPluginProps {
48
48
 
49
49
  export const proseMirrorCursorsKey = new PluginKey<RemoteCursor[]>("pylonRemoteCursors");
50
50
 
51
+ /** A Loro cursor as text (base64), to store or send. */
52
+ export function encodeCursor(cursor: Cursor): string {
53
+ return toBase64(cursor.encode());
54
+ }
55
+
56
+ /** A cursor from {@link encodeCursor}, or null when the text is not one. */
57
+ export function decodeCursor(text: string): Cursor | null {
58
+ try {
59
+ return Cursor.decode(fromBase64(text));
60
+ } catch {
61
+ return null;
62
+ }
63
+ }
64
+
51
65
  function toBase64(bytes: Uint8Array): string {
52
66
  let s = "";
53
67
  for (const b of bytes) s += String.fromCharCode(b);