@liveblocks/react 1.2.2-comments2 → 1.2.2-comments3

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/dist/index.js CHANGED
@@ -1,11 +1,9 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }"use client";
2
-
3
- // src/index.ts
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/index.ts
4
2
  var _core = require('@liveblocks/core');
5
3
 
6
4
  // src/version.ts
7
5
  var PKG_NAME = "@liveblocks/react";
8
- var PKG_VERSION = "1.2.2-comments2";
6
+ var PKG_VERSION = "1.2.2-comments3";
9
7
  var PKG_FORMAT = "cjs";
10
8
 
11
9
  // src/ClientSideSuspense.tsx
@@ -26,483 +24,8 @@ var _client = require('@liveblocks/client');
26
24
 
27
25
 
28
26
 
29
-
30
-
31
27
  var _withselectorjs = require('use-sync-external-store/shim/with-selector.js');
32
28
 
33
- // src/comments/CommentsRoom.ts
34
-
35
-
36
- // ../../node_modules/nanoid/index.js
37
- var _crypto = require('crypto'); var _crypto2 = _interopRequireDefault(_crypto);
38
-
39
- // ../../node_modules/nanoid/url-alphabet/index.js
40
- var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
41
-
42
- // ../../node_modules/nanoid/index.js
43
- var POOL_SIZE_MULTIPLIER = 128;
44
- var pool;
45
- var poolOffset;
46
- var fillPool = (bytes) => {
47
- if (!pool || pool.length < bytes) {
48
- pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER);
49
- _crypto2.default.randomFillSync(pool);
50
- poolOffset = 0;
51
- } else if (poolOffset + bytes > pool.length) {
52
- _crypto2.default.randomFillSync(pool);
53
- poolOffset = 0;
54
- }
55
- poolOffset += bytes;
56
- };
57
- var nanoid = (size = 21) => {
58
- fillPool(size -= 0);
59
- let id = "";
60
- for (let i = poolOffset - size; i < poolOffset; i++) {
61
- id += urlAlphabet[pool[i] & 63];
62
- }
63
- return id;
64
- };
65
-
66
- // src/comments/CommentsRoom.ts
67
- var _indexjs = require('use-sync-external-store/shim/index.js');
68
-
69
- // src/comments/errors.ts
70
- var CreateThreadError = class extends Error {
71
- constructor(cause, context) {
72
- super("Create thread failed.");
73
- this.cause = cause;
74
- this.context = context;
75
- this.name = "CreateThreadError";
76
- }
77
- };
78
- var EditThreadMetadataError = class extends Error {
79
- constructor(cause, context) {
80
- super("Edit thread metadata failed.");
81
- this.cause = cause;
82
- this.context = context;
83
- this.name = "EditThreadMetadataError";
84
- }
85
- };
86
- var CreateCommentError = class extends Error {
87
- constructor(cause, context) {
88
- super("Create comment failed.");
89
- this.cause = cause;
90
- this.context = context;
91
- this.name = "CreateCommentError";
92
- }
93
- };
94
- var EditCommentError = class extends Error {
95
- constructor(cause, context) {
96
- super("Edit comment failed.");
97
- this.cause = cause;
98
- this.context = context;
99
- this.name = "EditCommentError";
100
- }
101
- };
102
- var DeleteCommentError = class extends Error {
103
- constructor(cause, context) {
104
- super("Delete comment failed.");
105
- this.cause = cause;
106
- this.context = context;
107
- this.name = "DeleteCommentError";
108
- }
109
- };
110
-
111
- // src/comments/lib/store.ts
112
-
113
- function createStore(initialState) {
114
- let state = initialState;
115
- const eventSource = _core.makeEventSource.call(void 0, );
116
- return {
117
- get() {
118
- return state;
119
- },
120
- set(newState) {
121
- state = newState;
122
- eventSource.notify(state);
123
- },
124
- subscribe(callback) {
125
- return eventSource.subscribe(callback);
126
- },
127
- subscribeOnce(callback) {
128
- return eventSource.subscribeOnce(callback);
129
- },
130
- subscribersCount() {
131
- return eventSource.count();
132
- },
133
- destroy() {
134
- return eventSource.clear();
135
- }
136
- };
137
- }
138
-
139
- // src/comments/CommentsRoom.ts
140
- var POLLING_INTERVAL_REALTIME = 3e4;
141
- var POLLING_INTERVAL = 5e3;
142
- var THREAD_ID_PREFIX = "th";
143
- var COMMENT_ID_PREFIX = "cm";
144
- function createOptimisticId(prefix) {
145
- return `${prefix}_${nanoid()}`;
146
- }
147
- function createCommentsRoom(room, errorEventSource) {
148
- const store = createStore({
149
- isLoading: true
150
- });
151
- let numberOfMutations = 0;
152
- function endMutation() {
153
- numberOfMutations--;
154
- if (numberOfMutations === 0) {
155
- revalidateThreads();
156
- }
157
- }
158
- function startMutation() {
159
- pollingHub.threads.stop();
160
- numberOfMutations++;
161
- }
162
- const pollingHub = {
163
- // TODO: If there's an error, it will currently infinitely retry at the current polling rate → add retry logic
164
- threads: _core.makePoller.call(void 0, revalidateThreads)
165
- };
166
- let unsubscribeRealtimeEvents;
167
- let unsubscribeRealtimeConnection;
168
- let realtimeClientConnected = false;
169
- function getPollingInterval() {
170
- return realtimeClientConnected ? POLLING_INTERVAL_REALTIME : POLLING_INTERVAL;
171
- }
172
- function ensureThreadsAreLoadedForMutations() {
173
- const state = store.get();
174
- if (state.isLoading || state.error) {
175
- throw new Error(
176
- "Cannot update threads or comments before they are loaded"
177
- );
178
- }
179
- return state.threads;
180
- }
181
- async function revalidateThreads() {
182
- pollingHub.threads.pause();
183
- if (numberOfMutations === 0) {
184
- setThreads(await room.getThreads());
185
- }
186
- pollingHub.threads.resume();
187
- }
188
- function subscribe() {
189
- if (!unsubscribeRealtimeEvents) {
190
- unsubscribeRealtimeEvents = room.events.comments.subscribe(() => {
191
- pollingHub.threads.restart(getPollingInterval());
192
- revalidateThreads();
193
- });
194
- }
195
- if (!unsubscribeRealtimeConnection) {
196
- unsubscribeRealtimeConnection = room.events.status.subscribe((status) => {
197
- const nextRealtimeClientConnected = status === "connected";
198
- if (nextRealtimeClientConnected !== realtimeClientConnected) {
199
- realtimeClientConnected = nextRealtimeClientConnected;
200
- pollingHub.threads.restart(getPollingInterval());
201
- }
202
- });
203
- }
204
- pollingHub.threads.start(getPollingInterval());
205
- revalidateThreads();
206
- return () => {
207
- pollingHub.threads.stop();
208
- _optionalChain([unsubscribeRealtimeEvents, 'optionalCall', _ => _()]);
209
- unsubscribeRealtimeEvents = void 0;
210
- _optionalChain([unsubscribeRealtimeConnection, 'optionalCall', _2 => _2()]);
211
- unsubscribeRealtimeConnection = void 0;
212
- };
213
- }
214
- function setThreads(newThreads) {
215
- store.set({
216
- threads: newThreads,
217
- isLoading: false
218
- });
219
- }
220
- function getCurrentUserId() {
221
- const self = room.getSelf();
222
- if (self === null || self.id === void 0) {
223
- return "anonymous";
224
- } else {
225
- return self.id;
226
- }
227
- }
228
- function createThread(options) {
229
- const body = options.body;
230
- const metadata = "metadata" in options ? options.metadata : {};
231
- const threads = ensureThreadsAreLoadedForMutations();
232
- const threadId = createOptimisticId(THREAD_ID_PREFIX);
233
- const commentId = createOptimisticId(COMMENT_ID_PREFIX);
234
- const now = (/* @__PURE__ */ new Date()).toISOString();
235
- const newThread = {
236
- id: threadId,
237
- type: "thread",
238
- createdAt: now,
239
- roomId: room.id,
240
- metadata,
241
- comments: [
242
- {
243
- id: commentId,
244
- createdAt: now,
245
- type: "comment",
246
- userId: getCurrentUserId(),
247
- body
248
- }
249
- ]
250
- };
251
- setThreads([...threads, newThread]);
252
- startMutation();
253
- room.createThread({ threadId, commentId, body, metadata }).catch(
254
- (er) => errorEventSource.notify(
255
- new CreateThreadError(er, {
256
- roomId: room.id,
257
- threadId,
258
- commentId,
259
- body,
260
- metadata
261
- })
262
- )
263
- ).finally(endMutation);
264
- return newThread;
265
- }
266
- function editThreadMetadata(options) {
267
- const threadId = options.threadId;
268
- const metadata = "metadata" in options ? options.metadata : {};
269
- const threads = ensureThreadsAreLoadedForMutations();
270
- setThreads(
271
- threads.map(
272
- (thread) => thread.id === threadId ? {
273
- ...thread,
274
- metadata: {
275
- ...thread.metadata,
276
- ...metadata
277
- }
278
- } : thread
279
- )
280
- );
281
- startMutation();
282
- room.editThreadMetadata({ metadata, threadId }).catch(
283
- (er) => errorEventSource.notify(
284
- new EditThreadMetadataError(er, {
285
- roomId: room.id,
286
- threadId,
287
- metadata
288
- })
289
- )
290
- ).finally(endMutation);
291
- }
292
- function createComment({
293
- threadId,
294
- body
295
- }) {
296
- const threads = ensureThreadsAreLoadedForMutations();
297
- const commentId = createOptimisticId(COMMENT_ID_PREFIX);
298
- const now = (/* @__PURE__ */ new Date()).toISOString();
299
- const comment = {
300
- id: commentId,
301
- threadId,
302
- roomId: room.id,
303
- type: "comment",
304
- createdAt: now,
305
- userId: getCurrentUserId(),
306
- body
307
- };
308
- setThreads(
309
- threads.map(
310
- (thread) => thread.id === threadId ? {
311
- ...thread,
312
- comments: [...thread.comments, comment]
313
- } : thread
314
- )
315
- );
316
- startMutation();
317
- room.createComment({ threadId, commentId, body }).catch(
318
- (er) => errorEventSource.notify(
319
- new CreateCommentError(er, {
320
- roomId: room.id,
321
- threadId,
322
- commentId,
323
- body
324
- })
325
- )
326
- ).finally(endMutation);
327
- return comment;
328
- }
329
- function editComment({ threadId, commentId, body }) {
330
- const threads = ensureThreadsAreLoadedForMutations();
331
- const now = (/* @__PURE__ */ new Date()).toISOString();
332
- setThreads(
333
- threads.map(
334
- (thread) => thread.id === threadId ? {
335
- ...thread,
336
- comments: thread.comments.map(
337
- (comment) => comment.id === commentId ? {
338
- ...comment,
339
- editedAt: now,
340
- body
341
- } : comment
342
- )
343
- } : thread
344
- )
345
- );
346
- startMutation();
347
- room.editComment({ threadId, commentId, body }).catch(
348
- (er) => errorEventSource.notify(
349
- new EditCommentError(er, {
350
- roomId: room.id,
351
- threadId,
352
- commentId,
353
- body
354
- })
355
- )
356
- ).finally(endMutation);
357
- }
358
- function deleteComment({ threadId, commentId }) {
359
- const threads = ensureThreadsAreLoadedForMutations();
360
- const now = (/* @__PURE__ */ new Date()).toISOString();
361
- const newThreads = [];
362
- for (const thread of threads) {
363
- if (thread.id === threadId) {
364
- const newThread = {
365
- ...thread,
366
- comments: thread.comments.map(
367
- (comment) => comment.id === commentId ? {
368
- ...comment,
369
- deletedAt: now,
370
- body: void 0
371
- } : comment
372
- )
373
- };
374
- if (newThread.comments.some((comment) => comment.deletedAt === void 0)) {
375
- newThreads.push(newThread);
376
- }
377
- } else {
378
- newThreads.push(thread);
379
- }
380
- }
381
- setThreads(newThreads);
382
- startMutation();
383
- room.deleteComment({ threadId, commentId }).catch(
384
- (er) => errorEventSource.notify(
385
- new DeleteCommentError(er, {
386
- roomId: room.id,
387
- threadId,
388
- commentId
389
- })
390
- )
391
- ).finally(endMutation);
392
- }
393
- function useThreads() {
394
- return _indexjs.useSyncExternalStore.call(void 0,
395
- store.subscribe,
396
- store.get,
397
- store.get
398
- );
399
- }
400
- function useThreadsSuspense() {
401
- const result = useThreads();
402
- if (result.isLoading) {
403
- throw new Promise(store.subscribeOnce);
404
- }
405
- if (result.error) {
406
- throw result.error;
407
- }
408
- return result.threads;
409
- }
410
- return {
411
- useThreads,
412
- useThreadsSuspense,
413
- createThread,
414
- editThreadMetadata,
415
- createComment,
416
- editComment,
417
- deleteComment,
418
- subscribe
419
- };
420
- }
421
-
422
- // src/comments/lib/use-async-cache.ts
423
-
424
-
425
-
426
- // src/comments/lib/use-initial.ts
427
-
428
- function useInitial(value) {
429
- return _react.useRef.call(void 0, value instanceof Function ? value() : value).current;
430
- }
431
-
432
- // src/comments/lib/use-async-cache.ts
433
- var INITIAL_ASYNC_STATE = {
434
- isLoading: false,
435
- data: void 0,
436
- error: void 0
437
- };
438
- var noop = () => {
439
- };
440
- function useAsyncCache(cache, key, options) {
441
- const frozenOptions = useInitial(options);
442
- const cacheItem = _react.useMemo.call(void 0, () => {
443
- if (key === null || !cache) {
444
- return null;
445
- }
446
- const cacheItem2 = cache.create(key, _optionalChain([frozenOptions, 'optionalAccess', _3 => _3.overrideFunction]));
447
- void cacheItem2.get();
448
- return cacheItem2;
449
- }, [cache, frozenOptions, key]);
450
- const subscribe = _react.useCallback.call(void 0,
451
- (callback) => _nullishCoalesce(_optionalChain([cacheItem, 'optionalAccess', _4 => _4.subscribe, 'call', _5 => _5(callback)]), () => ( noop)),
452
- [cacheItem]
453
- );
454
- const getState = _react.useCallback.call(void 0,
455
- () => _nullishCoalesce(_optionalChain([cacheItem, 'optionalAccess', _6 => _6.getState, 'call', _7 => _7()]), () => ( INITIAL_ASYNC_STATE)),
456
- [cacheItem]
457
- );
458
- const revalidate = _react.useCallback.call(void 0, () => _optionalChain([cacheItem, 'optionalAccess', _8 => _8.revalidate, 'call', _9 => _9()]), [cacheItem]);
459
- const state = _indexjs.useSyncExternalStore.call(void 0, subscribe, getState, getState);
460
- const previousData = _react.useRef.call(void 0, );
461
- let data = state.data;
462
- _react.useEffect.call(void 0, () => {
463
- previousData.current = { key, data: state.data };
464
- }, [key, state]);
465
- if (_optionalChain([frozenOptions, 'optionalAccess', _10 => _10.suspense]) && state.isLoading && cacheItem) {
466
- throw new Promise((resolve) => {
467
- cacheItem.subscribeOnce(() => resolve());
468
- });
469
- }
470
- if (state.isLoading && _optionalChain([frozenOptions, 'optionalAccess', _11 => _11.keepPreviousDataWhileLoading]) && typeof state.data === "undefined" && _optionalChain([previousData, 'access', _12 => _12.current, 'optionalAccess', _13 => _13.key]) !== key && typeof _optionalChain([previousData, 'access', _14 => _14.current, 'optionalAccess', _15 => _15.data]) !== "undefined") {
471
- data = previousData.current.data;
472
- }
473
- return {
474
- isLoading: state.isLoading,
475
- data,
476
- error: state.error,
477
- getState,
478
- revalidate
479
- };
480
- }
481
-
482
- // src/comments/lib/use-debounce.ts
483
-
484
- var DEFAULT_DELAY = 500;
485
- function useDebounce(value, delay = DEFAULT_DELAY) {
486
- const timeout = _react.useRef.call(void 0, );
487
- const [debouncedValue, setDebouncedValue] = _react.useState.call(void 0, value);
488
- _react.useEffect.call(void 0, () => {
489
- if (delay === false) {
490
- return;
491
- }
492
- if (timeout.current === void 0) {
493
- setDebouncedValue(value);
494
- }
495
- timeout.current = window.setTimeout(() => {
496
- setDebouncedValue(value);
497
- timeout.current = void 0;
498
- }, delay);
499
- return () => {
500
- window.clearTimeout(timeout.current);
501
- };
502
- }, [value, delay]);
503
- return debouncedValue;
504
- }
505
-
506
29
  // src/hooks.ts
