@voltro/local-first 0.52.0 → 0.54.0

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.
@@ -5,7 +5,7 @@ property of its respective copyright holders and is used under the terms of
5
5
  its license. This file is provided for attribution; it grants no rights in
6
6
  @voltro/local-first itself, which is proprietary (see LICENSE).
7
7
 
8
- Generated from the resolved runtime dependency closure (3 packages).
8
+ Generated from the resolved runtime dependency closure (4 packages).
9
9
 
10
10
  ---
11
11
 
@@ -65,6 +65,34 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
65
65
  SOFTWARE.
66
66
  ```
67
67
 
68
+ ## y-protocols@1.0.7
69
+
70
+ License: MIT
71
+
72
+ ```
73
+ The MIT License (MIT)
74
+
75
+ Copyright (c) 2019 Kevin Jahns <kevin.jahns@protonmail.com>.
76
+
77
+ Permission is hereby granted, free of charge, to any person obtaining a copy
78
+ of this software and associated documentation files (the "Software"), to deal
79
+ in the Software without restriction, including without limitation the rights
80
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
81
+ copies of the Software, and to permit persons to whom the Software is
82
+ furnished to do so, subject to the following conditions:
83
+
84
+ The above copyright notice and this permission notice shall be included in all
85
+ copies or substantial portions of the Software.
86
+
87
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
88
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
89
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
90
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
91
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
92
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
93
+ SOFTWARE.
94
+ ```
95
+
68
96
  ## yjs@13.6.32
69
97
 
70
98
  License: MIT
@@ -0,0 +1,125 @@
1
+ import * as awarenessProtocol from 'y-protocols/awareness';
2
+ import { Editor } from '@tiptap/react';
3
+
4
+ /**
5
+ * Bridge ONE client's awareness onto the latest-event transport. Outbound:
6
+ * every local change publishes ONLY this client's encoded state — the
7
+ * per-member payload budget that keeps a multi-range selection far inside
8
+ * the 7 500-byte event envelope cap (never the aggregated room). Inbound:
9
+ * received updates apply as remote states. Returns the detach, which also
10
+ * removes this client's state so peers see the caret leave.
11
+ */
12
+ export declare const attachAwarenessBridge: (instance: awarenessProtocol.Awareness, transport: AwarenessTransport) => (() => void);
13
+
14
+ export declare interface AwarenessTransport {
15
+ /** Publish THIS client's encoded awareness update (a small Uint8Array —
16
+ * one member's caret/selection). Bind to a `delivery: 'latest'` event
17
+ * publish; fire-and-forget. */
18
+ readonly send: (update: Uint8Array) => void;
19
+ /** Subscribe to OTHER clients' awareness updates. Returns unsubscribe. */
20
+ readonly onReceive: (handler: (update: Uint8Array) => void) => () => void;
21
+ }
22
+
23
+ /**
24
+ * A CRDT implementation. One per library. The default is {@link yjsBackend}.
25
+ *
26
+ * `merge` and `decodeText` are STATELESS with respect to any live handle: they
27
+ * operate purely on encoded bytes, which is what lets the sync layer and tests
28
+ * converge two states without holding a document open.
29
+ */
30
+ /**
31
+ * A live, mutable CRDT DOCUMENT — the whole-doc generalisation `crdtDoc()`
32
+ * stores (rich text, maps, arrays; whatever the backend's document model
33
+ * holds). `crdtText()` remains the single-field specialisation over the same
34
+ * backend.
35
+ */
36
+ declare interface CrdtDocHandle {
37
+ /**
38
+ * The underlying library document (a `Y.Doc` for the yjs backend), typed
39
+ * opaquely: an EDITOR BINDING needs the real object (Tiptap's Collaboration
40
+ * extension takes a Y.Doc), while every sync-layer consumer only moves
41
+ * encoded bytes and must never reach in. Cast at the binding, nowhere else.
42
+ */
43
+ readonly raw: unknown;
44
+ /** Full state, encoded for transport or merge. */
45
+ encodeState: () => CrdtState;
46
+ /** This doc's state VECTOR — the compact "what I have" summary a peer
47
+ * diffs against. */
48
+ stateVector: () => Uint8Array;
49
+ /**
50
+ * Encode only what a peer holding `sinceVector` is missing — the
51
+ * INCREMENTAL update lane. A 1-character edit against a 100 KB doc encodes
52
+ * to a few dozen bytes, not the full state.
53
+ */
54
+ encodeUpdateSince: (sinceVector: Uint8Array) => CrdtState;
55
+ /** Fold an encoded state or incremental update into this doc, in place. */
56
+ applyState: (state: CrdtState) => void;
57
+ /**
58
+ * Subscribe to update blobs this doc produces. Returns the unsubscribe.
59
+ *
60
+ * `local` distinguishes an edit made HERE from one produced by folding a
61
+ * remote state through `applyState`, and it is the difference between a
62
+ * working push loop and an echo: without it, applying a peer's update fires
63
+ * this handler, the app pushes it back, and every client re-broadcasts what
64
+ * it just received. Measured with three tabs open: one keystroke produced
65
+ * three server writes instead of one. It converges — the merge is
66
+ * idempotent — but the amplification scales with the session.
67
+ *
68
+ * It had to come from the BACKEND rather than an `applying` flag around
69
+ * `applyState` in app code: that flag is only correct while the backend emits
70
+ * synchronously, which `CrdtBackend` deliberately does not promise ("the
71
+ * backend decision lives behind our abstraction so it can change").
72
+ */
73
+ onUpdate: (handler: (update: CrdtState, meta: {
74
+ readonly local: boolean;
75
+ }) => void) => () => void;
76
+ /**
77
+ * Encode a stable ANCHOR at `index` of the named text field — a position
78
+ * that survives concurrent edits (the primitive an inline-comment UI pins
79
+ * threads with; the UI itself is the comments plugin's business).
80
+ */
81
+ encodeAnchor: (field: string, index: number) => Uint8Array;
82
+ /** Resolve an anchor back to its current index, or `undefined` when the
83
+ * anchored region was deleted. */
84
+ resolveAnchor: (encoded: Uint8Array) => number | undefined;
85
+ }
86
+
87
+ /**
88
+ * An encoded CRDT state or delta, as opaque bytes. Produced by
89
+ * {@link CrdtBackend.encodeState} / {@link CrdtTextHandle.encodeState},
90
+ * consumed by {@link CrdtBackend.merge} and {@link CrdtBackend.decodeText}.
91
+ *
92
+ * It is opaque ON PURPOSE: the shape is the backend's business. Yjs emits a
93
+ * v1 update blob; Loro would emit its own. Consumers only ever move these
94
+ * bytes around and hand them back.
95
+ */
96
+ declare type CrdtState = Uint8Array;
97
+
98
+ /**
99
+ * A collaborative rich-text editor over a `crdtDoc()` column. Content edits
100
+ * mutate the shared Y.Doc (push them through the app's mutation via
101
+ * `doc.onUpdate`; remote deltas arrive through the subscription fold) —
102
+ * this hook owns only the EDITOR lifecycle: one Tiptap instance bound to the
103
+ * doc, carets bridged over the injected latest-event transport, everything
104
+ * destroyed with the component.
105
+ */
106
+ export declare const useCrdtEditor: (options: UseCrdtEditorOptions) => Editor | null;
107
+
108
+ export declare interface UseCrdtEditorOptions {
109
+ /** The document handle (from `createDoc` / the sync layer) — its `raw`
110
+ * Y.Doc is what Tiptap's Collaboration extension binds. */
111
+ readonly doc: CrdtDocHandle;
112
+ /** This user's caret identity. */
113
+ readonly user?: {
114
+ readonly name: string;
115
+ readonly color: string;
116
+ };
117
+ /** Caret transport (the `delivery: 'latest'` event pair). Omit for a
118
+ * single-user editor — the caret extension is then not mounted. */
119
+ readonly awareness?: AwarenessTransport;
120
+ /** Extra Tiptap extensions (tables, mentions, …). */
121
+ readonly extensions?: ReadonlyArray<unknown>;
122
+ readonly editable?: boolean;
123
+ }
124
+
125
+ export { }
package/dist/editor.js ADDED
@@ -0,0 +1,53 @@
1
+ import { useEffect as e, useMemo as t, useRef as n, useState as r } from "react";
2
+ import { Editor as i } from "@tiptap/react";
3
+ import a from "@tiptap/starter-kit";
4
+ import o from "@tiptap/extension-collaboration";
5
+ import { CollaborationCaret as s } from "@tiptap/extension-collaboration-caret";
6
+ import * as c from "y-protocols/awareness";
7
+ //#region src/editor/useCrdtEditor.ts
8
+ var l = (l) => {
9
+ let { doc: d, user: f, awareness: p, editable: m = !0 } = l, h = n(null), g = t(() => p === void 0 ? null : new c.Awareness(d.raw), [p, d]);
10
+ e(() => {
11
+ if (g !== null && p !== void 0) return u(g, p);
12
+ }, [g, p]);
13
+ let _ = n(l.extensions);
14
+ _.current = l.extensions;
15
+ let [v, y] = r(null);
16
+ return e(() => {
17
+ let e = [
18
+ a.configure({ undoRedo: !1 }),
19
+ o.configure({ document: d.raw }),
20
+ ...g === null ? [] : [s.configure({
21
+ provider: { awareness: g },
22
+ ...f === void 0 ? {} : { user: f }
23
+ })],
24
+ ..._.current ?? []
25
+ ], t = new i({
26
+ extensions: e,
27
+ editable: m
28
+ });
29
+ return h.current = t, y(t), () => {
30
+ t.destroy(), h.current === t && (h.current = null), y((e) => e === t ? null : e);
31
+ };
32
+ }, [
33
+ d,
34
+ g,
35
+ f,
36
+ m
37
+ ]), e(() => () => {
38
+ g?.destroy();
39
+ }, [g]), v;
40
+ }, u = (e, t) => {
41
+ let n = e.clientID, r = (r, i) => {
42
+ i !== "remote" && t.send(c.encodeAwarenessUpdate(e, [n]));
43
+ };
44
+ e.on("update", r);
45
+ let i = t.onReceive((t) => {
46
+ c.applyAwarenessUpdate(e, t, "remote");
47
+ });
48
+ return () => {
49
+ c.removeAwarenessStates(e, [n], "detach"), e.off("update", r), i();
50
+ };
51
+ };
52
+ //#endregion
53
+ export { u as attachAwarenessBridge, l as useCrdtEditor };