@kolosal-ai/rivet 0.1.0 → 0.2.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.
- package/README.md +4 -0
- package/dist/anchor/index.d.ts +2 -2
- package/dist/chunk-RG5ALD3X.js +306 -0
- package/dist/chunk-RG5ALD3X.js.map +1 -0
- package/dist/index.d.ts +498 -252
- package/dist/index.js +1019 -421
- package/dist/index.js.map +1 -1
- package/dist/presence/index.d.ts +19 -0
- package/dist/presence/index.js +16 -0
- package/dist/presence/index.js.map +1 -0
- package/dist/{registry-Dkk4ZKt-.d.ts → registry-t5ldbviG.d.ts} +1 -1
- package/dist/svg/index.d.ts +2 -2
- package/dist/swimlane/index.d.ts +2 -2
- package/dist/{types-B8AAJ60T.d.ts → types-CQqnm4yW.d.ts} +55 -1
- package/dist/use-node-lock-Csg9pUeC.d.ts +323 -0
- package/package.json +5 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { P as PeerRecord } from '../use-node-lock-Csg9pUeC.js';
|
|
2
|
+
export { C as CanInteractWithLocked, D as DEFAULT_PRESENCE_OPTIONS, L as LOCK_DEFAULT_REFUSED, a as LocalPresence, b as LockIntent, c as LockInteraction, d as LockRegistry, N as NodeLock, e as PEER_COLORS, f as Peer, g as PresenceOptions, h as PresenceRegistry, R as ResolvedPresenceOptions, p as peerColor, u as useNodeLock, i as useNodeLockAllows } from '../use-node-lock-Csg9pUeC.js';
|
|
3
|
+
import '../types-CQqnm4yW.js';
|
|
4
|
+
import 'react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The peers currently in the document — for participant chrome you render
|
|
8
|
+
* yourself: an avatar stack, a follow button, a "3 others editing" line.
|
|
9
|
+
*
|
|
10
|
+
* Re-renders when the **roster** changes: someone joins or leaves, is renamed,
|
|
11
|
+
* or changes what they have selected or held. It deliberately does *not*
|
|
12
|
+
* re-render on cursor frames — those arrive at pointer rate and are already
|
|
13
|
+
* painted on the canvas. If you're rendering cursors in the DOM yourself (with
|
|
14
|
+
* `presenceOptions={{ renderCursors: false }}`), read them off the frame
|
|
15
|
+
* channel instead, where the rest of the imperative chrome lives.
|
|
16
|
+
*/
|
|
17
|
+
declare function usePeers(): readonly PeerRecord[];
|
|
18
|
+
|
|
19
|
+
export { PeerRecord, usePeers };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { DEFAULT_PRESENCE_OPTIONS, LOCK_DEFAULT_REFUSED, PEER_COLORS, peerColor, useNodeLock, useNodeLockAllows } from '../chunk-RG5ALD3X.js';
|
|
2
|
+
import { useRivetContext } from '../chunk-VQYN27OK.js';
|
|
3
|
+
import { useSyncExternalStore } from 'react';
|
|
4
|
+
|
|
5
|
+
function usePeers() {
|
|
6
|
+
const { store } = useRivetContext();
|
|
7
|
+
return useSyncExternalStore(
|
|
8
|
+
store.presence.subscribe,
|
|
9
|
+
store.presence.getPeers,
|
|
10
|
+
store.presence.getPeers
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { usePeers };
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/use-peers.ts"],"names":[],"mappings":";;;;AAeO,SAAS,QAAA,GAAkC;AAChD,EAAA,MAAM,EAAE,KAAA,EAAM,GAAI,eAAA,EAAgB;AAClC,EAAA,OAAO,oBAAA;AAAA,IACL,MAAM,QAAA,CAAS,SAAA;AAAA,IACf,MAAM,QAAA,CAAS,QAAA;AAAA,IACf,MAAM,QAAA,CAAS;AAAA,GACjB;AACF","file":"index.js","sourcesContent":["import { useSyncExternalStore } from \"react\"\nimport { useRivetContext } from \"../context\"\nimport type { PeerRecord } from \"../presence/registry\"\n\n/**\n * The peers currently in the document — for participant chrome you render\n * yourself: an avatar stack, a follow button, a \"3 others editing\" line.\n *\n * Re-renders when the **roster** changes: someone joins or leaves, is renamed,\n * or changes what they have selected or held. It deliberately does *not*\n * re-render on cursor frames — those arrive at pointer rate and are already\n * painted on the canvas. If you're rendering cursors in the DOM yourself (with\n * `presenceOptions={{ renderCursors: false }}`), read them off the frame\n * channel instead, where the rest of the imperative chrome lives.\n */\nexport function usePeers(): readonly PeerRecord[] {\n const { store } = useRivetContext()\n return useSyncExternalStore(\n store.presence.subscribe,\n store.presence.getPeers,\n store.presence.getPeers,\n )\n}\n"]}
|
package/dist/svg/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { CSSProperties } from 'react';
|
|
3
|
-
import { g as AnchorStrayPolicy } from '../registry-
|
|
4
|
-
import '../types-
|
|
3
|
+
import { g as AnchorStrayPolicy } from '../registry-t5ldbviG.js';
|
|
4
|
+
import '../types-CQqnm4yW.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* The extract seam behind `<SvgArtwork>` — which elements inside a parsed
|
package/dist/swimlane/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { R as Rect, c as RivetNode, V as Vec2, S as Size,
|
|
2
|
-
export { L as LaneChange,
|
|
1
|
+
import { R as Rect, c as RivetNode, V as Vec2, S as Size, s as SwimlaneMargin, r as SwimlaneGroup } from '../types-CQqnm4yW.js';
|
|
2
|
+
export { L as LaneChange, U as Swimlane, t as SwimlaneHeaderProps, u as SwimlaneLabelProps, v as SwimlaneSizeChange } from '../types-CQqnm4yW.js';
|
|
3
3
|
import 'react';
|
|
4
4
|
|
|
5
5
|
/** World height of a group's sticky header band. */
|
|
@@ -205,6 +205,60 @@ type EdgeChange<TData = unknown> = {
|
|
|
205
205
|
id: EdgeId;
|
|
206
206
|
item: RivetEdge<TData>;
|
|
207
207
|
};
|
|
208
|
+
/**
|
|
209
|
+
* Where a change batch came from.
|
|
210
|
+
*
|
|
211
|
+
* - `"local"` — this client produced it (a gesture, a `useRivet()` call). In a
|
|
212
|
+
* multiplayer app this is the batch you send to your server.
|
|
213
|
+
* - `"remote"` — it arrived through {@link RivetStore.applyRemote}, i.e. it has
|
|
214
|
+
* already happened elsewhere. Apply it to your state, but don't send it back
|
|
215
|
+
* or the echo becomes a loop.
|
|
216
|
+
*
|
|
217
|
+
* Any other string is passed through untouched, so you can carry a peer id or a
|
|
218
|
+
* transaction id if you'd rather route on that.
|
|
219
|
+
*/
|
|
220
|
+
type ChangeOrigin = "local" | "remote" | (string & {});
|
|
221
|
+
/**
|
|
222
|
+
* Batch metadata handed to `onNodesChange`/`onEdgesChange` alongside the changes.
|
|
223
|
+
* Every change in one batch shares an origin by construction.
|
|
224
|
+
*/
|
|
225
|
+
type ChangeMeta = {
|
|
226
|
+
origin: ChangeOrigin;
|
|
227
|
+
};
|
|
228
|
+
/**
|
|
229
|
+
* A local gesture opening or closing on one or more nodes — a pointer drag, a
|
|
230
|
+
* resize, or a keyboard grab. In a shared document these are the acquire and
|
|
231
|
+
* release signals: take a lock on start, drop it on end.
|
|
232
|
+
*
|
|
233
|
+
* - `id` — the node the gesture began on (the one grabbed).
|
|
234
|
+
* - `ids` — every node moving with it, `id` included. A group drag carries the
|
|
235
|
+
* whole selection; a resize carries one node.
|
|
236
|
+
*/
|
|
237
|
+
type NodeGestureEvent = {
|
|
238
|
+
id: NodeId;
|
|
239
|
+
ids: NodeId[];
|
|
240
|
+
};
|
|
241
|
+
/**
|
|
242
|
+
* A peer's lock arrived on a node this client is already holding — the double-
|
|
243
|
+
* hold a gesture guard alone can't rule out, since two clients can start a drag
|
|
244
|
+
* before either one's lock reaches the other.
|
|
245
|
+
*
|
|
246
|
+
* rivet reports it and keeps going: the running gesture stays authoritative
|
|
247
|
+
* over its geometry, because ripping a node out from under a live pointer is a
|
|
248
|
+
* worse outcome than a late merge, and only the consumer knows whether its
|
|
249
|
+
* transport made this client the loser. Yield with
|
|
250
|
+
* {@link RivetInstance.releaseNodeGesture}.
|
|
251
|
+
*
|
|
252
|
+
* - `nodeId` — the held node the incoming lock names.
|
|
253
|
+
* - `holderId` — the peer the lock table gives it to.
|
|
254
|
+
* - `ids` — every node the local gesture is holding, `nodeId` included, so a
|
|
255
|
+
* consumer that yields can release the whole group in one call.
|
|
256
|
+
*/
|
|
257
|
+
type NodeLockConflictEvent = {
|
|
258
|
+
nodeId: NodeId;
|
|
259
|
+
holderId: string;
|
|
260
|
+
ids: NodeId[];
|
|
261
|
+
};
|
|
208
262
|
/**
|
|
209
263
|
* What a handle may be when dragging a connection:
|
|
210
264
|
* - `"source"` — can only start an edge.
|
|
@@ -512,4 +566,4 @@ type RivetControls = {
|
|
|
512
566
|
setViewport: (viewport: Viewport) => void;
|
|
513
567
|
};
|
|
514
568
|
|
|
515
|
-
export type { AlignmentGuide as A,
|
|
569
|
+
export type { AlignmentGuide as A, EdgeDrawExtras as B, Connection as C, DefaultEdgeOptions as D, EdgeChange as E, EdgeEnd as F, EdgePathFn as G, HandlePosition as H, CenterNodeOptions as I, EdgeMarker as J, EdgePath as K, LaneChange as L, EdgePathParams as M, NodeId as N, EdgeStyle as O, PendingConnection as P, FitViewOptions as Q, Rect as R, Size as S, NodeComponent as T, Swimlane as U, Vec2 as V, RivetEdge as a, NodeChange as b, RivetNode as c, NodeProps as d, NodeTypes as e, HandleType as f, ChangeOrigin as g, EdgeId as h, HandleRecord as i, ChangeMeta as j, Viewport as k, NodeGestureEvent as l, NodeLockConflictEvent as m, RivetSelection as n, ReconnectDelegate as o, EdgeTypes as p, EdgeRendererFactory as q, SwimlaneGroup as r, SwimlaneMargin as s, SwimlaneHeaderProps as t, SwimlaneLabelProps as u, SwimlaneSizeChange as v, RivetControls as w, RivetSnapshot as x, EdgeRenderer as y, EdgeRendererOptions as z };
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import { N as NodeId, V as Vec2, R as Rect } from './types-CQqnm4yW.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Locks — nodes a peer has claimed, and what this client may still do to them.
|
|
5
|
+
*
|
|
6
|
+
* A lock is policy where presence is description. `Peer.holding` says "they
|
|
7
|
+
* have their pointer on this"; a lock says "hands off", and rivet acts on it.
|
|
8
|
+
* The two render identically on purpose — to whoever is looking, they mean the
|
|
9
|
+
* same thing — but only a lock refuses anything.
|
|
10
|
+
*
|
|
11
|
+
* Locks come in whole, as the `lockedNodes` prop, because the transport already
|
|
12
|
+
* has to hold them: a lock outlives the tab that took it (that's the point of
|
|
13
|
+
* taking one), so the server owns the lifetime and rivet only reads it. Nothing
|
|
14
|
+
* here enters the graph, the change stream, or history — a lock is no more a
|
|
15
|
+
* fact about the document than a cursor is.
|
|
16
|
+
*
|
|
17
|
+
* What a lock refuses is a default, not a rule. {@link LOCK_DEFAULT_REFUSED} is
|
|
18
|
+
* rivet's opinion; `canInteractWithLocked` is the consumer's, and it wins on
|
|
19
|
+
* every intent it's asked about.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* A thing this client might try to do to a locked node.
|
|
24
|
+
*
|
|
25
|
+
* Granular because the answer genuinely differs per app: a design tool wants a
|
|
26
|
+
* locked node inspectable, a form builder wants it untouchable, and a pipeline
|
|
27
|
+
* editor usually wants to keep wiring around one while a colleague renames it.
|
|
28
|
+
*/
|
|
29
|
+
type LockIntent =
|
|
30
|
+
/** Click it, or sweep it up in a marquee. */
|
|
31
|
+
"select"
|
|
32
|
+
/** Move it — pointer drag, group drag, keyboard grab or arrow nudge. */
|
|
33
|
+
| "drag"
|
|
34
|
+
/** Change its box through {@link NodeResizer}. */
|
|
35
|
+
| "resize"
|
|
36
|
+
/** Remove it as part of deleting the selection. */
|
|
37
|
+
| "delete"
|
|
38
|
+
/** Start or land an edge on one of its handles. */
|
|
39
|
+
| "connect";
|
|
40
|
+
/** What {@link CanInteractWithLocked} is asked about. */
|
|
41
|
+
type LockInteraction = {
|
|
42
|
+
nodeId: NodeId;
|
|
43
|
+
/** The peer holding the lock — the `lockedNodes` value for this node. */
|
|
44
|
+
holderId: string;
|
|
45
|
+
intent: LockIntent;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Consumer override for rivet's default refusals, consulted once per attempt.
|
|
49
|
+
* Return `true` to allow the intent, `false` to refuse it — the default is
|
|
50
|
+
* replaced, not consulted, so a handler owns the whole policy.
|
|
51
|
+
*/
|
|
52
|
+
type CanInteractWithLocked = (event: LockInteraction) => boolean;
|
|
53
|
+
/** A node's lock as {@link useNodeLock} reports it. */
|
|
54
|
+
type NodeLock = {
|
|
55
|
+
locked: boolean;
|
|
56
|
+
/** The peer holding it, or `undefined` when the node isn't locked. */
|
|
57
|
+
holderId?: string;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* The intents rivet refuses on a locked node when no policy is given.
|
|
61
|
+
*
|
|
62
|
+
* `connect` is deliberately absent. A lock claims the node, not the graph
|
|
63
|
+
* around it: an edge is its own row with its own id, and refusing to wire one
|
|
64
|
+
* would make a locked node an island for as long as somebody holds it — a far
|
|
65
|
+
* heavier lock than "someone is editing this" warrants. Consumers who want that
|
|
66
|
+
* can say so through {@link CanInteractWithLocked}.
|
|
67
|
+
*/
|
|
68
|
+
declare const LOCK_DEFAULT_REFUSED: ReadonlySet<LockIntent>;
|
|
69
|
+
/**
|
|
70
|
+
* The lock registry — one per graph, reachable as `store.locks`.
|
|
71
|
+
*
|
|
72
|
+
* Reads are hot: every marquee frame and every mover loop asks
|
|
73
|
+
* {@link LockRegistry.allows}, so it stays a map lookup plus at most one
|
|
74
|
+
* consumer call, with no allocation on the common (nothing locked) path.
|
|
75
|
+
*/
|
|
76
|
+
type LockRegistry = {
|
|
77
|
+
/**
|
|
78
|
+
* Replace the lock table (the `lockedNodes` prop). Returns the nodes that
|
|
79
|
+
* weren't locked before and are now — the store scans those for conflicts
|
|
80
|
+
* with a live local gesture.
|
|
81
|
+
*/
|
|
82
|
+
setLocks: (locks: Record<NodeId, string> | undefined) => NodeId[];
|
|
83
|
+
/** Install the consumer's policy, or `null` to fall back to the defaults. */
|
|
84
|
+
setPolicy: (policy: CanInteractWithLocked | null) => void;
|
|
85
|
+
isLocked: (id: NodeId) => boolean;
|
|
86
|
+
/** Who holds this node's lock, or `null` when it isn't locked. */
|
|
87
|
+
getHolder: (id: NodeId) => string | null;
|
|
88
|
+
/** The whole table. The renderer walks it once a frame. */
|
|
89
|
+
getLocks: () => ReadonlyMap<NodeId, string>;
|
|
90
|
+
/** How many nodes are locked — the render loop's early-out. */
|
|
91
|
+
size: () => number;
|
|
92
|
+
/**
|
|
93
|
+
* Whether this client may act on a node. Always `true` for an unlocked node,
|
|
94
|
+
* so callers can ask unconditionally.
|
|
95
|
+
*/
|
|
96
|
+
allows: (id: NodeId, intent: LockIntent) => boolean;
|
|
97
|
+
/** Bumped on every table change, for `useSyncExternalStore`. */
|
|
98
|
+
getVersion: () => number;
|
|
99
|
+
/** Subscribe to the table changing — locks move at human rate, so this is React-safe. */
|
|
100
|
+
subscribe: (listener: () => void) => () => void;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Presence — who else is in the document, and where they are.
|
|
105
|
+
*
|
|
106
|
+
* Presence is ephemeral by construction. Nothing here enters the graph, the
|
|
107
|
+
* change stream, or history: a peer's cursor is not a fact about the document,
|
|
108
|
+
* it's a fact about a person, and it stops being true the moment they move. So
|
|
109
|
+
* the registry is imperative, painted straight from the render loop, and thrown
|
|
110
|
+
* away when the tab closes.
|
|
111
|
+
*
|
|
112
|
+
* Two doors write to it, at deliberately different speeds:
|
|
113
|
+
*
|
|
114
|
+
* - the `peers` prop — the roster. Identity (name, colour) and the slow
|
|
115
|
+
* fields (selection, holding). React-rate.
|
|
116
|
+
* - {@link PresenceRegistry.setPeerCursor} / `setPeerNodeTransform` — the hot
|
|
117
|
+
* path off your ephemeral channel, called as fast as frames arrive. These
|
|
118
|
+
* never touch React: they mark the canvas dirty and nothing else.
|
|
119
|
+
*
|
|
120
|
+
* A peer the roster has never mentioned is still legitimate — a cursor frame
|
|
121
|
+
* can beat the join event, and dropping it would blink the cursor. Such a peer
|
|
122
|
+
* lives until its cursor clears (see {@link PresenceRegistry.setPeerCursor}),
|
|
123
|
+
* and its colour is derived from its id, so the record can be rebuilt any
|
|
124
|
+
* number of times without the colour ever flickering.
|
|
125
|
+
*/
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* A participant other than this client, as your transport describes them.
|
|
129
|
+
*
|
|
130
|
+
* Everything is optional but `id`: presence degrades field by field, and a peer
|
|
131
|
+
* you know nothing about except that they exist is still worth an avatar.
|
|
132
|
+
*/
|
|
133
|
+
type Peer = {
|
|
134
|
+
id: string;
|
|
135
|
+
/** Display name, drawn beside their cursor. Unnamed peers get no label. */
|
|
136
|
+
name?: string;
|
|
137
|
+
/** Any CSS colour. Defaults to a stable colour derived from {@link Peer.id}. */
|
|
138
|
+
color?: string;
|
|
139
|
+
/**
|
|
140
|
+
* Cursor in **world** coordinates — peers pan and zoom independently, so a
|
|
141
|
+
* screen point means nothing to anyone else. `null` when their pointer is
|
|
142
|
+
* off the canvas. Only a seed: once {@link PresenceRegistry.setPeerCursor}
|
|
143
|
+
* has been called for a peer, the imperative value owns the cursor.
|
|
144
|
+
*/
|
|
145
|
+
cursor?: Vec2 | null;
|
|
146
|
+
/** Nodes they have selected. Outlined in their colour. */
|
|
147
|
+
selection?: NodeId[];
|
|
148
|
+
/** Nodes under one of their live gestures (their `onNodeDragStart`). */
|
|
149
|
+
holding?: NodeId[];
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* A peer as the registry holds it: identity resolved, live overlays merged in.
|
|
153
|
+
* What the renderer and {@link usePeers} both read.
|
|
154
|
+
*/
|
|
155
|
+
type PeerRecord = {
|
|
156
|
+
id: string;
|
|
157
|
+
name?: string;
|
|
158
|
+
/** Always set — {@link peerColor} fills in for a peer that declared none. */
|
|
159
|
+
color: string;
|
|
160
|
+
cursor: Vec2 | null;
|
|
161
|
+
selection: readonly NodeId[];
|
|
162
|
+
holding: readonly NodeId[];
|
|
163
|
+
/**
|
|
164
|
+
* Where this peer currently has each node they're dragging, in world space —
|
|
165
|
+
* the frame-rate overlay from `setPeerNodeTransform`. The node renders there
|
|
166
|
+
* until they let go; the graph keeps its own position until their commit
|
|
167
|
+
* arrives as a real change.
|
|
168
|
+
*/
|
|
169
|
+
transforms: ReadonlyMap<NodeId, Rect>;
|
|
170
|
+
};
|
|
171
|
+
/** Presence policy, set via the `presenceOptions` prop. */
|
|
172
|
+
type PresenceOptions = {
|
|
173
|
+
/**
|
|
174
|
+
* Smallest gap between outbound `onLocalPresence` snapshots, in ms. Cursor
|
|
175
|
+
* movement is coalesced to this rate; selection and gesture changes ignore it
|
|
176
|
+
* and go out at once (a lock signal that waits is a lock signal that races).
|
|
177
|
+
* Default `50`.
|
|
178
|
+
*/
|
|
179
|
+
throttleMs?: number;
|
|
180
|
+
/**
|
|
181
|
+
* Paint peer cursors on the canvas. Turn off to render your own from
|
|
182
|
+
* {@link usePeers} — avatars, follow buttons, anything the canvas can't do.
|
|
183
|
+
* Node outlines and peers' live boxes are unaffected. Default `true`.
|
|
184
|
+
*/
|
|
185
|
+
renderCursors?: boolean;
|
|
186
|
+
};
|
|
187
|
+
type ResolvedPresenceOptions = Required<PresenceOptions>;
|
|
188
|
+
declare const DEFAULT_PRESENCE_OPTIONS: ResolvedPresenceOptions;
|
|
189
|
+
/**
|
|
190
|
+
* Default peer colours. Spaced around the wheel and mid-toned, so they read on
|
|
191
|
+
* a light or dark canvas and stay distinguishable side by side.
|
|
192
|
+
*/
|
|
193
|
+
declare const PEER_COLORS: readonly ["#6366f1", "#ec4899", "#f59e0b", "#10b981", "#3b82f6", "#8b5cf6", "#ef4444", "#14b8a6"];
|
|
194
|
+
/**
|
|
195
|
+
* A stable colour for a peer id. Deterministic, so the same person is the same
|
|
196
|
+
* colour on every client and across a record being pruned and rebuilt — nobody
|
|
197
|
+
* coordinates a palette, and nobody's cursor changes colour mid-session.
|
|
198
|
+
*/
|
|
199
|
+
declare function peerColor(id: string): string;
|
|
200
|
+
/**
|
|
201
|
+
* The presence registry — one per graph, reachable as `store.presence`.
|
|
202
|
+
*
|
|
203
|
+
* Reads are snapshot-based: {@link getPeers} returns a cached array rebuilt
|
|
204
|
+
* only when something actually changed, so the render loop can call it every
|
|
205
|
+
* frame and `useSyncExternalStore` can compare identities.
|
|
206
|
+
*/
|
|
207
|
+
type PresenceRegistry = {
|
|
208
|
+
/**
|
|
209
|
+
* Replace the roster (the `peers` prop). Peers that were in the previous
|
|
210
|
+
* roster and aren't in this one are dropped outright — leaving the roster is
|
|
211
|
+
* how a peer leaves. Peers this registry only knows imperatively are kept.
|
|
212
|
+
*/
|
|
213
|
+
setPeers: (peers: Peer[]) => void;
|
|
214
|
+
/**
|
|
215
|
+
* Move a peer's cursor, in world coordinates. The hot path: call it as fast
|
|
216
|
+
* as your channel delivers frames.
|
|
217
|
+
*
|
|
218
|
+
* `null` parks the cursor. For a peer the roster never declared, that leaves
|
|
219
|
+
* nothing to draw, so the record is dropped — the next frame recreates it
|
|
220
|
+
* with the same colour.
|
|
221
|
+
*/
|
|
222
|
+
setPeerCursor: (peerId: string, point: Vec2 | null) => void;
|
|
223
|
+
/**
|
|
224
|
+
* Where a peer currently has a node, in world space — their drag, mid-flight.
|
|
225
|
+
* The node itself moves there: it's painted, hit-tested and wired at the peer's
|
|
226
|
+
* live box, while the graph underneath is untouched until their commit lands.
|
|
227
|
+
* `null` releases it, which is what their drop should do just before their
|
|
228
|
+
* real change arrives.
|
|
229
|
+
*/
|
|
230
|
+
setPeerNodeTransform: (peerId: string, nodeId: NodeId, rect: Rect | null) => void;
|
|
231
|
+
/**
|
|
232
|
+
* Every node a peer currently has under a gesture, at its *rendered* position
|
|
233
|
+
* — the interpolated one, not the last frame that arrived. What the store
|
|
234
|
+
* folds into world positions.
|
|
235
|
+
*/
|
|
236
|
+
getNodeTransforms: () => ReadonlyMap<NodeId, Rect>;
|
|
237
|
+
/**
|
|
238
|
+
* Bumped whenever a rendered transform moves. Lets the store cache world
|
|
239
|
+
* positions across frames where peers are idle.
|
|
240
|
+
*/
|
|
241
|
+
getTransformVersion: () => number;
|
|
242
|
+
/**
|
|
243
|
+
* Advance the interpolation toward the values that arrived, and report
|
|
244
|
+
* whether anything is still in motion (i.e. whether another frame is owed).
|
|
245
|
+
*
|
|
246
|
+
* Frames arrive at whatever rate a transport manages — 20Hz is normal, and
|
|
247
|
+
* stepping straight to each one makes a cursor stutter and a dragged node
|
|
248
|
+
* jump. Easing between them costs one lerp per peer and buys motion that
|
|
249
|
+
* reads as somebody moving rather than as packets landing.
|
|
250
|
+
*/
|
|
251
|
+
step: (now: number) => boolean;
|
|
252
|
+
/** Forget a peer entirely — cursor, held nodes and all. Use it when they disconnect. */
|
|
253
|
+
removePeer: (peerId: string) => void;
|
|
254
|
+
/** Every known peer. A cached snapshot; identity only changes when the data does. */
|
|
255
|
+
getPeers: () => readonly PeerRecord[];
|
|
256
|
+
/** True when nobody else is here — the render loop's early-out. */
|
|
257
|
+
isEmpty: () => boolean;
|
|
258
|
+
/**
|
|
259
|
+
* Subscribe to **roster** changes: peers arriving or leaving, and their
|
|
260
|
+
* identity, selection or holding changing. Cursor and transform frames
|
|
261
|
+
* deliberately don't notify — they'd re-render React at pointer rate, and
|
|
262
|
+
* they're already painted on the canvas. Read them from {@link getPeers} on
|
|
263
|
+
* the frame channel if you need them in the DOM.
|
|
264
|
+
*/
|
|
265
|
+
subscribe: (listener: () => void) => () => void;
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* The outbound half of presence: what this client tells everyone else.
|
|
270
|
+
*
|
|
271
|
+
* It publishes a *snapshot*, never an event stream. A snapshot is idempotent —
|
|
272
|
+
* a dropped one costs nothing, a duplicate costs nothing, and a client that
|
|
273
|
+
* reconnects mid-session is immediately correct rather than replaying history.
|
|
274
|
+
* That's also how presence channels themselves model state, so this maps onto
|
|
275
|
+
* any transport without a translation layer.
|
|
276
|
+
*
|
|
277
|
+
* Cursor movement is coalesced to `throttleMs`; selection and gesture changes
|
|
278
|
+
* jump the queue, because they're the signals a peer acts on (a lock request
|
|
279
|
+
* that waits 50ms is a lock request that can lose a race it should have won).
|
|
280
|
+
*/
|
|
281
|
+
|
|
282
|
+
/** This client's presence, as handed to `onLocalPresence`. */
|
|
283
|
+
type LocalPresence = {
|
|
284
|
+
/**
|
|
285
|
+
* Pointer position in **world** coordinates, or `null` when the pointer is
|
|
286
|
+
* off the canvas. World, not screen: peers have their own viewports, and a
|
|
287
|
+
* screen point means nothing on the other side.
|
|
288
|
+
*/
|
|
289
|
+
cursor: Vec2 | null;
|
|
290
|
+
/** Currently selected node ids. */
|
|
291
|
+
selection: NodeId[];
|
|
292
|
+
/** Nodes under a live local gesture — the same set as `onNodeDragStart`. */
|
|
293
|
+
holding: NodeId[];
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Whether a node is locked, and by whom — for the chrome rivet can't draw for
|
|
298
|
+
* you: a padlock in the node's header, a "Ada is editing" line, a disabled
|
|
299
|
+
* form inside the node body.
|
|
300
|
+
*
|
|
301
|
+
* rivet already refuses the interactions it owns (see the `lockedNodes` prop),
|
|
302
|
+
* so this is for *your* controls. Re-renders only when this node changes hands,
|
|
303
|
+
* not when any lock in the document moves.
|
|
304
|
+
*
|
|
305
|
+
* ```tsx
|
|
306
|
+
* function MyNode({ id }: NodeProps) {
|
|
307
|
+
* const { locked, holderId } = useNodeLock(id)
|
|
308
|
+
* return <input disabled={locked} title={locked ? `${holderId} is editing` : ""} />
|
|
309
|
+
* }
|
|
310
|
+
* ```
|
|
311
|
+
*/
|
|
312
|
+
declare function useNodeLock(id: NodeId): NodeLock;
|
|
313
|
+
/**
|
|
314
|
+
* Whether this client may do `intent` to a node right now — the same question
|
|
315
|
+
* every rivet input path asks, answered through the same policy.
|
|
316
|
+
*
|
|
317
|
+
* Use it to keep your own affordances honest: hide a delete button on a node a
|
|
318
|
+
* peer has locked, rather than letting it be pressed and refused. Always `true`
|
|
319
|
+
* for an unlocked node.
|
|
320
|
+
*/
|
|
321
|
+
declare function useNodeLockAllows(id: NodeId, intent: LockIntent): boolean;
|
|
322
|
+
|
|
323
|
+
export { type CanInteractWithLocked as C, DEFAULT_PRESENCE_OPTIONS as D, LOCK_DEFAULT_REFUSED as L, type NodeLock as N, type PeerRecord as P, type ResolvedPresenceOptions as R, type LocalPresence as a, type LockIntent as b, type LockInteraction as c, type LockRegistry as d, PEER_COLORS as e, type Peer as f, type PresenceOptions as g, type PresenceRegistry as h, useNodeLockAllows as i, peerColor as p, useNodeLock as u };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kolosal-ai/rivet",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Canvas-rendered node graph for React: DOM nodes, Canvas2D edges, swimlanes, anchors, undo/redo",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -31,6 +31,10 @@
|
|
|
31
31
|
"types": "./dist/anchor/index.d.ts",
|
|
32
32
|
"import": "./dist/anchor/index.js"
|
|
33
33
|
},
|
|
34
|
+
"./presence": {
|
|
35
|
+
"types": "./dist/presence/index.d.ts",
|
|
36
|
+
"import": "./dist/presence/index.js"
|
|
37
|
+
},
|
|
34
38
|
"./svg": {
|
|
35
39
|
"types": "./dist/svg/index.d.ts",
|
|
36
40
|
"import": "./dist/svg/index.js"
|