@kolosal-ai/rivet 0.1.1 → 0.3.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-A52HZWLH.js +314 -0
- package/dist/chunk-A52HZWLH.js.map +1 -0
- package/dist/index.d.ts +503 -255
- package/dist/index.js +1330 -680
- package/dist/index.js.map +1 -1
- package/dist/presence/index.d.ts +108 -0
- package/dist/presence/index.js +38 -0
- package/dist/presence/index.js.map +1 -0
- package/dist/{registry-Dkk4ZKt-.d.ts → registry-CCBgd7FN.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-C9Vn1rzy.d.ts} +55 -1
- package/dist/use-node-lock-DH0dB1yA.d.ts +327 -0
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -36,6 +36,10 @@ export function App() {
|
|
|
36
36
|
node, measured live (`@kolosal-ai/rivet/anchor`).
|
|
37
37
|
- **SVG artwork nodes** — parse and render SVG inside nodes, with anchors on
|
|
38
38
|
elements inside the artwork (`@kolosal-ai/rivet/svg`).
|
|
39
|
+
- **Multiplayer seams** — origin-tagged change batches with `applyRemote`, local
|
|
40
|
+
gestures that own their geometry, presence (peer cursors, selections and the
|
|
41
|
+
nodes they're moving), and locks that refuse local interaction on a node a peer has
|
|
42
|
+
claimed (`@kolosal-ai/rivet/presence`).
|
|
39
43
|
- **Pluggable edge renderer** — swap the Canvas2D backend through the
|
|
40
44
|
`renderer` prop (`EdgeRendererFactory`).
|
|
41
45
|
- **Keyboard + ARIA** — roving node focus, grab-to-move, keyboard connect, live
|
package/dist/anchor/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CSSProperties, ReactNode } from 'react';
|
|
2
|
-
export { A as ANCHOR_SIDES, a as AnchorGeometry, b as AnchorOptions, c as AnchorPoint, d as AnchorRecord, e as AnchorRegistration, f as AnchorRegistrationOptions, g as AnchorStrayPolicy, D as DEFAULT_ANCHOR_OPTIONS, R as ResolvedAnchorOptions, h as anchorAutoHandleId, i as anchorDotHandleId, j as anchorHandleId, k as computeAnchorGeometry, n as normalizeAnchorConnection, p as parseAnchorAutoHandleId, l as parseAnchorDotHandleId, m as parseAnchorHandleId, s as strayPlacementPct } from '../registry-
|
|
3
|
-
import '../types-
|
|
2
|
+
export { A as ANCHOR_SIDES, a as AnchorGeometry, b as AnchorOptions, c as AnchorPoint, d as AnchorRecord, e as AnchorRegistration, f as AnchorRegistrationOptions, g as AnchorStrayPolicy, D as DEFAULT_ANCHOR_OPTIONS, R as ResolvedAnchorOptions, h as anchorAutoHandleId, i as anchorDotHandleId, j as anchorHandleId, k as computeAnchorGeometry, n as normalizeAnchorConnection, p as parseAnchorAutoHandleId, l as parseAnchorDotHandleId, m as parseAnchorHandleId, s as strayPlacementPct } from '../registry-CCBgd7FN.js';
|
|
3
|
+
import '../types-C9Vn1rzy.js';
|
|
4
4
|
|
|
5
5
|
type AnchorProps = {
|
|
6
6
|
/**
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { useRivetContext } from './chunk-VQYN27OK.js';
|
|
2
|
+
import { useCallback, useSyncExternalStore } from 'react';
|
|
3
|
+
|
|
4
|
+
// src/locks/registry.ts
|
|
5
|
+
var LOCK_DEFAULT_REFUSED = /* @__PURE__ */ new Set([
|
|
6
|
+
"select",
|
|
7
|
+
"drag",
|
|
8
|
+
"resize",
|
|
9
|
+
"delete"
|
|
10
|
+
]);
|
|
11
|
+
function locksEqual(current, next) {
|
|
12
|
+
const keys = Object.keys(next);
|
|
13
|
+
if (keys.length !== current.size) return false;
|
|
14
|
+
return keys.every((id) => current.get(id) === next[id]);
|
|
15
|
+
}
|
|
16
|
+
var Registry = class {
|
|
17
|
+
/** Marks the canvas dirty — a lock is paint as well as policy. */
|
|
18
|
+
constructor(requestRender) {
|
|
19
|
+
this.requestRender = requestRender;
|
|
20
|
+
}
|
|
21
|
+
requestRender;
|
|
22
|
+
locks = /* @__PURE__ */ new Map();
|
|
23
|
+
policy = null;
|
|
24
|
+
version = 0;
|
|
25
|
+
listeners = /* @__PURE__ */ new Set();
|
|
26
|
+
setLocks = (locks) => {
|
|
27
|
+
const next = locks ?? {};
|
|
28
|
+
if (locksEqual(this.locks, next)) return [];
|
|
29
|
+
const opened = [];
|
|
30
|
+
for (const [id, holderId] of Object.entries(next)) {
|
|
31
|
+
if (this.locks.get(id) !== holderId) opened.push(id);
|
|
32
|
+
}
|
|
33
|
+
this.locks = new Map(Object.entries(next));
|
|
34
|
+
this.version += 1;
|
|
35
|
+
this.requestRender();
|
|
36
|
+
for (const listener of this.listeners) listener();
|
|
37
|
+
return opened;
|
|
38
|
+
};
|
|
39
|
+
setPolicy = (policy) => {
|
|
40
|
+
this.policy = policy;
|
|
41
|
+
};
|
|
42
|
+
isLocked = (id) => this.locks.has(id);
|
|
43
|
+
getHolder = (id) => this.locks.get(id) ?? null;
|
|
44
|
+
getLocks = () => this.locks;
|
|
45
|
+
size = () => this.locks.size;
|
|
46
|
+
allows = (id, intent) => {
|
|
47
|
+
if (this.locks.size === 0) return true;
|
|
48
|
+
const holderId = this.locks.get(id);
|
|
49
|
+
if (holderId === void 0) return true;
|
|
50
|
+
if (this.policy) return this.policy({ nodeId: id, holderId, intent });
|
|
51
|
+
return !LOCK_DEFAULT_REFUSED.has(intent);
|
|
52
|
+
};
|
|
53
|
+
getVersion = () => this.version;
|
|
54
|
+
subscribe = (listener) => {
|
|
55
|
+
this.listeners.add(listener);
|
|
56
|
+
return () => {
|
|
57
|
+
this.listeners.delete(listener);
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
function createLockRegistry(requestRender) {
|
|
62
|
+
return new Registry(requestRender);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// src/presence/registry.ts
|
|
66
|
+
var DEFAULT_PRESENCE_OPTIONS = {
|
|
67
|
+
throttleMs: 50,
|
|
68
|
+
renderCursors: true
|
|
69
|
+
};
|
|
70
|
+
var PEER_COLORS = [
|
|
71
|
+
"#6366f1",
|
|
72
|
+
"#ec4899",
|
|
73
|
+
"#f59e0b",
|
|
74
|
+
"#10b981",
|
|
75
|
+
"#3b82f6",
|
|
76
|
+
"#8b5cf6",
|
|
77
|
+
"#ef4444",
|
|
78
|
+
"#14b8a6"
|
|
79
|
+
];
|
|
80
|
+
function peerColor(id) {
|
|
81
|
+
let hash = 0;
|
|
82
|
+
for (let i = 0; i < id.length; i += 1) hash = hash * 31 + id.charCodeAt(i) | 0;
|
|
83
|
+
const index = (hash % PEER_COLORS.length + PEER_COLORS.length) % PEER_COLORS.length;
|
|
84
|
+
return PEER_COLORS[index] ?? PEER_COLORS[0];
|
|
85
|
+
}
|
|
86
|
+
var SMOOTHING_MS = 45;
|
|
87
|
+
var NOMINAL_FRAME_MS = 16;
|
|
88
|
+
var SETTLED_EPSILON = 0.05;
|
|
89
|
+
function approach(from, to, t) {
|
|
90
|
+
const next = from + (to - from) * t;
|
|
91
|
+
return Math.abs(to - next) < SETTLED_EPSILON ? to : next;
|
|
92
|
+
}
|
|
93
|
+
var EMPTY_IDS = [];
|
|
94
|
+
var samePoint = (a, b) => a === b || a != null && b != null && a.x === b.x && a.y === b.y;
|
|
95
|
+
var sameRect = (a, b) => a !== void 0 && a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
|
|
96
|
+
var sameIds = (a, b) => {
|
|
97
|
+
const left = a ?? EMPTY_IDS;
|
|
98
|
+
const right = b ?? EMPTY_IDS;
|
|
99
|
+
return left.length === right.length && left.every((id, i) => id === right[i]);
|
|
100
|
+
};
|
|
101
|
+
function declarationEqual(a, b) {
|
|
102
|
+
if (a === b) return true;
|
|
103
|
+
if (!a || !b) return false;
|
|
104
|
+
return a.name === b.name && a.color === b.color && samePoint(a.cursor, b.cursor) && sameIds(a.selection, b.selection) && sameIds(a.holding, b.holding);
|
|
105
|
+
}
|
|
106
|
+
var Registry2 = class {
|
|
107
|
+
/** Called on every change, roster or hot-path — something has to repaint either way. */
|
|
108
|
+
constructor(requests) {
|
|
109
|
+
this.requests = requests;
|
|
110
|
+
}
|
|
111
|
+
requests;
|
|
112
|
+
peers = /* @__PURE__ */ new Map();
|
|
113
|
+
listeners = /* @__PURE__ */ new Set();
|
|
114
|
+
snapshot = [];
|
|
115
|
+
stale = false;
|
|
116
|
+
/** Merged rendered transforms across peers, rebuilt when {@link version} moves. */
|
|
117
|
+
transforms = /* @__PURE__ */ new Map();
|
|
118
|
+
transformsStale = false;
|
|
119
|
+
version = 0;
|
|
120
|
+
/** Timestamp of the last {@link step}, so the ease is frame-rate independent. */
|
|
121
|
+
lastStep = -1;
|
|
122
|
+
touch() {
|
|
123
|
+
this.stale = true;
|
|
124
|
+
this.requests.requestRender();
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* A change only the cursor layer can see. Same snapshot invalidation, but the
|
|
128
|
+
* frame it asks for repaints one canvas instead of all of them.
|
|
129
|
+
*/
|
|
130
|
+
touchCursor() {
|
|
131
|
+
this.stale = true;
|
|
132
|
+
this.requests.requestCursorRender();
|
|
133
|
+
}
|
|
134
|
+
/** A change React needs to know about, as well as the canvas. */
|
|
135
|
+
touchRoster() {
|
|
136
|
+
this.touch();
|
|
137
|
+
for (const listener of this.listeners) listener();
|
|
138
|
+
}
|
|
139
|
+
peer(id) {
|
|
140
|
+
let state = this.peers.get(id);
|
|
141
|
+
if (!state) {
|
|
142
|
+
state = {
|
|
143
|
+
id,
|
|
144
|
+
declared: null,
|
|
145
|
+
live: void 0,
|
|
146
|
+
renderCursor: null,
|
|
147
|
+
transforms: /* @__PURE__ */ new Map(),
|
|
148
|
+
renderTransforms: /* @__PURE__ */ new Map()
|
|
149
|
+
};
|
|
150
|
+
this.peers.set(id, state);
|
|
151
|
+
}
|
|
152
|
+
return state;
|
|
153
|
+
}
|
|
154
|
+
/** Drop a peer the roster doesn't claim and that has nothing left to draw. */
|
|
155
|
+
prune(state) {
|
|
156
|
+
if (state.declared || state.live || state.transforms.size > 0) return;
|
|
157
|
+
this.peers.delete(state.id);
|
|
158
|
+
this.invalidateTransforms();
|
|
159
|
+
}
|
|
160
|
+
invalidateTransforms() {
|
|
161
|
+
this.transformsStale = true;
|
|
162
|
+
this.version += 1;
|
|
163
|
+
}
|
|
164
|
+
setPeers = (peers) => {
|
|
165
|
+
let changed = false;
|
|
166
|
+
const incoming = /* @__PURE__ */ new Set();
|
|
167
|
+
for (const peer of peers) {
|
|
168
|
+
incoming.add(peer.id);
|
|
169
|
+
const state = this.peer(peer.id);
|
|
170
|
+
if (declarationEqual(state.declared, peer)) continue;
|
|
171
|
+
state.declared = peer;
|
|
172
|
+
changed = true;
|
|
173
|
+
}
|
|
174
|
+
for (const state of [...this.peers.values()]) {
|
|
175
|
+
if (incoming.has(state.id)) continue;
|
|
176
|
+
if (!state.declared) continue;
|
|
177
|
+
this.peers.delete(state.id);
|
|
178
|
+
changed = true;
|
|
179
|
+
}
|
|
180
|
+
if (changed) this.touchRoster();
|
|
181
|
+
};
|
|
182
|
+
setPeerCursor = (peerId, point) => {
|
|
183
|
+
const state = this.peer(peerId);
|
|
184
|
+
if (state.live !== void 0 && samePoint(state.live, point)) return;
|
|
185
|
+
state.live = point;
|
|
186
|
+
if (point === null) this.prune(state);
|
|
187
|
+
this.touchCursor();
|
|
188
|
+
};
|
|
189
|
+
setPeerNodeTransform = (peerId, nodeId, rect) => {
|
|
190
|
+
const state = this.peer(peerId);
|
|
191
|
+
if (rect === null) {
|
|
192
|
+
const had = state.transforms.delete(nodeId);
|
|
193
|
+
state.renderTransforms.delete(nodeId);
|
|
194
|
+
this.prune(state);
|
|
195
|
+
if (!had) return;
|
|
196
|
+
this.invalidateTransforms();
|
|
197
|
+
this.touch();
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
if (sameRect(state.transforms.get(nodeId), rect)) return;
|
|
201
|
+
state.transforms.set(nodeId, rect);
|
|
202
|
+
if (!state.renderTransforms.has(nodeId)) {
|
|
203
|
+
state.renderTransforms.set(nodeId, rect);
|
|
204
|
+
this.invalidateTransforms();
|
|
205
|
+
}
|
|
206
|
+
this.touch();
|
|
207
|
+
};
|
|
208
|
+
removePeer = (peerId) => {
|
|
209
|
+
if (!this.peers.delete(peerId)) return;
|
|
210
|
+
this.invalidateTransforms();
|
|
211
|
+
this.touchRoster();
|
|
212
|
+
};
|
|
213
|
+
getNodeTransforms = () => {
|
|
214
|
+
if (this.transformsStale) {
|
|
215
|
+
this.transformsStale = false;
|
|
216
|
+
this.transforms = /* @__PURE__ */ new Map();
|
|
217
|
+
for (const state of this.peers.values()) {
|
|
218
|
+
for (const [nodeId, rect] of state.renderTransforms) this.transforms.set(nodeId, rect);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return this.transforms;
|
|
222
|
+
};
|
|
223
|
+
getTransformVersion = () => this.version;
|
|
224
|
+
step = (now) => {
|
|
225
|
+
const elapsed = this.lastStep < 0 ? NOMINAL_FRAME_MS : Math.max(0, now - this.lastStep);
|
|
226
|
+
this.lastStep = now;
|
|
227
|
+
const t = 1 - Math.exp(-elapsed / SMOOTHING_MS);
|
|
228
|
+
let moving = false;
|
|
229
|
+
let transformsMoved = false;
|
|
230
|
+
for (const state of this.peers.values()) {
|
|
231
|
+
const target = state.live !== void 0 ? state.live : state.declared?.cursor ?? null;
|
|
232
|
+
if (target === null) {
|
|
233
|
+
state.renderCursor = null;
|
|
234
|
+
} else if (!state.renderCursor) {
|
|
235
|
+
state.renderCursor = target;
|
|
236
|
+
} else if (!samePoint(state.renderCursor, target)) {
|
|
237
|
+
state.renderCursor = {
|
|
238
|
+
x: approach(state.renderCursor.x, target.x, t),
|
|
239
|
+
y: approach(state.renderCursor.y, target.y, t)
|
|
240
|
+
};
|
|
241
|
+
moving = true;
|
|
242
|
+
}
|
|
243
|
+
for (const [nodeId, rect] of state.transforms) {
|
|
244
|
+
const current = state.renderTransforms.get(nodeId);
|
|
245
|
+
if (!current) {
|
|
246
|
+
state.renderTransforms.set(nodeId, rect);
|
|
247
|
+
transformsMoved = true;
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
if (sameRect(current, rect)) continue;
|
|
251
|
+
state.renderTransforms.set(nodeId, {
|
|
252
|
+
x: approach(current.x, rect.x, t),
|
|
253
|
+
y: approach(current.y, rect.y, t),
|
|
254
|
+
// Size comes from a resize rather than a drag and rarely differs
|
|
255
|
+
// frame to frame, but easing it keeps a live resize as smooth.
|
|
256
|
+
width: approach(current.width, rect.width, t),
|
|
257
|
+
height: approach(current.height, rect.height, t)
|
|
258
|
+
});
|
|
259
|
+
transformsMoved = true;
|
|
260
|
+
moving = true;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
if (transformsMoved) this.invalidateTransforms();
|
|
264
|
+
if (moving) this.stale = true;
|
|
265
|
+
return moving;
|
|
266
|
+
};
|
|
267
|
+
getPeers = () => {
|
|
268
|
+
if (this.stale) {
|
|
269
|
+
this.stale = false;
|
|
270
|
+
this.snapshot = [...this.peers.values()].map((state) => {
|
|
271
|
+
const declared = state.declared;
|
|
272
|
+
const target = (state.live !== void 0 ? state.live : declared?.cursor) ?? null;
|
|
273
|
+
return {
|
|
274
|
+
id: state.id,
|
|
275
|
+
name: declared?.name,
|
|
276
|
+
color: declared?.color ?? peerColor(state.id),
|
|
277
|
+
// Rendered, not raw: what {@link step} has eased to. Falls back to the
|
|
278
|
+
// target so a registry nobody steps still paints something sensible.
|
|
279
|
+
cursor: target === null ? null : state.renderCursor ?? target,
|
|
280
|
+
selection: declared?.selection ?? EMPTY_IDS,
|
|
281
|
+
holding: declared?.holding ?? EMPTY_IDS,
|
|
282
|
+
transforms: state.renderTransforms
|
|
283
|
+
};
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
return this.snapshot;
|
|
287
|
+
};
|
|
288
|
+
isEmpty = () => this.peers.size === 0;
|
|
289
|
+
subscribe = (listener) => {
|
|
290
|
+
this.listeners.add(listener);
|
|
291
|
+
return () => {
|
|
292
|
+
this.listeners.delete(listener);
|
|
293
|
+
};
|
|
294
|
+
};
|
|
295
|
+
};
|
|
296
|
+
function createPresenceRegistry(requests) {
|
|
297
|
+
return new Registry2(requests);
|
|
298
|
+
}
|
|
299
|
+
var UNLOCKED = { locked: false };
|
|
300
|
+
function useNodeLock(id) {
|
|
301
|
+
const { store } = useRivetContext();
|
|
302
|
+
const getHolder = useCallback(() => store.locks.getHolder(id), [store, id]);
|
|
303
|
+
const holderId = useSyncExternalStore(store.locks.subscribe, getHolder, getHolder);
|
|
304
|
+
return holderId === null ? UNLOCKED : { locked: true, holderId };
|
|
305
|
+
}
|
|
306
|
+
function useNodeLockAllows(id, intent) {
|
|
307
|
+
const { store } = useRivetContext();
|
|
308
|
+
const allows = useCallback(() => store.locks.allows(id, intent), [store, id, intent]);
|
|
309
|
+
return useSyncExternalStore(store.locks.subscribe, allows, allows);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export { DEFAULT_PRESENCE_OPTIONS, LOCK_DEFAULT_REFUSED, PEER_COLORS, createLockRegistry, createPresenceRegistry, peerColor, useNodeLock, useNodeLockAllows };
|
|
313
|
+
//# sourceMappingURL=chunk-A52HZWLH.js.map
|
|
314
|
+
//# sourceMappingURL=chunk-A52HZWLH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/locks/registry.ts","../src/presence/registry.ts","../src/hooks/use-node-lock.ts"],"names":["Registry"],"mappings":";;;;AAuEO,IAAM,oBAAA,uBAAoD,GAAA,CAAgB;AAAA,EAC/E,QAAA;AAAA,EACA,MAAA;AAAA,EACA,QAAA;AAAA,EACA;AACF,CAAC;AAqCD,SAAS,UAAA,CAAW,SAAsC,IAAA,EAAuC;AAC/F,EAAA,MAAM,IAAA,GAAO,MAAA,CAAO,IAAA,CAAK,IAAI,CAAA;AAC7B,EAAA,IAAI,IAAA,CAAK,MAAA,KAAW,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,QAAA,KAAuC;AAClD,IAAA,IAAA,CAAK,SAAA,CAAU,IAAI,QAAQ,CAAA;AAC3B,IAAA,OAAO,MAAM;AACX,MAAA,IAAA,CAAK,SAAA,CAAU,OAAO,QAAQ,CAAA;AAAA,IAChC,CAAA;AAAA,EACF,CAAA;AACF,CAAA;AAcO,SAAS,uBAAuB,QAAA,EAAoD;AACzF,EAAA,OAAO,IAAIA,UAAS,QAAQ,CAAA;AAC9B;ACreA,IAAM,QAAA,GAAqB,EAAE,MAAA,EAAQ,KAAA,EAAM;AAkBpC,SAAS,YAAY,EAAA,EAAsB;AAChD,EAAA,MAAM,EAAE,KAAA,EAAM,GAAI,eAAA,EAAgB;AAClC,EAAA,MAAM,SAAA,GAAY,WAAA,CAAY,MAAM,KAAA,CAAM,KAAA,CAAM,SAAA,CAAU,EAAE,CAAA,EAAG,CAAC,KAAA,EAAO,EAAE,CAAC,CAAA;AAI1E,EAAA,MAAM,WAAW,oBAAA,CAAqB,KAAA,CAAM,KAAA,CAAM,SAAA,EAAW,WAAW,SAAS,CAAA;AACjF,EAAA,OAAO,aAAa,IAAA,GAAO,QAAA,GAAW,EAAE,MAAA,EAAQ,MAAM,QAAA,EAAS;AACjE;AAUO,SAAS,iBAAA,CAAkB,IAAY,MAAA,EAA6B;AACzE,EAAA,MAAM,EAAE,KAAA,EAAM,GAAI,eAAA,EAAgB;AAClC,EAAA,MAAM,MAAA,GAAS,WAAA,CAAY,MAAM,KAAA,CAAM,KAAA,CAAM,MAAA,CAAO,EAAA,EAAI,MAAM,CAAA,EAAG,CAAC,KAAA,EAAO,EAAA,EAAI,MAAM,CAAC,CAAA;AACpF,EAAA,OAAO,oBAAA,CAAqB,KAAA,CAAM,KAAA,CAAM,SAAA,EAAW,QAAQ,MAAM,CAAA;AACnE","file":"chunk-A52HZWLH.js","sourcesContent":["/**\n * Locks — nodes a peer has claimed, and what this client may still do to them.\n *\n * A lock is policy where presence is description. `Peer.holding` says \"they\n * have their pointer on this\"; a lock says \"hands off\", and rivet acts on it.\n * The two render identically on purpose — to whoever is looking, they mean the\n * same thing — but only a lock refuses anything.\n *\n * Locks come in whole, as the `lockedNodes` prop, because the transport already\n * has to hold them: a lock outlives the tab that took it (that's the point of\n * taking one), so the server owns the lifetime and rivet only reads it. Nothing\n * here enters the graph, the change stream, or history — a lock is no more a\n * fact about the document than a cursor is.\n *\n * What a lock refuses is a default, not a rule. {@link LOCK_DEFAULT_REFUSED} is\n * rivet's opinion; `canInteractWithLocked` is the consumer's, and it wins on\n * every intent it's asked about.\n */\n\nimport type { NodeId } from \"../types\"\n\n/**\n * A thing this client might try to do to a locked node.\n *\n * Granular because the answer genuinely differs per app: a design tool wants a\n * locked node inspectable, a form builder wants it untouchable, and a pipeline\n * editor usually wants to keep wiring around one while a colleague renames it.\n */\nexport type LockIntent =\n /** Click it, or sweep it up in a marquee. */\n | \"select\"\n /** Move it — pointer drag, group drag, keyboard grab or arrow nudge. */\n | \"drag\"\n /** Change its box through {@link NodeResizer}. */\n | \"resize\"\n /** Remove it as part of deleting the selection. */\n | \"delete\"\n /** Start or land an edge on one of its handles. */\n | \"connect\"\n\n/** What {@link CanInteractWithLocked} is asked about. */\nexport type LockInteraction = {\n nodeId: NodeId\n /** The peer holding the lock — the `lockedNodes` value for this node. */\n holderId: string\n intent: LockIntent\n}\n\n/**\n * Consumer override for rivet's default refusals, consulted once per attempt.\n * Return `true` to allow the intent, `false` to refuse it — the default is\n * replaced, not consulted, so a handler owns the whole policy.\n */\nexport type CanInteractWithLocked = (event: LockInteraction) => boolean\n\n/** A node's lock as {@link useNodeLock} reports it. */\nexport type NodeLock = {\n locked: boolean\n /** The peer holding it, or `undefined` when the node isn't locked. */\n holderId?: string\n}\n\n/**\n * The intents rivet refuses on a locked node when no policy is given.\n *\n * `connect` is deliberately absent. A lock claims the node, not the graph\n * around it: an edge is its own row with its own id, and refusing to wire one\n * would make a locked node an island for as long as somebody holds it — a far\n * heavier lock than \"someone is editing this\" warrants. Consumers who want that\n * can say so through {@link CanInteractWithLocked}.\n */\nexport const LOCK_DEFAULT_REFUSED: ReadonlySet<LockIntent> = new Set<LockIntent>([\n \"select\",\n \"drag\",\n \"resize\",\n \"delete\",\n])\n\n/**\n * The lock registry — one per graph, reachable as `store.locks`.\n *\n * Reads are hot: every marquee frame and every mover loop asks\n * {@link LockRegistry.allows}, so it stays a map lookup plus at most one\n * consumer call, with no allocation on the common (nothing locked) path.\n */\nexport type LockRegistry = {\n /**\n * Replace the lock table (the `lockedNodes` prop). Returns the nodes that\n * weren't locked before and are now — the store scans those for conflicts\n * with a live local gesture.\n */\n setLocks: (locks: Record<NodeId, string> | undefined) => NodeId[]\n /** Install the consumer's policy, or `null` to fall back to the defaults. */\n setPolicy: (policy: CanInteractWithLocked | null) => void\n isLocked: (id: NodeId) => boolean\n /** Who holds this node's lock, or `null` when it isn't locked. */\n getHolder: (id: NodeId) => string | null\n /** The whole table. The renderer walks it once a frame. */\n getLocks: () => ReadonlyMap<NodeId, string>\n /** How many nodes are locked — the render loop's early-out. */\n size: () => number\n /**\n * Whether this client may act on a node. Always `true` for an unlocked node,\n * so callers can ask unconditionally.\n */\n allows: (id: NodeId, intent: LockIntent) => boolean\n /** Bumped on every table change, for `useSyncExternalStore`. */\n getVersion: () => number\n /** Subscribe to the table changing — locks move at human rate, so this is React-safe. */\n subscribe: (listener: () => void) => () => void\n}\n\n/** Whether two lock tables hold the same node→holder pairs. */\nfunction locksEqual(current: ReadonlyMap<NodeId, string>, next: Record<NodeId, string>): boolean {\n const keys = Object.keys(next)\n if (keys.length !== current.size) return false\n return keys.every((id) => current.get(id) === next[id])\n}\n\nclass Registry implements LockRegistry {\n private locks = new Map<NodeId, string>()\n private policy: CanInteractWithLocked | null = null\n private version = 0\n private readonly listeners = new Set<() => void>()\n\n /** Marks the canvas dirty — a lock is paint as well as policy. */\n constructor(private readonly requestRender: () => void) {}\n\n setLocks = (locks: Record<NodeId, string> | undefined): NodeId[] => {\n const next = locks ?? {}\n // An unchanged table is the common case (any prop change re-runs the\n // effect), and re-publishing it would re-fire every conflict.\n if (locksEqual(this.locks, next)) return []\n const opened: NodeId[] = []\n for (const [id, holderId] of Object.entries(next)) {\n if (this.locks.get(id) !== holderId) opened.push(id)\n }\n this.locks = new Map(Object.entries(next))\n this.version += 1\n this.requestRender()\n for (const listener of this.listeners) listener()\n return opened\n }\n\n setPolicy = (policy: CanInteractWithLocked | null): void => {\n this.policy = policy\n }\n\n isLocked = (id: NodeId): boolean => this.locks.has(id)\n\n getHolder = (id: NodeId): string | null => this.locks.get(id) ?? null\n\n getLocks = (): ReadonlyMap<NodeId, string> => this.locks\n\n size = (): number => this.locks.size\n\n allows = (id: NodeId, intent: LockIntent): boolean => {\n // Fast path: nothing locked at all, which is every single-player frame.\n if (this.locks.size === 0) return true\n const holderId = this.locks.get(id)\n if (holderId === undefined) return true\n if (this.policy) return this.policy({ nodeId: id, holderId, intent })\n return !LOCK_DEFAULT_REFUSED.has(intent)\n }\n\n getVersion = (): number => this.version\n\n subscribe = (listener: () => void): (() => void) => {\n this.listeners.add(listener)\n return () => {\n this.listeners.delete(listener)\n }\n }\n}\n\n/** Create a lock registry. `requestRender` repaints the holder outlines. */\nexport function createLockRegistry(requestRender: () => void): LockRegistry {\n return new Registry(requestRender)\n}\n","/**\n * Presence — who else is in the document, and where they are.\n *\n * Presence is ephemeral by construction. Nothing here enters the graph, the\n * change stream, or history: a peer's cursor is not a fact about the document,\n * it's a fact about a person, and it stops being true the moment they move. So\n * the registry is imperative, painted straight from the render loop, and thrown\n * away when the tab closes.\n *\n * Two doors write to it, at deliberately different speeds:\n *\n * - the `peers` prop — the roster. Identity (name, colour) and the slow\n * fields (selection, holding). React-rate.\n * - {@link PresenceRegistry.setPeerCursor} / `setPeerNodeTransform` — the hot\n * path off your ephemeral channel, called as fast as frames arrive. These\n * never touch React: they mark the canvas dirty and nothing else. A cursor\n * dirties only the cursor layer; a transform moves a real node, so it\n * dirties the frame.\n *\n * A peer the roster has never mentioned is still legitimate — a cursor frame\n * can beat the join event, and dropping it would blink the cursor. Such a peer\n * lives until its cursor clears (see {@link PresenceRegistry.setPeerCursor}),\n * and its colour is derived from its id, so the record can be rebuilt any\n * number of times without the colour ever flickering.\n */\n\nimport type { NodeId, Rect, Vec2 } from \"../types\"\n\n/**\n * A participant other than this client, as your transport describes them.\n *\n * Everything is optional but `id`: presence degrades field by field, and a peer\n * you know nothing about except that they exist is still worth an avatar.\n */\nexport type Peer = {\n id: string\n /** Display name, drawn beside their cursor. Unnamed peers get no label. */\n name?: string\n /** Any CSS colour. Defaults to a stable colour derived from {@link Peer.id}. */\n color?: string\n /**\n * Cursor in **world** coordinates — peers pan and zoom independently, so a\n * screen point means nothing to anyone else. `null` when their pointer is\n * off the canvas. Only a seed: once {@link PresenceRegistry.setPeerCursor}\n * has been called for a peer, the imperative value owns the cursor.\n */\n cursor?: Vec2 | null\n /** Nodes they have selected. Outlined in their colour. */\n selection?: NodeId[]\n /** Nodes under one of their live gestures (their `onNodeDragStart`). */\n holding?: NodeId[]\n}\n\n/**\n * A peer as the registry holds it: identity resolved, live overlays merged in.\n * What the renderer and {@link usePeers} both read.\n */\nexport type PeerRecord = {\n id: string\n name?: string\n /** Always set — {@link peerColor} fills in for a peer that declared none. */\n color: string\n cursor: Vec2 | null\n selection: readonly NodeId[]\n holding: readonly NodeId[]\n /**\n * Where this peer currently has each node they're dragging, in world space —\n * the frame-rate overlay from `setPeerNodeTransform`. The node renders there\n * until they let go; the graph keeps its own position until their commit\n * arrives as a real change.\n */\n transforms: ReadonlyMap<NodeId, Rect>\n}\n\n/** Presence policy, set via the `presenceOptions` prop. */\nexport type PresenceOptions = {\n /**\n * Smallest gap between outbound `onLocalPresence` snapshots, in ms. Cursor\n * movement is coalesced to this rate; selection and gesture changes ignore it\n * and go out at once (a lock signal that waits is a lock signal that races).\n * Default `50`.\n */\n throttleMs?: number\n /**\n * Give peer cursors their own canvas layer. Turn off to render your own from\n * {@link usePeers} — avatars, follow buttons, anything the canvas can't do —\n * and the layer is never created at all. Node outlines and peers' live boxes\n * are unaffected: they live with the geometry they annotate. Default `true`.\n */\n renderCursors?: boolean\n}\n\nexport type ResolvedPresenceOptions = Required<PresenceOptions>\n\nexport const DEFAULT_PRESENCE_OPTIONS: ResolvedPresenceOptions = {\n throttleMs: 50,\n renderCursors: true,\n}\n\n/**\n * Default peer colours. Spaced around the wheel and mid-toned, so they read on\n * a light or dark canvas and stay distinguishable side by side.\n */\nexport const PEER_COLORS = [\n \"#6366f1\",\n \"#ec4899\",\n \"#f59e0b\",\n \"#10b981\",\n \"#3b82f6\",\n \"#8b5cf6\",\n \"#ef4444\",\n \"#14b8a6\",\n] as const\n\n/**\n * A stable colour for a peer id. Deterministic, so the same person is the same\n * colour on every client and across a record being pruned and rebuilt — nobody\n * coordinates a palette, and nobody's cursor changes colour mid-session.\n */\nexport function peerColor(id: string): string {\n let hash = 0\n for (let i = 0; i < id.length; i += 1) hash = (hash * 31 + id.charCodeAt(i)) | 0\n // Modulo of a negative hash is negative; normalize before indexing.\n const index = ((hash % PEER_COLORS.length) + PEER_COLORS.length) % PEER_COLORS.length\n return PEER_COLORS[index] ?? PEER_COLORS[0]\n}\n\n/**\n * The presence registry — one per graph, reachable as `store.presence`.\n *\n * Reads are snapshot-based: {@link getPeers} returns a cached array rebuilt\n * only when something actually changed, so the render loop can call it every\n * frame and `useSyncExternalStore` can compare identities.\n */\nexport type PresenceRegistry = {\n /**\n * Replace the roster (the `peers` prop). Peers that were in the previous\n * roster and aren't in this one are dropped outright — leaving the roster is\n * how a peer leaves. Peers this registry only knows imperatively are kept.\n */\n setPeers: (peers: Peer[]) => void\n /**\n * Move a peer's cursor, in world coordinates. The hot path: call it as fast\n * as your channel delivers frames — it dirties the cursor layer and nothing\n * else, so the cost doesn't scale into the rest of the canvas.\n *\n * `null` parks the cursor. For a peer the roster never declared, that leaves\n * nothing to draw, so the record is dropped — the next frame recreates it\n * with the same colour.\n */\n setPeerCursor: (peerId: string, point: Vec2 | null) => void\n /**\n * Where a peer currently has a node, in world space — their drag, mid-flight.\n * The node itself moves there: it's painted, hit-tested and wired at the peer's\n * live box, while the graph underneath is untouched until their commit lands.\n * `null` releases it, which is what their drop should do just before their\n * real change arrives.\n */\n setPeerNodeTransform: (peerId: string, nodeId: NodeId, rect: Rect | null) => void\n /**\n * Every node a peer currently has under a gesture, at its *rendered* position\n * — the interpolated one, not the last frame that arrived. What the store\n * folds into world positions.\n */\n getNodeTransforms: () => ReadonlyMap<NodeId, Rect>\n /**\n * Bumped whenever a rendered transform moves. Lets the store cache world\n * positions across frames where peers are idle.\n */\n getTransformVersion: () => number\n /**\n * Advance the interpolation toward the values that arrived, and report\n * whether anything is still in motion (i.e. whether another frame is owed).\n *\n * Frames arrive at whatever rate a transport manages — 20Hz is normal, and\n * stepping straight to each one makes a cursor stutter and a dragged node\n * jump. Easing between them costs one lerp per peer and buys motion that\n * reads as somebody moving rather than as packets landing.\n */\n step: (now: number) => boolean\n /** Forget a peer entirely — cursor, held nodes and all. Use it when they disconnect. */\n removePeer: (peerId: string) => void\n /** Every known peer. A cached snapshot; identity only changes when the data does. */\n getPeers: () => readonly PeerRecord[]\n /** True when nobody else is here — the render loop's early-out. */\n isEmpty: () => boolean\n /**\n * Subscribe to **roster** changes: peers arriving or leaving, and their\n * identity, selection or holding changing. Cursor and transform frames\n * deliberately don't notify — they'd re-render React at pointer rate, and\n * they're already painted on the canvas. Read them from {@link getPeers} on\n * the frame channel if you need them in the DOM.\n */\n subscribe: (listener: () => void) => () => void\n}\n\n/** Internal peer state: what the roster declared, plus the imperative overlays. */\ntype PeerState = {\n id: string\n /** The roster's entry, or null for a peer only known through cursor frames. */\n declared: Peer | null\n /** `undefined` until an imperative write; after that it owns the cursor. */\n live: Vec2 | null | undefined\n /** Where the cursor is being drawn, easing toward {@link live}. */\n renderCursor: Vec2 | null\n /** Latest frame per node — the target the rendered box is easing toward. */\n transforms: Map<NodeId, Rect>\n /** Where each box is actually drawn this frame. */\n renderTransforms: Map<NodeId, Rect>\n}\n\n/**\n * Time constant for peer interpolation, in ms: the gap to the target closes by\n * ~63% every `SMOOTHING_MS`. Short enough that a cursor never trails visibly\n * behind the frames arriving, long enough to absorb a 20Hz channel.\n */\nconst SMOOTHING_MS = 45\n/** Assumed frame length for the very first step, which has no interval to measure. */\nconst NOMINAL_FRAME_MS = 16\n/** Below this (px, world or screen) the ease is over and the value snaps. */\nconst SETTLED_EPSILON = 0.05\n\n/** Ease `from` toward `to` by `t`, or snap when it's close enough to be done. */\nfunction approach(from: number, to: number, t: number): number {\n const next = from + (to - from) * t\n return Math.abs(to - next) < SETTLED_EPSILON ? to : next\n}\n\nconst EMPTY_IDS: readonly NodeId[] = []\n\nconst samePoint = (a: Vec2 | null | undefined, b: Vec2 | null | undefined): boolean =>\n a === b || (a != null && b != null && a.x === b.x && a.y === b.y)\n\nconst sameRect = (a: Rect | undefined, b: Rect): boolean =>\n a !== undefined && a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height\n\nconst sameIds = (a: readonly NodeId[] | undefined, b: readonly NodeId[] | undefined): boolean => {\n const left = a ?? EMPTY_IDS\n const right = b ?? EMPTY_IDS\n return left.length === right.length && left.every((id, i) => id === right[i])\n}\n\n/** Whether two roster entries carry the same identity and slow fields. */\nfunction declarationEqual(a: Peer | null, b: Peer | null): boolean {\n if (a === b) return true\n if (!a || !b) return false\n return (\n a.name === b.name &&\n a.color === b.color &&\n samePoint(a.cursor, b.cursor) &&\n sameIds(a.selection, b.selection) &&\n sameIds(a.holding, b.holding)\n )\n}\n\nclass Registry implements PresenceRegistry {\n private readonly peers = new Map<string, PeerState>()\n private readonly listeners = new Set<() => void>()\n private snapshot: readonly PeerRecord[] = []\n private stale = false\n /** Merged rendered transforms across peers, rebuilt when {@link version} moves. */\n private transforms: Map<NodeId, Rect> = new Map()\n private transformsStale = false\n private version = 0\n /** Timestamp of the last {@link step}, so the ease is frame-rate independent. */\n private lastStep = -1\n\n /** Called on every change, roster or hot-path — something has to repaint either way. */\n constructor(private readonly requests: PresenceRenderRequests) {}\n\n private touch(): void {\n this.stale = true\n this.requests.requestRender()\n }\n\n /**\n * A change only the cursor layer can see. Same snapshot invalidation, but the\n * frame it asks for repaints one canvas instead of all of them.\n */\n private touchCursor(): void {\n this.stale = true\n this.requests.requestCursorRender()\n }\n\n /** A change React needs to know about, as well as the canvas. */\n private touchRoster(): void {\n this.touch()\n for (const listener of this.listeners) listener()\n }\n\n private peer(id: string): PeerState {\n let state = this.peers.get(id)\n if (!state) {\n state = {\n id,\n declared: null,\n live: undefined,\n renderCursor: null,\n transforms: new Map(),\n renderTransforms: new Map(),\n }\n this.peers.set(id, state)\n }\n return state\n }\n\n /** Drop a peer the roster doesn't claim and that has nothing left to draw. */\n private prune(state: PeerState): void {\n if (state.declared || state.live || state.transforms.size > 0) return\n this.peers.delete(state.id)\n this.invalidateTransforms()\n }\n\n private invalidateTransforms(): void {\n this.transformsStale = true\n this.version += 1\n }\n\n setPeers = (peers: Peer[]): void => {\n let changed = false\n const incoming = new Set<string>()\n for (const peer of peers) {\n incoming.add(peer.id)\n const state = this.peer(peer.id)\n if (declarationEqual(state.declared, peer)) continue\n state.declared = peer\n changed = true\n }\n for (const state of [...this.peers.values()]) {\n if (incoming.has(state.id)) continue\n // Declared before, absent now: they left. A peer the roster never\n // mentioned is none of its business and survives.\n if (!state.declared) continue\n this.peers.delete(state.id)\n changed = true\n }\n if (changed) this.touchRoster()\n }\n\n setPeerCursor = (peerId: string, point: Vec2 | null): void => {\n const state = this.peer(peerId)\n if (state.live !== undefined && samePoint(state.live, point)) return\n state.live = point\n if (point === null) this.prune(state)\n // Cursor-only: a peer this registry knows nothing else about is pruned here\n // too, but pruning one is only ever the erasure of a cursor — a record with\n // a roster entry or a live transform doesn't qualify (see `prune`).\n this.touchCursor()\n }\n\n setPeerNodeTransform = (peerId: string, nodeId: NodeId, rect: Rect | null): void => {\n const state = this.peer(peerId)\n if (rect === null) {\n const had = state.transforms.delete(nodeId)\n // The rendered box goes with the target: a released node snaps back to\n // wherever the graph says it is, which by then is where their commit put it.\n state.renderTransforms.delete(nodeId)\n this.prune(state)\n if (!had) return\n this.invalidateTransforms()\n this.touch()\n return\n }\n if (sameRect(state.transforms.get(nodeId), rect)) return\n state.transforms.set(nodeId, rect)\n // The first frame for a node places it outright — there's nothing to ease\n // from, and easing from the graph position would slide it across the canvas.\n if (!state.renderTransforms.has(nodeId)) {\n state.renderTransforms.set(nodeId, rect)\n this.invalidateTransforms()\n }\n this.touch()\n }\n\n removePeer = (peerId: string): void => {\n if (!this.peers.delete(peerId)) return\n this.invalidateTransforms()\n this.touchRoster()\n }\n\n getNodeTransforms = (): ReadonlyMap<NodeId, Rect> => {\n if (this.transformsStale) {\n this.transformsStale = false\n this.transforms = new Map()\n for (const state of this.peers.values()) {\n for (const [nodeId, rect] of state.renderTransforms) this.transforms.set(nodeId, rect)\n }\n }\n return this.transforms\n }\n\n getTransformVersion = (): number => this.version\n\n step = (now: number): boolean => {\n // Exponential ease, sampled at whatever interval this frame actually took,\n // so the motion looks the same on a 60Hz and a 120Hz display. The first\n // step has no interval to measure and assumes one ordinary frame.\n const elapsed = this.lastStep < 0 ? NOMINAL_FRAME_MS : Math.max(0, now - this.lastStep)\n this.lastStep = now\n const t = 1 - Math.exp(-elapsed / SMOOTHING_MS)\n let moving = false\n let transformsMoved = false\n\n for (const state of this.peers.values()) {\n const target = state.live !== undefined ? state.live : (state.declared?.cursor ?? null)\n if (target === null) {\n state.renderCursor = null\n } else if (!state.renderCursor) {\n state.renderCursor = target\n } else if (!samePoint(state.renderCursor, target)) {\n state.renderCursor = {\n x: approach(state.renderCursor.x, target.x, t),\n y: approach(state.renderCursor.y, target.y, t),\n }\n moving = true\n }\n\n for (const [nodeId, rect] of state.transforms) {\n const current = state.renderTransforms.get(nodeId)\n if (!current) {\n state.renderTransforms.set(nodeId, rect)\n transformsMoved = true\n continue\n }\n if (sameRect(current, rect)) continue\n state.renderTransforms.set(nodeId, {\n x: approach(current.x, rect.x, t),\n y: approach(current.y, rect.y, t),\n // Size comes from a resize rather than a drag and rarely differs\n // frame to frame, but easing it keeps a live resize as smooth.\n width: approach(current.width, rect.width, t),\n height: approach(current.height, rect.height, t),\n })\n transformsMoved = true\n moving = true\n }\n }\n\n if (transformsMoved) this.invalidateTransforms()\n if (moving) this.stale = true\n return moving\n }\n\n getPeers = (): readonly PeerRecord[] => {\n if (this.stale) {\n this.stale = false\n this.snapshot = [...this.peers.values()].map((state) => {\n const declared = state.declared\n // An imperative write, once made, owns the cursor; the roster's is a seed.\n const target = (state.live !== undefined ? state.live : declared?.cursor) ?? null\n return {\n id: state.id,\n name: declared?.name,\n color: declared?.color ?? peerColor(state.id),\n // Rendered, not raw: what {@link step} has eased to. Falls back to the\n // target so a registry nobody steps still paints something sensible.\n cursor: target === null ? null : (state.renderCursor ?? target),\n selection: declared?.selection ?? EMPTY_IDS,\n holding: declared?.holding ?? EMPTY_IDS,\n transforms: state.renderTransforms,\n }\n })\n }\n return this.snapshot\n }\n\n isEmpty = (): boolean => this.peers.size === 0\n\n subscribe = (listener: () => void): (() => void) => {\n this.listeners.add(listener)\n return () => {\n this.listeners.delete(listener)\n }\n }\n}\n\n/**\n * How the registry asks for paint. Every write is a repaint — presence exists\n * only as paint — but they don't all cost the same canvas.\n */\nexport type PresenceRenderRequests = {\n /** Repaint the frame: roster changes and peers' live boxes move real geometry. */\n requestRender: () => void\n /** Repaint the cursor layer alone. */\n requestCursorRender: () => void\n}\n\n/** Create a presence registry. */\nexport function createPresenceRegistry(requests: PresenceRenderRequests): PresenceRegistry {\n return new Registry(requests)\n}\n","import { useCallback, useSyncExternalStore } from \"react\"\nimport { useRivetContext } from \"../context\"\nimport type { LockIntent, NodeLock } from \"../locks/registry\"\nimport type { NodeId } from \"../types\"\n\nconst UNLOCKED: NodeLock = { locked: false }\n\n/**\n * Whether a node is locked, and by whom — for the chrome rivet can't draw for\n * you: a padlock in the node's header, a \"Ada is editing\" line, a disabled\n * form inside the node body.\n *\n * rivet already refuses the interactions it owns (see the `lockedNodes` prop),\n * so this is for *your* controls. Re-renders only when this node changes hands,\n * not when any lock in the document moves.\n *\n * ```tsx\n * function MyNode({ id }: NodeProps) {\n * const { locked, holderId } = useNodeLock(id)\n * return <input disabled={locked} title={locked ? `${holderId} is editing` : \"\"} />\n * }\n * ```\n */\nexport function useNodeLock(id: NodeId): NodeLock {\n const { store } = useRivetContext()\n const getHolder = useCallback(() => store.locks.getHolder(id), [store, id])\n // Snapshot the holder id, not an object: `useSyncExternalStore` compares with\n // Object.is, so a fresh `{ locked, holderId }` every call would re-render on\n // any lock change anywhere. The record is built after the comparison.\n const holderId = useSyncExternalStore(store.locks.subscribe, getHolder, getHolder)\n return holderId === null ? UNLOCKED : { locked: true, holderId }\n}\n\n/**\n * Whether this client may do `intent` to a node right now — the same question\n * every rivet input path asks, answered through the same policy.\n *\n * Use it to keep your own affordances honest: hide a delete button on a node a\n * peer has locked, rather than letting it be pressed and refused. Always `true`\n * for an unlocked node.\n */\nexport function useNodeLockAllows(id: NodeId, intent: LockIntent): boolean {\n const { store } = useRivetContext()\n const allows = useCallback(() => store.locks.allows(id, intent), [store, id, intent])\n return useSyncExternalStore(store.locks.subscribe, allows, allows)\n}\n"]}
|