507
30
 
508
31
  function useRerender() {
@@ -515,12 +38,12 @@ function useRerender() {
515
38
  );
516
39
  return update;
517
40
  }
518
- function useInitial2(value) {
41
+ function useInitial(value) {
519
42
  return _react.useRef.call(void 0, value).current;
520
43
  }
521
44
 
522
45
  // src/factory.tsx
523
- var noop2 = () => {
46
+ var noop = () => {
524
47
  };
525
48
  var identity = (x) => x;
526
49
  var missing_unstable_batchedUpdates = (reactVersion, roomId) => `We noticed you\u2019re using React ${reactVersion}. Please pass unstable_batchedUpdates at the RoomProvider level until you\u2019re ready to upgrade to React 18:
@@ -535,7 +58,7 @@ var missing_unstable_batchedUpdates = (reactVersion, roomId) => `We noticed you\
535
58
 
536
59
  Why? Please see https://liveblocks.io/docs/guides/troubleshooting#stale-props-zombie-child for more information`;
537
60
  var superfluous_unstable_batchedUpdates = "You don\u2019t need to pass unstable_batchedUpdates to RoomProvider anymore, since you\u2019re on React 18+ already.";
538
- function useSyncExternalStore3(s, gs, gss) {
61
+ function useSyncExternalStore(s, gs, gss) {
539
62
  return _withselectorjs.useSyncExternalStoreWithSelector.call(void 0, s, gs, gss, identity);
540
63
  }
541
64
  var EMPTY_OTHERS = (
@@ -572,27 +95,7 @@ function makeMutationContext(room) {
572
95
  setMyPresence: room.updatePresence
573
96
  };
574
97
  }
575
- var hasWarnedIfNoResolveUser = false;
576
- var hasWarnedIfNoResolveMentionSuggestions = false;
577
- function warnIfNoResolveUser(usersCache) {
578
- if (!hasWarnedIfNoResolveUser && !usersCache && process.env.NODE_ENV !== "production") {
579
- console.warn("The resolveUser option wasn't set in createRoomContext.");
580
- hasWarnedIfNoResolveUser = true;
581
- }
582
- }
583
- function warnIfNoResolveMentionSuggestions(mentionSuggestionsCache) {
584
- if (!hasWarnedIfNoResolveMentionSuggestions && !mentionSuggestionsCache && process.env.NODE_ENV !== "production") {
585
- console.warn(
586
- "The resolveMentionSuggestions option wasn't set in createRoomContext."
587
- );
588
- hasWarnedIfNoResolveMentionSuggestions = true;
589
- }
590
- }
591
- var ContextBundle = React2.createContext(null);
592
- function useRoomContextBundle() {
593
- return React2.useContext(ContextBundle);
594
- }
595
- function createRoomContext(client, options) {
98
+ function createRoomContext(client) {
596
99
  const RoomContext = React2.createContext(null);
597
100
  function RoomProvider(props) {
598
101
  const {
@@ -622,7 +125,7 @@ function createRoomContext(client, options) {
622
125
  superfluous_unstable_batchedUpdates
623
126
  );
624
127
  }
625
- const frozen = useInitial2({
128
+ const frozen = useInitial({
626
129
  initialPresence,
627
130
  initialStorage,
628
131
  unstable_batchedUpdates,
@@ -637,24 +140,19 @@ function createRoomContext(client, options) {
637
140
  })
638
141
  );
639
142
  React2.useEffect(() => {
640
- const room2 = client.enter(
641
- roomId,
642
- {
143
+ setRoom(
144
+ client.enter(roomId, {
643
145
  initialPresence: frozen.initialPresence,
644
146
  initialStorage: frozen.initialStorage,
645
147
  shouldInitiallyConnect: frozen.shouldInitiallyConnect,
646
148
  unstable_batchedUpdates: frozen.unstable_batchedUpdates
647
- }
149
+ })
648
150
  );
649
- setRoom(room2);
650
- const unsubscribe = getCommentsRoom(room2).subscribe();
651
151
  return () => {
652
- unsubscribe();
653
- commentsRooms.delete(room2.id);
654
152
  client.leave(roomId);
655
153
  };
656
154
  }, [roomId, frozen]);
657
- return /* @__PURE__ */ React2.createElement(RoomContext.Provider, { value: room }, /* @__PURE__ */ React2.createElement(ContextBundle.Provider, { value: bundle }, props.children));
155
+ return /* @__PURE__ */ React2.createElement(RoomContext.Provider, { value: room }, props.children);
658
156
  }
659
157
  function connectionIdSelector(others) {
660
158
  return others.map((user) => user.connectionId);
@@ -662,7 +160,7 @@ function createRoomContext(client, options) {
662
160
  function useRoom() {
663
161
  const room = React2.useContext(RoomContext);
664
162
  if (room === null) {
665
- throw new Error("RoomProvider is missing from the React tree.");
163
+ throw new Error("RoomProvider is missing from the react tree");
666
164
  }
667
165
  return room;
668
166
  }
@@ -670,13 +168,13 @@ function createRoomContext(client, options) {
670
168
  const room = useRoom();
671
169
  const subscribe = room.events.status.subscribe;
672
170
  const getSnapshot = room.getStatus;
673
- return useSyncExternalStore3(subscribe, getSnapshot, getSnapshot);
171
+ return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
674
172
  }
675
173
  function useMyPresence() {
676
174
  const room = useRoom();
677
175
  const subscribe = room.events.myPresence.subscribe;
678
176
  const getSnapshot = room.getPresence;
679
- const presence = useSyncExternalStore3(subscribe, getSnapshot, getSnapshot);
177
+ const presence = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
680
178
  const setPresence = room.updatePresence;
681
179
  return [presence, setPresence];
682
180
  }
@@ -750,8 +248,8 @@ function createRoomContext(client, options) {
750
248
  function useBroadcastEvent() {
751
249
  const room = useRoom();
752
250
  return React2.useCallback(
753
- (event, options2 = { shouldQueueEventIfNotReady: false }) => {
754
- room.broadcastEvent(event, options2);
251
+ (event, options = { shouldQueueEventIfNotReady: false }) => {
252
+ room.broadcastEvent(event, options);
755
253
  },
756
254
  [room]
757
255
  );
@@ -816,7 +314,7 @@ function createRoomContext(client, options) {
816
314
  const subscribe = room.events.storageDidLoad.subscribeOnce;
817
315
  const getSnapshot = room.getStorageSnapshot;
818
316
  const getServerSnapshot = React2.useCallback(() => null, []);
819
- return useSyncExternalStore3(subscribe, getSnapshot, getServerSnapshot);
317
+ return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
820
318
  }
821
319
  function useStorageRoot() {
822
320
  return [useMutableStorageRoot()];
@@ -834,13 +332,13 @@ function createRoomContext(client, options) {
834
332
  const room = useRoom();
835
333
  const subscribe = room.events.history.subscribe;
836
334
  const canUndo = room.history.canUndo;
837
- return useSyncExternalStore3(subscribe, canUndo, canUndo);
335
+ return useSyncExternalStore(subscribe, canUndo, canUndo);
838
336
  }
839
337
  function useCanRedo() {
840
338
  const room = useRoom();
841
339
  const subscribe = room.events.history.subscribe;
842
340
  const canRedo = room.history.canRedo;
843
- return useSyncExternalStore3(subscribe, canRedo, canRedo);
341
+ return useSyncExternalStore(subscribe, canRedo, canRedo);
844
342
  }
845
343
  function useBatch() {
846
344
  return useRoom().batch;
@@ -897,7 +395,7 @@ function createRoomContext(client, options) {
897
395
  [selector]
898
396
  );
899
397
  const subscribe = React2.useCallback(
900
- (onStoreChange) => rootOrNull !== null ? room.subscribe(rootOrNull, onStoreChange, { isDeep: true }) : noop2,
398
+ (onStoreChange) => rootOrNull !== null ? room.subscribe(rootOrNull, onStoreChange, { isDeep: true }) : noop,
901
399
  [room, rootOrNull]
902
400
  );
903
401
  const getSnapshot = React2.useCallback(() => {
@@ -1003,123 +501,7 @@ function createRoomContext(client, options) {
1003
501
  useSuspendUntilStorageLoaded();
1004
502
  return useLegacyKey(key);
1005
503
  }
1006
- const errorEventSource = _core.makeEventSource.call(void 0, );
1007
- const commentsRooms = /* @__PURE__ */ new Map();
1008
- function getCommentsRoom(room) {
1009
- let commentsRoom = commentsRooms.get(room.id);
1010
- if (commentsRoom === void 0) {
1011
- commentsRoom = createCommentsRoom(room, errorEventSource);
1012
- commentsRooms.set(room.id, commentsRoom);
1013
- }
1014
- return commentsRoom;
1015
- }
1016
- function useThreads() {
1017
- const room = useRoom();
1018
- return getCommentsRoom(room).useThreads();
1019
- }
1020
- function useThreadsSuspense() {
1021
- const room = useRoom();
1022
- return getCommentsRoom(room).useThreadsSuspense();
1023
- }
1024
- function useCreateThread() {
1025
- const room = useRoom();
1026
- return React2.useCallback(
1027
- (options2) => getCommentsRoom(room).createThread(options2),
1028
- [room]
1029
- );
1030
- }
1031
- function useEditThreadMetadata() {
1032
- const room = useRoom();
1033
- return React2.useCallback(
1034
- (options2) => getCommentsRoom(room).editThreadMetadata(options2),
1035
- [room]
1036
- );
1037
- }
1038
- function useCreateComment() {
1039
- const room = useRoom();
1040
- return React2.useCallback(
1041
- (options2) => getCommentsRoom(room).createComment(options2),
1042
- [room]
1043
- );
1044
- }
1045
- function useEditComment() {
1046
- const room = useRoom();
1047
- return React2.useCallback(
1048
- (options2) => getCommentsRoom(room).editComment(options2),
1049
- [room]
1050
- );
1051
- }
1052
- function useDeleteComment() {
1053
- const room = useRoom();
1054
- return React2.useCallback(
1055
- (options2) => getCommentsRoom(room).deleteComment(options2),
1056
- [room]
1057
- );
1058
- }
1059
- const { resolveUser, resolveMentionSuggestions } = _nullishCoalesce(options, () => ( {}));
1060
- const usersCache = resolveUser ? _core.createAsyncCache.call(void 0, (stringifiedOptions) => {
1061
- return resolveUser(
1062
- JSON.parse(stringifiedOptions)
1063
- );
1064
- }) : void 0;
1065
- function useUser(userId) {
1066
- const resolverKey = React2.useMemo(
1067
- () => JSON.stringify({ userId }),
1068
- [userId]
1069
- );
1070
- const state = useAsyncCache(usersCache, resolverKey);
1071
- React2.useEffect(() => warnIfNoResolveUser(usersCache), []);
1072
- if (state.isLoading) {
1073
- return {
1074
- isLoading: true
1075
- };
1076
- } else {
1077
- return {
1078
- user: state.data,
1079
- error: state.error,
1080
- isLoading: false
1081
- };
1082
- }
1083
- }
1084
- function useUserSuspense(userId) {
1085
- const resolverKey = React2.useMemo(
1086
- () => JSON.stringify({ userId }),
1087
- [userId]
1088
- );
1089
- const state = useAsyncCache(usersCache, resolverKey, {
1090
- suspense: true
1091
- });
1092
- React2.useEffect(() => warnIfNoResolveUser(usersCache), []);
1093
- return {
1094
- user: state.data,
1095
- error: state.error,
1096
- isLoading: false
1097
- };
1098
- }
1099
- const mentionSuggestionsCache = _core.createAsyncCache.call(void 0,
1100
- resolveMentionSuggestions ? (stringifiedOptions) => {
1101
- return resolveMentionSuggestions(
1102
- JSON.parse(stringifiedOptions)
1103
- );
1104
- } : () => Promise.resolve([])
1105
- );
1106
- function useMentionSuggestions(search) {
1107
- const room = useRoom();
1108
- const debouncedSearch = useDebounce(search, 500);
1109
- const resolverKey = React2.useMemo(
1110
- () => debouncedSearch !== void 0 ? JSON.stringify({ text: debouncedSearch, roomId: room.id }) : null,
1111
- [debouncedSearch, room.id]
1112
- );
1113
- const { data } = useAsyncCache(mentionSuggestionsCache, resolverKey, {
1114
- keepPreviousDataWhileLoading: true
1115
- });
1116
- React2.useEffect(
1117
- () => warnIfNoResolveMentionSuggestions(mentionSuggestionsCache),
1118
- []
1119
- );
1120
- return data;
1121
- }
1122
- const bundle = {
504
+ return {
1123
505
  RoomContext,
1124
506
  RoomProvider,
1125
507
  useRoom,
@@ -1148,14 +530,6 @@ function createRoomContext(client, options) {
1148
530
  useOthersConnectionIds,
1149
531
  useOther,
1150
532
  useMutation,
1151
- useThreads,
1152
- useUser,
1153
- useCreateThread,
1154
- useEditThreadMetadata,
1155
- useCreateComment,
1156
- useEditComment,
1157
- useDeleteComment,
1158
- useMentionSuggestions,
1159
533
  suspense: {
1160
534
  RoomContext,
1161
535
  RoomProvider,
@@ -1184,17 +558,9 @@ function createRoomContext(client, options) {
1184
558
  useOthersMapped: useOthersMappedSuspense,
1185
559
  useOthersConnectionIds: useOthersConnectionIdsSuspense,
1186
560
  useOther: useOtherSuspense,
1187
- useMutation,
1188
- useThreads: useThreadsSuspense,
1189
- useUser: useUserSuspense,
1190
- useCreateThread,
1191
- useEditThreadMetadata,
1192
- useCreateComment,
1193
- useEditComment,
1194
- useDeleteComment
561
+ useMutation
1195
562
  }
1196
563
  };
1197
- return bundle;
1198
564
  }
1199
565
 
1200
566
  // src/index.ts
@@ -1204,6 +570,5 @@ _core.detectDupes.call(void 0, PKG_NAME, PKG_VERSION, PKG_FORMAT);
1204
570
 
1205
571
 
1206
572
 
1207
-
1208
- exports.ClientSideSuspense = ClientSideSuspense; exports.createRoomContext = createRoomContext; exports.shallow = _client.shallow; exports.useRoomContextBundle = useRoomContextBundle;
573
+ exports.ClientSideSuspense = ClientSideSuspense; exports.createRoomContext = createRoomContext; exports.shallow = _client.shallow;
1209
574
  //# sourceMappingURL=index.js.map