@liveblocks/react 2.7.0 → 2.7.2

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.
@@ -1,6 +1,6 @@
1
1
  // src/version.ts
2
2
  var PKG_NAME = "@liveblocks/react";
3
- var PKG_VERSION = "2.7.0";
3
+ var PKG_VERSION = "2.7.2";
4
4
  var PKG_FORMAT = "esm";
5
5
 
6
6
  // src/ClientSideSuspense.tsx
@@ -13,123 +13,37 @@ function ClientSideSuspense(props) {
13
13
  return /* @__PURE__ */ React.createElement(React.Suspense, { fallback: props.fallback }, mounted ? typeof props.children === "function" ? props.children() : props.children : props.fallback);
14
14
  }
15
15
 
16
- // src/comments/errors.ts
17
- var CreateThreadError = class extends Error {
18
- constructor(cause, context) {
19
- super("Create thread failed.");
20
- this.cause = cause;
21
- this.context = context;
22
- this.name = "CreateThreadError";
23
- }
24
- };
25
- var DeleteThreadError = class extends Error {
26
- constructor(cause, context) {
27
- super("Delete thread failed.");
28
- this.cause = cause;
29
- this.context = context;
30
- this.name = "DeleteThreadError";
31
- }
32
- };
33
- var EditThreadMetadataError = class extends Error {
34
- constructor(cause, context) {
35
- super("Edit thread metadata failed.");
36
- this.cause = cause;
37
- this.context = context;
38
- this.name = "EditThreadMetadataError";
39
- }
40
- };
41
- var MarkThreadAsResolvedError = class extends Error {
42
- constructor(cause, context) {
43
- super("Mark thread as resolved failed.");
44
- this.cause = cause;
45
- this.context = context;
46
- this.name = "MarkThreadAsResolvedError";
47
- }
48
- };
49
- var MarkThreadAsUnresolvedError = class extends Error {
50
- constructor(cause, context) {
51
- super("Mark thread as unresolved failed.");
52
- this.cause = cause;
53
- this.context = context;
54
- this.name = "MarkThreadAsUnresolvedError";
55
- }
56
- };
57
- var CreateCommentError = class extends Error {
58
- constructor(cause, context) {
59
- super("Create comment failed.");
60
- this.cause = cause;
61
- this.context = context;
62
- this.name = "CreateCommentError";
63
- }
64
- };
65
- var EditCommentError = class extends Error {
66
- constructor(cause, context) {
67
- super("Edit comment failed.");
68
- this.cause = cause;
69
- this.context = context;
70
- this.name = "EditCommentError";
71
- }
72
- };
73
- var DeleteCommentError = class extends Error {
74
- constructor(cause, context) {
75
- super("Delete comment failed.");
76
- this.cause = cause;
77
- this.context = context;
78
- this.name = "DeleteCommentError";
79
- }
80
- };
81
- var AddReactionError = class extends Error {
82
- constructor(cause, context) {
83
- super("Add reaction failed.");
84
- this.cause = cause;
85
- this.context = context;
86
- this.name = "AddReactionError";
87
- }
88
- };
89
- var RemoveReactionError = class extends Error {
90
- constructor(cause, context) {
91
- super("Remove reaction failed.");
92
- this.cause = cause;
93
- this.context = context;
94
- this.name = "RemoveReactionError";
95
- }
96
- };
97
- var MarkInboxNotificationAsReadError = class extends Error {
98
- constructor(cause, context) {
99
- super("Mark inbox notification as read failed.");
100
- this.cause = cause;
101
- this.context = context;
102
- this.name = "MarkInboxNotificationAsReadError";
103
- }
104
- };
105
- var UpdateNotificationSettingsError = class extends Error {
106
- constructor(cause, context) {
107
- super("Update notification settings failed.");
108
- this.cause = cause;
109
- this.context = context;
110
- this.name = "UpdateNotificationSettingsError";
111
- }
112
- };
16
+ // src/contexts.ts
17
+ import * as React2 from "react";
18
+ var RoomContext = React2.createContext(null);
19
+ function useRoomOrNull() {
20
+ return React2.useContext(RoomContext);
21
+ }
22
+ function useIsInsideRoom() {
23
+ const room = useRoomOrNull();
24
+ return room !== null;
25
+ }
113
26
 
114
- // src/room.tsx
115
- import { shallow as shallow2 } from "@liveblocks/client";
27
+ // src/liveblocks.tsx
116
28
  import {
117
- CommentsApiError,
118
- console as console3,
119
- createCommentId,
120
- createThreadId,
121
- deprecateIf,
122
- errorIf,
123
- kInternal as kInternal2,
124
- makeEventSource,
125
- makePoller as makePoller2,
126
- nn,
127
- NotificationsApiError,
128
- ServerMsgCode,
129
- stringify as stringify2
29
+ assert,
30
+ createClient,
31
+ kInternal,
32
+ makePoller,
33
+ memoizeOnSuccess,
34
+ raise,
35
+ shallow as shallow3,
36
+ stringify
130
37
  } from "@liveblocks/core";
131
- import * as React4 from "react";
132
- import { useSyncExternalStoreWithSelector as useSyncExternalStoreWithSelector2 } from "use-sync-external-store/shim/with-selector.js";
38
+ import React3, {
39
+ createContext as createContext2,
40
+ useCallback as useCallback2,
41
+ useContext as useContext2,
42
+ useEffect as useEffect3,
43
+ useMemo
44
+ } from "react";
45
+ import { useSyncExternalStore } from "use-sync-external-store/shim/index.js";
46
+ import { useSyncExternalStoreWithSelector } from "use-sync-external-store/shim/with-selector.js";
133
47
 
134
48
  // src/lib/compare.ts
135
49
  function byFirstCreated(a, b) {
@@ -204,6 +118,21 @@ async function autoRetry(promiseFn, maxTries, backoff) {
204
118
  }
205
119
  }
206
120
 
121
+ // src/lib/shallow2.ts
122
+ import { isPlainObject as isPlainObject2, shallow } from "@liveblocks/core";
123
+ function shallow2(a, b) {
124
+ if (!isPlainObject2(a) || !isPlainObject2(b)) {
125
+ return shallow(a, b);
126
+ }
127
+ const keysA = Object.keys(a);
128
+ if (keysA.length !== Object.keys(b).length) {
129
+ return false;
130
+ }
131
+ return keysA.every(
132
+ (key) => Object.prototype.hasOwnProperty.call(b, key) && shallow(a[key], b[key])
133
+ );
134
+ }
135
+
207
136
  // src/lib/use-initial.ts
208
137
  import { useCallback, useReducer } from "react";
209
138
 
@@ -261,66 +190,147 @@ var use = (
261
190
  }
262
191
  );
263
192
 
264
- // src/liveblocks.tsx
193
+ // src/umbrella-store.ts
265
194
  import {
266
- assert,
267
- createClient,
268
- kInternal,
269
- makePoller,
270
- memoizeOnSuccess,
271
- raise,
272
- shallow,
273
- stringify
195
+ compactObject,
196
+ console as console2,
197
+ createStore,
198
+ mapValues,
199
+ nanoid,
200
+ nn
274
201
  } from "@liveblocks/core";
275
- import React2, {
276
- createContext,
277
- useCallback as useCallback2,
278
- useContext,
279
- useEffect as useEffect3,
280
- useMemo
281
- } from "react";
282
- import { useSyncExternalStore } from "use-sync-external-store/shim/index.js";
283
- import { useSyncExternalStoreWithSelector } from "use-sync-external-store/shim/with-selector.js";
284
-
285
- // src/umbrella-store.ts
286
- import { console as console2, createStore, mapValues, nanoid } from "@liveblocks/core";
202
+ var QUERY_STATE_LOADING = Object.freeze({ isLoading: true });
203
+ var QUERY_STATE_OK = Object.freeze({ isLoading: false, data: void 0 });
204
+ var INBOX_NOTIFICATIONS_QUERY = "INBOX_NOTIFICATIONS";
205
+ function makeNotificationSettingsQueryKey(roomId) {
206
+ return `${roomId}:NOTIFICATION_SETTINGS`;
207
+ }
208
+ function makeVersionsQueryKey(roomId) {
209
+ return `${roomId}-VERSIONS`;
210
+ }
287
211
  var UmbrellaStore = class {
288
212
  constructor() {
213
+ this._prevState = null;
214
+ this._stateCached = null;
289
215
  this._store = createStore({
290
- threads: {},
216
+ rawThreadsById: {},
291
217
  queries: {},
292
218
  optimisticUpdates: [],
293
- inboxNotifications: {},
294
- notificationSettings: {},
295
- versions: {}
219
+ inboxNotificationsById: {},
220
+ notificationSettingsByRoomId: {},
221
+ versionsByRoomId: {}
296
222
  });
297
- this.get = this.get.bind(this);
298
- this.subscribe = this.subscribe.bind(this);
223
+ this.getThreads = this.getThreads.bind(this);
224
+ this.getInboxNotifications = this.getInboxNotifications.bind(this);
225
+ this.getInboxNotificationsAsync = this.getInboxNotificationsAsync.bind(this);
226
+ this.subscribeThreads = this.subscribeThreads.bind(this);
227
+ this.subscribeInboxNotifications = this.subscribeInboxNotifications.bind(this);
228
+ this.subscribeNotificationSettings = this.subscribeNotificationSettings.bind(this);
229
+ this.subscribeVersions = this.subscribeVersions.bind(this);
230
+ this._hasOptimisticUpdates = this._hasOptimisticUpdates.bind(this);
231
+ this._subscribeOptimisticUpdates = this._subscribeOptimisticUpdates.bind(this);
299
232
  }
300
233
  get() {
301
- return this._store.get();
234
+ const rawState = this._store.get();
235
+ if (this._prevState !== rawState || this._stateCached === null) {
236
+ this._prevState = rawState;
237
+ this._stateCached = internalToExternalState(rawState);
238
+ }
239
+ return this._stateCached;
240
+ }
241
+ getThreads() {
242
+ return this.get();
243
+ }
244
+ getInboxNotifications() {
245
+ return this.get();
246
+ }
247
+ // NOTE: This will read the async result, but WILL NOT start loading at the moment!
248
+ getInboxNotificationsAsync() {
249
+ const internalState = this._store.get();
250
+ const query = internalState.queries[INBOX_NOTIFICATIONS_QUERY];
251
+ if (query === void 0 || query.isLoading) {
252
+ return QUERY_STATE_LOADING;
253
+ }
254
+ if (query.error !== void 0) {
255
+ return query;
256
+ }
257
+ const inboxNotifications = this.get().inboxNotifications;
258
+ return { isLoading: false, inboxNotifications };
259
+ }
260
+ // NOTE: This will read the async result, but WILL NOT start loading at the moment!
261
+ getNotificationSettingsAsync(roomId) {
262
+ const state = this.get();
263
+ const query = state.queries[makeNotificationSettingsQueryKey(roomId)];
264
+ if (query === void 0 || query.isLoading) {
265
+ return QUERY_STATE_LOADING;
266
+ }
267
+ if (query.error !== void 0) {
268
+ return query;
269
+ }
270
+ return {
271
+ isLoading: false,
272
+ settings: nn(state.notificationSettingsByRoomId[roomId])
273
+ };
274
+ }
275
+ getVersionsAsync(roomId) {
276
+ const state = this.get();
277
+ const query = state.queries[makeVersionsQueryKey(roomId)];
278
+ if (query === void 0 || query.isLoading) {
279
+ return QUERY_STATE_LOADING;
280
+ }
281
+ if (query.error !== void 0) {
282
+ return query;
283
+ }
284
+ return {
285
+ isLoading: false,
286
+ versions: nn(state.versionsByRoomId[roomId])
287
+ };
288
+ }
289
+ /**
290
+ * @private Only used by the E2E test suite.
291
+ */
292
+ _hasOptimisticUpdates() {
293
+ return this._store.get().optimisticUpdates.length > 0;
302
294
  }
303
295
  subscribe(callback) {
304
296
  return this._store.subscribe(callback);
305
297
  }
298
+ /**
299
+ * @private Only used by the E2E test suite.
300
+ */
301
+ _subscribeOptimisticUpdates(callback) {
302
+ return this.subscribe(callback);
303
+ }
304
+ subscribeThreads(callback) {
305
+ return this.subscribe(callback);
306
+ }
307
+ subscribeInboxNotifications(callback) {
308
+ return this.subscribe(callback);
309
+ }
310
+ subscribeNotificationSettings(callback) {
311
+ return this.subscribe(callback);
312
+ }
313
+ subscribeVersions(callback) {
314
+ return this.subscribe(callback);
315
+ }
306
316
  // Direct low-level cache mutations ------------------------------------------------- {{{
307
317
  updateThreadsCache(mapFn) {
308
318
  this._store.set((state) => {
309
- const threads = mapFn(state.threads);
310
- return threads !== state.threads ? { ...state, threads } : state;
319
+ const threads = mapFn(state.rawThreadsById);
320
+ return threads !== state.rawThreadsById ? { ...state, rawThreadsById: threads } : state;
311
321
  });
312
322
  }
313
323
  updateInboxNotificationsCache(mapFn) {
314
324
  this._store.set((state) => {
315
- const inboxNotifications = mapFn(state.inboxNotifications);
316
- return inboxNotifications !== state.inboxNotifications ? { ...state, inboxNotifications } : state;
325
+ const inboxNotifications = mapFn(state.inboxNotificationsById);
326
+ return inboxNotifications !== state.inboxNotificationsById ? { ...state, inboxNotificationsById: inboxNotifications } : state;
317
327
  });
318
328
  }
319
329
  setNotificationSettings(roomId, settings) {
320
330
  this._store.set((state) => ({
321
331
  ...state,
322
- notificationSettings: {
323
- ...state.notificationSettings,
332
+ notificationSettingsByRoomId: {
333
+ ...state.notificationSettingsByRoomId,
324
334
  [roomId]: settings
325
335
  }
326
336
  }));
@@ -328,8 +338,8 @@ var UmbrellaStore = class {
328
338
  setVersions(roomId, versions) {
329
339
  this._store.set((state) => ({
330
340
  ...state,
331
- versions: {
332
- ...state.versions,
341
+ versionsByRoomId: {
342
+ ...state.versionsByRoomId,
333
343
  [roomId]: versions
334
344
  }
335
345
  }));
@@ -449,6 +459,30 @@ var UmbrellaStore = class {
449
459
  });
450
460
  });
451
461
  }
462
+ patchThread(threadId, optimisticUpdateId, patch, updatedAt) {
463
+ return this.updateThread(
464
+ threadId,
465
+ optimisticUpdateId,
466
+ (thread) => ({ ...thread, ...compactObject(patch) }),
467
+ updatedAt
468
+ );
469
+ }
470
+ addReaction(threadId, optimisticUpdateId, commentId, reaction, createdAt) {
471
+ this.updateThread(
472
+ threadId,
473
+ optimisticUpdateId,
474
+ (thread) => applyAddReaction(thread, commentId, reaction),
475
+ createdAt
476
+ );
477
+ }
478
+ removeReaction(threadId, optimisticUpdateId, commentId, emoji, userId, removedAt) {
479
+ this.updateThread(
480
+ threadId,
481
+ optimisticUpdateId,
482
+ (thread) => applyRemoveReaction(thread, commentId, emoji, userId, removedAt),
483
+ removedAt
484
+ );
485
+ }
452
486
  /**
453
487
  * Soft-deletes an existing thread by setting its `deletedAt` value,
454
488
  * replacing the corresponding optimistic update.
@@ -472,13 +506,13 @@ var UmbrellaStore = class {
472
506
  createComment(newComment, optimisticUpdateId) {
473
507
  this._store.batch(() => {
474
508
  this.removeOptimisticUpdate(optimisticUpdateId);
475
- const existingThread = this._store.get().threads[newComment.threadId];
509
+ const existingThread = this._store.get().rawThreadsById[newComment.threadId];
476
510
  if (!existingThread) {
477
511
  return;
478
512
  }
479
513
  this.updateThreadsCache((cache) => ({
480
514
  ...cache,
481
- [newComment.threadId]: upsertComment(existingThread, newComment)
515
+ [newComment.threadId]: applyUpsertComment(existingThread, newComment)
482
516
  }));
483
517
  this.updateInboxNotificationsCache((cache) => {
484
518
  const existingNotification = Object.values(cache).find(
@@ -498,6 +532,21 @@ var UmbrellaStore = class {
498
532
  });
499
533
  });
500
534
  }
535
+ editComment(threadId, optimisticUpdateId, editedComment) {
536
+ return this.updateThread(
537
+ threadId,
538
+ optimisticUpdateId,
539
+ (thread) => applyUpsertComment(thread, editedComment)
540
+ );
541
+ }
542
+ deleteComment(threadId, optimisticUpdateId, commentId, deletedAt) {
543
+ return this.updateThread(
544
+ threadId,
545
+ optimisticUpdateId,
546
+ (thread) => applyDeleteComment(thread, commentId, deletedAt),
547
+ deletedAt
548
+ );
549
+ }
501
550
  updateThreadAndNotification(thread, inboxNotification) {
502
551
  this._store.batch(() => {
503
552
  this.updateThreadsCache((cache) => {
@@ -570,35 +619,29 @@ var UmbrellaStore = class {
570
619
  // Query State APIs
571
620
  //
572
621
  setQueryLoading(queryKey) {
573
- this.setQueryState(queryKey, { isLoading: true });
622
+ this.setQueryState(queryKey, QUERY_STATE_LOADING);
574
623
  }
575
624
  setQueryOK(queryKey) {
576
- this.setQueryState(queryKey, { isLoading: false, data: void 0 });
625
+ this.setQueryState(queryKey, QUERY_STATE_OK);
577
626
  }
578
627
  setQueryError(queryKey, error) {
579
628
  this.setQueryState(queryKey, { isLoading: false, error });
580
629
  }
581
630
  };
582
- function applyOptimisticUpdates(state) {
583
- const result = {
584
- threads: {
585
- ...state.threads
586
- },
587
- inboxNotifications: {
588
- ...state.inboxNotifications
589
- },
590
- notificationSettings: {
591
- ...state.notificationSettings
592
- }
631
+ function internalToExternalState(state) {
632
+ const computed = {
633
+ threadsById: { ...state.rawThreadsById },
634
+ inboxNotificationsById: { ...state.inboxNotificationsById },
635
+ notificationSettingsByRoomId: { ...state.notificationSettingsByRoomId }
593
636
  };
594
637
  for (const optimisticUpdate of state.optimisticUpdates) {
595
638
  switch (optimisticUpdate.type) {
596
639
  case "create-thread": {
597
- result.threads[optimisticUpdate.thread.id] = optimisticUpdate.thread;
640
+ computed.threadsById[optimisticUpdate.thread.id] = optimisticUpdate.thread;
598
641
  break;
599
642
  }
600
643
  case "edit-thread-metadata": {
601
- const thread = result.threads[optimisticUpdate.threadId];
644
+ const thread = computed.threadsById[optimisticUpdate.threadId];
602
645
  if (thread === void 0) {
603
646
  break;
604
647
  }
@@ -608,7 +651,7 @@ function applyOptimisticUpdates(state) {
608
651
  if (thread.updatedAt !== void 0 && thread.updatedAt > optimisticUpdate.updatedAt) {
609
652
  break;
610
653
  }
611
- result.threads[thread.id] = {
654
+ computed.threadsById[thread.id] = {
612
655
  ...thread,
613
656
  updatedAt: optimisticUpdate.updatedAt,
614
657
  metadata: {
@@ -619,49 +662,51 @@ function applyOptimisticUpdates(state) {
619
662
  break;
620
663
  }
621
664
  case "mark-thread-as-resolved": {
622
- const thread = result.threads[optimisticUpdate.threadId];
665
+ const thread = computed.threadsById[optimisticUpdate.threadId];
623
666
  if (thread === void 0) {
624
667
  break;
625
668
  }
626
669
  if (thread.deletedAt !== void 0) {
627
670
  break;
628
671
  }
629
- result.threads[thread.id] = {
672
+ computed.threadsById[thread.id] = {
630
673
  ...thread,
631
674
  resolved: true
632
675
  };
633
676
  break;
634
677
  }
635
678
  case "mark-thread-as-unresolved": {
636
- const thread = result.threads[optimisticUpdate.threadId];
679
+ const thread = computed.threadsById[optimisticUpdate.threadId];
637
680
  if (thread === void 0) {
638
681
  break;
639
682
  }
640
683
  if (thread.deletedAt !== void 0) {
641
684
  break;
642
685
  }
643
- result.threads[thread.id] = {
686
+ computed.threadsById[thread.id] = {
644
687
  ...thread,
645
688
  resolved: false
646
689
  };
647
690
  break;
648
691
  }
649
692
  case "create-comment": {
650
- const thread = result.threads[optimisticUpdate.comment.threadId];
693
+ const thread = computed.threadsById[optimisticUpdate.comment.threadId];
651
694
  if (thread === void 0) {
652
695
  break;
653
696
  }
654
- result.threads[thread.id] = upsertComment(
697
+ computed.threadsById[thread.id] = applyUpsertComment(
655
698
  thread,
656
699
  optimisticUpdate.comment
657
700
  );
658
- const inboxNotification = Object.values(result.inboxNotifications).find(
701
+ const inboxNotification = Object.values(
702
+ computed.inboxNotificationsById
703
+ ).find(
659
704
  (notification) => notification.kind === "thread" && notification.threadId === thread.id
660
705
  );
661
706
  if (inboxNotification === void 0) {
662
707
  break;
663
708
  }
664
- result.inboxNotifications[inboxNotification.id] = {
709
+ computed.inboxNotificationsById[inboxNotification.id] = {
665
710
  ...inboxNotification,
666
711
  notifiedAt: optimisticUpdate.comment.createdAt,
667
712
  readAt: optimisticUpdate.comment.createdAt
@@ -669,22 +714,22 @@ function applyOptimisticUpdates(state) {
669
714
  break;
670
715
  }
671
716
  case "edit-comment": {
672
- const thread = result.threads[optimisticUpdate.comment.threadId];
717
+ const thread = computed.threadsById[optimisticUpdate.comment.threadId];
673
718
  if (thread === void 0) {
674
719
  break;
675
720
  }
676
- result.threads[thread.id] = upsertComment(
721
+ computed.threadsById[thread.id] = applyUpsertComment(
677
722
  thread,
678
723
  optimisticUpdate.comment
679
724
  );
680
725
  break;
681
726
  }
682
727
  case "delete-comment": {
683
- const thread = result.threads[optimisticUpdate.threadId];
728
+ const thread = computed.threadsById[optimisticUpdate.threadId];
684
729
  if (thread === void 0) {
685
730
  break;
686
731
  }
687
- result.threads[thread.id] = deleteComment(
732
+ computed.threadsById[thread.id] = applyDeleteComment(
688
733
  thread,
689
734
  optimisticUpdate.commentId,
690
735
  optimisticUpdate.deletedAt
@@ -692,12 +737,12 @@ function applyOptimisticUpdates(state) {
692
737
  break;
693
738
  }
694
739
  case "delete-thread": {
695
- const thread = result.threads[optimisticUpdate.threadId];
740
+ const thread = computed.threadsById[optimisticUpdate.threadId];
696
741
  if (thread === void 0) {
697
742
  break;
698
743
  }
699
- result.threads[optimisticUpdate.threadId] = {
700
- ...result.threads[optimisticUpdate.threadId],
744
+ computed.threadsById[optimisticUpdate.threadId] = {
745
+ ...thread,
701
746
  deletedAt: optimisticUpdate.deletedAt,
702
747
  updatedAt: optimisticUpdate.deletedAt,
703
748
  comments: []
@@ -705,11 +750,11 @@ function applyOptimisticUpdates(state) {
705
750
  break;
706
751
  }
707
752
  case "add-reaction": {
708
- const thread = result.threads[optimisticUpdate.threadId];
753
+ const thread = computed.threadsById[optimisticUpdate.threadId];
709
754
  if (thread === void 0) {
710
755
  break;
711
756
  }
712
- result.threads[thread.id] = addReaction(
757
+ computed.threadsById[thread.id] = applyAddReaction(
713
758
  thread,
714
759
  optimisticUpdate.commentId,
715
760
  optimisticUpdate.reaction
@@ -717,11 +762,11 @@ function applyOptimisticUpdates(state) {
717
762
  break;
718
763
  }
719
764
  case "remove-reaction": {
720
- const thread = result.threads[optimisticUpdate.threadId];
765
+ const thread = computed.threadsById[optimisticUpdate.threadId];
721
766
  if (thread === void 0) {
722
767
  break;
723
768
  }
724
- result.threads[thread.id] = removeReaction(
769
+ computed.threadsById[thread.id] = applyRemoveReaction(
725
770
  thread,
726
771
  optimisticUpdate.commentId,
727
772
  optimisticUpdate.emoji,
@@ -731,42 +776,70 @@ function applyOptimisticUpdates(state) {
731
776
  break;
732
777
  }
733
778
  case "mark-inbox-notification-as-read": {
734
- result.inboxNotifications[optimisticUpdate.inboxNotificationId] = {
735
- ...state.inboxNotifications[optimisticUpdate.inboxNotificationId],
736
- readAt: optimisticUpdate.readAt
737
- };
779
+ const ibn = computed.inboxNotificationsById[optimisticUpdate.inboxNotificationId];
780
+ if (ibn === void 0) {
781
+ break;
782
+ }
783
+ computed.inboxNotificationsById[optimisticUpdate.inboxNotificationId] = { ...ibn, readAt: optimisticUpdate.readAt };
738
784
  break;
739
785
  }
740
786
  case "mark-all-inbox-notifications-as-read": {
741
- for (const id in result.inboxNotifications) {
742
- result.inboxNotifications[id] = {
743
- ...result.inboxNotifications[id],
787
+ for (const id in computed.inboxNotificationsById) {
788
+ const ibn = computed.inboxNotificationsById[id];
789
+ if (ibn === void 0) {
790
+ break;
791
+ }
792
+ computed.inboxNotificationsById[id] = {
793
+ ...ibn,
744
794
  readAt: optimisticUpdate.readAt
745
795
  };
746
796
  }
747
797
  break;
748
798
  }
749
799
  case "delete-inbox-notification": {
750
- const {
751
- [optimisticUpdate.inboxNotificationId]: _,
752
- ...inboxNotifications
753
- } = result.inboxNotifications;
754
- result.inboxNotifications = inboxNotifications;
800
+ delete computed.inboxNotificationsById[optimisticUpdate.inboxNotificationId];
755
801
  break;
756
802
  }
757
803
  case "delete-all-inbox-notifications": {
758
- result.inboxNotifications = {};
804
+ computed.inboxNotificationsById = {};
759
805
  break;
760
806
  }
761
807
  case "update-notification-settings": {
762
- result.notificationSettings[optimisticUpdate.roomId] = {
763
- ...result.notificationSettings[optimisticUpdate.roomId],
808
+ const settings = computed.notificationSettingsByRoomId[optimisticUpdate.roomId];
809
+ if (settings === void 0) {
810
+ break;
811
+ }
812
+ computed.notificationSettingsByRoomId[optimisticUpdate.roomId] = {
813
+ ...settings,
764
814
  ...optimisticUpdate.settings
765
815
  };
766
816
  }
767
817
  }
768
818
  }
769
- return result;
819
+ const cleanedThreads = (
820
+ // Don't expose any soft-deleted threads
821
+ Object.values(computed.threadsById).filter((thread) => !thread.deletedAt).filter(
822
+ (thread) => (
823
+ // Only keep a thread if there is at least one non-deleted comment
824
+ thread.comments.some((c) => c.deletedAt === void 0)
825
+ )
826
+ )
827
+ );
828
+ const cleanedNotifications = (
829
+ // Sort so that the most recent notifications are first
830
+ Object.values(computed.inboxNotificationsById).filter(
831
+ (ibn) => ibn.kind === "thread" ? computed.threadsById[ibn.threadId] && computed.threadsById[ibn.threadId]?.deletedAt === void 0 : true
832
+ ).sort((a, b) => b.notifiedAt.getTime() - a.notifiedAt.getTime())
833
+ );
834
+ return {
835
+ inboxNotifications: cleanedNotifications,
836
+ inboxNotificationsById: computed.inboxNotificationsById,
837
+ notificationSettingsByRoomId: computed.notificationSettingsByRoomId,
838
+ queries: state.queries,
839
+ threads: cleanedThreads,
840
+ threadsById: computed.threadsById,
841
+ versionsByRoomId: state.versionsByRoomId
842
+ };
770
843
  }
771
844
  function applyThreadUpdates(existingThreads, updates) {
772
845
  const updatedThreads = { ...existingThreads };
@@ -819,7 +892,7 @@ function compareInboxNotifications(inboxNotificationA, inboxNotificationB) {
819
892
  }
820
893
  return 0;
821
894
  }
822
- function upsertComment(thread, comment) {
895
+ function applyUpsertComment(thread, comment) {
823
896
  if (thread.deletedAt !== void 0) {
824
897
  return thread;
825
898
  }
@@ -864,7 +937,7 @@ function upsertComment(thread, comment) {
864
937
  }
865
938
  return thread;
866
939
  }
867
- function deleteComment(thread, commentId, deletedAt) {
940
+ function applyDeleteComment(thread, commentId, deletedAt) {
868
941
  if (thread.deletedAt !== void 0) {
869
942
  return thread;
870
943
  }
@@ -884,12 +957,11 @@ function deleteComment(thread, commentId, deletedAt) {
884
957
  body: void 0
885
958
  } : comment
886
959
  );
887
- if (!updatedComments.some((comment) => comment.deletedAt === void 0)) {
960
+ if (updatedComments.every((comment) => comment.deletedAt !== void 0)) {
888
961
  return {
889
962
  ...thread,
890
963
  deletedAt,
891
- updatedAt: deletedAt,
892
- comments: []
964
+ updatedAt: deletedAt
893
965
  };
894
966
  }
895
967
  return {
@@ -898,7 +970,7 @@ function deleteComment(thread, commentId, deletedAt) {
898
970
  comments: updatedComments
899
971
  };
900
972
  }
901
- function addReaction(thread, commentId, reaction) {
973
+ function applyAddReaction(thread, commentId, reaction) {
902
974
  if (thread.deletedAt !== void 0) {
903
975
  return thread;
904
976
  }
@@ -925,7 +997,7 @@ function addReaction(thread, commentId, reaction) {
925
997
  comments: updatedComments
926
998
  };
927
999
  }
928
- function removeReaction(thread, commentId, emoji, userId, removedAt) {
1000
+ function applyRemoveReaction(thread, commentId, emoji, userId, removedAt) {
929
1001
  if (thread.deletedAt !== void 0) {
930
1002
  return thread;
931
1003
  }
@@ -984,7 +1056,7 @@ function upsertReaction(reactions, reaction) {
984
1056
  }
985
1057
 
986
1058
  // src/liveblocks.tsx
987
- var ClientContext = createContext(null);
1059
+ var ClientContext = createContext2(null);
988
1060
  function missingUserError(userId) {
989
1061
  return new Error(`resolveUsers didn't return anything for user '${userId}'`);
990
1062
  }
@@ -993,66 +1065,30 @@ function missingRoomInfoError(roomId) {
993
1065
  `resolveRoomsInfo didn't return anything for room '${roomId}'`
994
1066
  );
995
1067
  }
1068
+ function identity(x) {
1069
+ return x;
1070
+ }
996
1071
  var _umbrellaStores = /* @__PURE__ */ new WeakMap();
997
1072
  var _extras = /* @__PURE__ */ new WeakMap();
998
1073
  var _bundles = /* @__PURE__ */ new WeakMap();
999
1074
  var POLLING_INTERVAL = 60 * 1e3;
1000
- var INBOX_NOTIFICATIONS_QUERY = "INBOX_NOTIFICATIONS";
1001
1075
  var USER_THREADS_QUERY = "USER_THREADS";
1002
- function selectorFor_useInboxNotifications(state) {
1003
- const query = state.queries[INBOX_NOTIFICATIONS_QUERY];
1004
- if (query === void 0 || query.isLoading) {
1005
- return {
1006
- isLoading: true
1007
- };
1008
- }
1009
- if (query.error !== void 0) {
1010
- return {
1011
- error: query.error,
1012
- isLoading: false
1013
- };
1014
- }
1015
- return {
1016
- inboxNotifications: selectInboxNotifications(state),
1017
- isLoading: false
1018
- };
1019
- }
1020
- function selectUserThreads(state, options) {
1021
- const result = applyOptimisticUpdates(state);
1022
- let threads = Object.values(result.threads).filter(
1023
- (thread) => !thread.deletedAt
1024
- );
1025
- const query = options.query;
1026
- if (query) {
1027
- threads = threads.filter(makeThreadsFilter(query));
1028
- }
1029
- return threads.sort(byMostRecentlyUpdated);
1030
- }
1031
- function selectUnreadInboxNotificationsCount(state) {
1076
+ function selectUnreadInboxNotificationsCount(inboxNotifications) {
1032
1077
  let count = 0;
1033
- for (const notification of selectInboxNotifications(state)) {
1078
+ for (const notification of inboxNotifications) {
1034
1079
  if (notification.readAt === null || notification.readAt < notification.notifiedAt) {
1035
1080
  count++;
1036
1081
  }
1037
1082
  }
1038
1083
  return count;
1039
1084
  }
1040
- function selectorFor_useUnreadInboxNotificationsCount(state) {
1041
- const query = state.queries[INBOX_NOTIFICATIONS_QUERY];
1042
- if (query === void 0 || query.isLoading) {
1043
- return {
1044
- isLoading: true
1045
- };
1046
- }
1047
- if (query.error !== void 0) {
1048
- return {
1049
- error: query.error,
1050
- isLoading: false
1051
- };
1085
+ function selectorFor_useUnreadInboxNotificationsCount(result) {
1086
+ if (!result.inboxNotifications) {
1087
+ return result;
1052
1088
  }
1053
1089
  return {
1054
1090
  isLoading: false,
1055
- count: selectUnreadInboxNotificationsCount(state)
1091
+ count: selectUnreadInboxNotificationsCount(result.inboxNotifications)
1056
1092
  };
1057
1093
  }
1058
1094
  function selectorFor_useUser(state, userId) {
@@ -1091,11 +1127,17 @@ function selectorFor_useRoomInfo(state, roomId) {
1091
1127
  info: state.data
1092
1128
  };
1093
1129
  }
1094
- function selectInboxNotifications(state) {
1095
- const result = applyOptimisticUpdates(state);
1096
- return Object.values(result.inboxNotifications).sort(
1097
- // Sort so that the most recent notifications are first
1098
- (a, b) => b.notifiedAt.getTime() - a.notifiedAt.getTime()
1130
+ function selectThreads(state, options) {
1131
+ let threads = state.threads;
1132
+ if (options.roomId !== null) {
1133
+ threads = threads.filter((thread) => thread.roomId === options.roomId);
1134
+ }
1135
+ const query = options.query;
1136
+ if (query) {
1137
+ threads = threads.filter(makeThreadsFilter(query));
1138
+ }
1139
+ return threads.sort(
1140
+ options.orderBy === "last-update" ? byMostRecentlyUpdated : byFirstCreated
1099
1141
  );
1100
1142
  }
1101
1143
  function getOrCreateContextBundle(client) {
@@ -1178,23 +1220,21 @@ function makeExtrasForClient(client) {
1178
1220
  void waitUntilInboxNotificationsLoaded().catch(() => {
1179
1221
  });
1180
1222
  }
1181
- function useEnableInboxNotificationsPolling() {
1182
- useEffect3(() => {
1183
- pollerSubscribers++;
1184
- poller.start(POLLING_INTERVAL);
1185
- return () => {
1186
- if (pollerSubscribers <= 0) {
1187
- console.warn(
1188
- `Internal unexpected behavior. Cannot decrease subscriber count for query "${INBOX_NOTIFICATIONS_QUERY}"`
1189
- );
1190
- return;
1191
- }
1192
- pollerSubscribers--;
1193
- if (pollerSubscribers <= 0) {
1194
- poller.stop();
1195
- }
1196
- };
1197
- }, []);
1223
+ function startPolling() {
1224
+ pollerSubscribers++;
1225
+ poller.start(POLLING_INTERVAL);
1226
+ return () => {
1227
+ if (pollerSubscribers <= 0) {
1228
+ console.warn(
1229
+ `Internal unexpected behavior. Cannot decrease subscriber count for query "${INBOX_NOTIFICATIONS_QUERY}"`
1230
+ );
1231
+ return;
1232
+ }
1233
+ pollerSubscribers--;
1234
+ if (pollerSubscribers <= 0) {
1235
+ poller.stop();
1236
+ }
1237
+ };
1198
1238
  }
1199
1239
  const userThreadsPoller = makePoller(refreshUserThreads);
1200
1240
  let isFetchingUserThreadsUpdates = false;
@@ -1279,7 +1319,7 @@ function makeExtrasForClient(client) {
1279
1319
  }
1280
1320
  return {
1281
1321
  store,
1282
- useEnableInboxNotificationsPolling,
1322
+ startPolling,
1283
1323
  waitUntilInboxNotificationsLoaded,
1284
1324
  loadInboxNotifications,
1285
1325
  incrementUserThreadsQuerySubscribers,
@@ -1294,7 +1334,7 @@ function makeLiveblocksContextBundle(client) {
1294
1334
  const useDeleteAllInboxNotifications2 = () => useDeleteAllInboxNotifications_withClient(client);
1295
1335
  function LiveblocksProvider2(props) {
1296
1336
  useEnsureNoLiveblocksProvider();
1297
- return /* @__PURE__ */ React2.createElement(ClientContext.Provider, { value: client }, props.children);
1337
+ return /* @__PURE__ */ React3.createElement(ClientContext.Provider, { value: client }, props.children);
1298
1338
  }
1299
1339
  const shared = createSharedContext(client);
1300
1340
  const bundle = {
@@ -1324,17 +1364,15 @@ function makeLiveblocksContextBundle(client) {
1324
1364
  return bundle;
1325
1365
  }
1326
1366
  function useInboxNotifications_withClient(client) {
1327
- const { loadInboxNotifications, store, useEnableInboxNotificationsPolling } = getExtrasForClient(client);
1328
- useEffect3(() => {
1329
- loadInboxNotifications();
1330
- }, [loadInboxNotifications]);
1331
- useEnableInboxNotificationsPolling();
1367
+ const { loadInboxNotifications, store, startPolling } = getExtrasForClient(client);
1368
+ useEffect3(loadInboxNotifications, [loadInboxNotifications]);
1369
+ useEffect3(startPolling, [startPolling]);
1332
1370
  return useSyncExternalStoreWithSelector(
1333
- store.subscribe,
1334
- store.get,
1335
- store.get,
1336
- selectorFor_useInboxNotifications,
1337
- shallow
1371
+ store.subscribeInboxNotifications,
1372
+ store.getInboxNotificationsAsync,
1373
+ store.getInboxNotificationsAsync,
1374
+ identity,
1375
+ shallow3
1338
1376
  );
1339
1377
  }
1340
1378
  function useInboxNotificationsSuspense_withClient(client) {
@@ -1346,17 +1384,15 @@ function useInboxNotificationsSuspense_withClient(client) {
1346
1384
  return result;
1347
1385
  }
1348
1386
  function useUnreadInboxNotificationsCount_withClient(client) {
1349
- const { store, loadInboxNotifications, useEnableInboxNotificationsPolling } = getExtrasForClient(client);
1350
- useEffect3(() => {
1351
- loadInboxNotifications();
1352
- }, [loadInboxNotifications]);
1353
- useEnableInboxNotificationsPolling();
1387
+ const { store, loadInboxNotifications, startPolling } = getExtrasForClient(client);
1388
+ useEffect3(loadInboxNotifications, [loadInboxNotifications]);
1389
+ useEffect3(startPolling, [startPolling]);
1354
1390
  return useSyncExternalStoreWithSelector(
1355
- store.subscribe,
1356
- store.get,
1357
- store.get,
1391
+ store.subscribeInboxNotifications,
1392
+ store.getInboxNotificationsAsync,
1393
+ store.getInboxNotificationsAsync,
1358
1394
  selectorFor_useUnreadInboxNotificationsCount,
1359
- shallow
1395
+ shallow3
1360
1396
  );
1361
1397
  }
1362
1398
  function useUnreadInboxNotificationsCountSuspense_withClient(client) {
@@ -1461,13 +1497,13 @@ function useInboxNotificationThread_withClient(client, inboxNotificationId) {
1461
1497
  const { store } = getExtrasForClient(client);
1462
1498
  const selector = useCallback2(
1463
1499
  (state) => {
1464
- const inboxNotification = state.inboxNotifications[inboxNotificationId] ?? raise(`Inbox notification with ID "${inboxNotificationId}" not found`);
1500
+ const inboxNotification = state.inboxNotificationsById[inboxNotificationId] ?? raise(`Inbox notification with ID "${inboxNotificationId}" not found`);
1465
1501
  if (inboxNotification.kind !== "thread") {
1466
1502
  raise(
1467
1503
  `Inbox notification with ID "${inboxNotificationId}" is not of kind "thread"`
1468
1504
  );
1469
1505
  }
1470
- const thread = state.threads[inboxNotification.threadId] ?? raise(
1506
+ const thread = state.threadsById[inboxNotification.threadId] ?? raise(
1471
1507
  `Thread with ID "${inboxNotification.threadId}" not found, this inbox notification might not be of kind "thread"`
1472
1508
  );
1473
1509
  return thread;
@@ -1475,9 +1511,9 @@ function useInboxNotificationThread_withClient(client, inboxNotificationId) {
1475
1511
  [inboxNotificationId]
1476
1512
  );
1477
1513
  return useSyncExternalStoreWithSelector(
1478
- store.subscribe,
1479
- store.get,
1480
- store.get,
1514
+ store.subscribeInboxNotifications,
1515
+ store.getInboxNotifications,
1516
+ store.getInboxNotifications,
1481
1517
  selector
1482
1518
  );
1483
1519
  }
@@ -1499,7 +1535,7 @@ function useUser_withClient(client, userId) {
1499
1535
  getUserState,
1500
1536
  getUserState,
1501
1537
  selector,
1502
- shallow
1538
+ shallow3
1503
1539
  );
1504
1540
  }
1505
1541
  function useUserSuspense_withClient(client, userId) {
@@ -1550,7 +1586,7 @@ function useRoomInfo_withClient(client, roomId) {
1550
1586
  getRoomInfoState,
1551
1587
  getRoomInfoState,
1552
1588
  selector,
1553
- shallow
1589
+ shallow3
1554
1590
  );
1555
1591
  }
1556
1592
  function useRoomInfoSuspense_withClient(client, roomId) {
@@ -1591,13 +1627,13 @@ function createSharedContext(client) {
1591
1627
  useClient: useClient2,
1592
1628
  useUser: (userId) => useUser_withClient(client, userId),
1593
1629
  useRoomInfo: (roomId) => useRoomInfo_withClient(client, roomId),
1594
- useIsInsideRoom: _useIsInsideRoom
1630
+ useIsInsideRoom
1595
1631
  },
1596
1632
  suspense: {
1597
1633
  useClient: useClient2,
1598
1634
  useUser: (userId) => useUserSuspense_withClient(client, userId),
1599
1635
  useRoomInfo: (roomId) => useRoomInfoSuspense_withClient(client, roomId),
1600
- useIsInsideRoom: _useIsInsideRoom
1636
+ useIsInsideRoom
1601
1637
  }
1602
1638
  };
1603
1639
  }
@@ -1610,14 +1646,14 @@ function useEnsureNoLiveblocksProvider(options) {
1610
1646
  }
1611
1647
  }
1612
1648
  function useClientOrNull() {
1613
- return useContext(ClientContext);
1649
+ return useContext2(ClientContext);
1614
1650
  }
1615
1651
  function useClient() {
1616
1652
  return useClientOrNull() ?? raise("LiveblocksProvider is missing from the React tree.");
1617
1653
  }
1618
1654
  function LiveblocksProviderWithClient(props) {
1619
1655
  useEnsureNoLiveblocksProvider(props);
1620
- return /* @__PURE__ */ React2.createElement(ClientContext.Provider, { value: props.client }, props.children);
1656
+ return /* @__PURE__ */ React3.createElement(ClientContext.Provider, { value: props.client }, props.children);
1621
1657
  }
1622
1658
  function LiveblocksProvider(props) {
1623
1659
  const { children, ...o } = props;
@@ -1645,7 +1681,7 @@ function LiveblocksProvider(props) {
1645
1681
  )
1646
1682
  };
1647
1683
  const client = useMemo(() => createClient(options), []);
1648
- return /* @__PURE__ */ React2.createElement(LiveblocksProviderWithClient, { client }, children);
1684
+ return /* @__PURE__ */ React3.createElement(LiveblocksProviderWithClient, { client }, children);
1649
1685
  }
1650
1686
  function createLiveblocksContext(client) {
1651
1687
  return getOrCreateContextBundle(client);
@@ -1655,7 +1691,7 @@ function useUserThreads_experimental(options = {
1655
1691
  metadata: {}
1656
1692
  }
1657
1693
  }) {
1658
- const queryKey = React2.useMemo(
1694
+ const queryKey = React3.useMemo(
1659
1695
  () => makeUserThreadsQueryKey(options.query),
1660
1696
  [options]
1661
1697
  );
@@ -1681,18 +1717,24 @@ function useUserThreads_experimental(options = {
1681
1717
  };
1682
1718
  }
1683
1719
  return {
1684
- threads: selectUserThreads(state, options),
1720
+ threads: selectThreads(state, {
1721
+ roomId: null,
1722
+ // Do _not_ filter by roomId
1723
+ query: options.query,
1724
+ orderBy: "last-update"
1725
+ }),
1685
1726
  isLoading: false
1686
1727
  };
1687
1728
  },
1688
1729
  [queryKey, options]
1689
1730
  );
1690
1731
  return useSyncExternalStoreWithSelector(
1691
- store.subscribe,
1692
- store.get,
1693
- store.get,
1732
+ store.subscribeThreads,
1733
+ store.getThreads,
1734
+ store.getThreads,
1694
1735
  selector,
1695
- shallow
1736
+ shallow2
1737
+ // NOTE: Using 2-level-deep shallow check here, because the result of selectThreads() is not stable!
1696
1738
  );
1697
1739
  }
1698
1740
  function useUserThreadsSuspense_experimental(options = {
@@ -1700,93 +1742,216 @@ function useUserThreadsSuspense_experimental(options = {
1700
1742
  metadata: {}
1701
1743
  }
1702
1744
  }) {
1703
- const queryKey = React2.useMemo(
1745
+ const queryKey = React3.useMemo(
1704
1746
  () => makeUserThreadsQueryKey(options.query),
1705
1747
  [options]
1706
1748
  );
1707
1749
  const client = useClient();
1708
1750
  const { store, getUserThreads } = getExtrasForClient(client);
1709
- React2.useEffect(() => {
1751
+ React3.useEffect(() => {
1710
1752
  const { incrementUserThreadsQuerySubscribers } = getExtrasForClient(client);
1711
1753
  return incrementUserThreadsQuerySubscribers(queryKey);
1712
1754
  }, [client, queryKey]);
1713
- const query = store.get().queries[queryKey];
1755
+ const query = store.getThreads().queries[queryKey];
1714
1756
  if (query === void 0 || query.isLoading) {
1715
1757
  throw getUserThreads(queryKey, options);
1716
1758
  }
1717
- if (query.error) {
1718
- throw query.error;
1759
+ if (query.error) {
1760
+ throw query.error;
1761
+ }
1762
+ const selector = useCallback2(
1763
+ (state) => {
1764
+ return {
1765
+ threads: selectThreads(state, {
1766
+ roomId: null,
1767
+ // Do _not_ filter by roomId
1768
+ query: options.query,
1769
+ orderBy: "last-update"
1770
+ }),
1771
+ isLoading: false
1772
+ };
1773
+ },
1774
+ [options]
1775
+ );
1776
+ return useSyncExternalStoreWithSelector(
1777
+ store.subscribeThreads,
1778
+ store.getThreads,
1779
+ store.getThreads,
1780
+ selector,
1781
+ shallow2
1782
+ // NOTE: Using 2-level-deep shallow check here, because the result of selectThreads() is not stable!
1783
+ );
1784
+ }
1785
+ function useInboxNotifications() {
1786
+ return useInboxNotifications_withClient(useClient());
1787
+ }
1788
+ function useInboxNotificationsSuspense() {
1789
+ return useInboxNotificationsSuspense_withClient(useClient());
1790
+ }
1791
+ function useInboxNotificationThread(inboxNotificationId) {
1792
+ return useInboxNotificationThread_withClient(
1793
+ useClient(),
1794
+ inboxNotificationId
1795
+ );
1796
+ }
1797
+ function useMarkAllInboxNotificationsAsRead() {
1798
+ return useMarkAllInboxNotificationsAsRead_withClient(useClient());
1799
+ }
1800
+ function useMarkInboxNotificationAsRead() {
1801
+ return useMarkInboxNotificationAsRead_withClient(useClient());
1802
+ }
1803
+ function useDeleteAllInboxNotifications() {
1804
+ return useDeleteAllInboxNotifications_withClient(useClient());
1805
+ }
1806
+ function useDeleteInboxNotification() {
1807
+ return useDeleteInboxNotification_withClient(useClient());
1808
+ }
1809
+ function useUnreadInboxNotificationsCount() {
1810
+ return useUnreadInboxNotificationsCount_withClient(useClient());
1811
+ }
1812
+ function useUnreadInboxNotificationsCountSuspense() {
1813
+ return useUnreadInboxNotificationsCountSuspense_withClient(useClient());
1814
+ }
1815
+ function useUser(userId) {
1816
+ const client = useClient();
1817
+ return useUser_withClient(client, userId);
1818
+ }
1819
+ function useUserSuspense(userId) {
1820
+ const client = useClient();
1821
+ return useUserSuspense_withClient(client, userId);
1822
+ }
1823
+ function useRoomInfo(roomId) {
1824
+ return useRoomInfo_withClient(useClient(), roomId);
1825
+ }
1826
+ function useRoomInfoSuspense(roomId) {
1827
+ return useRoomInfoSuspense_withClient(useClient(), roomId);
1828
+ }
1829
+ var _useInboxNotificationThread = useInboxNotificationThread;
1830
+ var _useUser = useUser;
1831
+ var _useUserSuspense = useUserSuspense;
1832
+ var _useUserThreads_experimental = useUserThreads_experimental;
1833
+ var _useUserThreadsSuspense_experimental = useUserThreadsSuspense_experimental;
1834
+ var makeUserThreadsQueryKey = (options) => `${USER_THREADS_QUERY}:${stringify(options)}`;
1835
+
1836
+ // src/types/errors.ts
1837
+ var CreateThreadError = class extends Error {
1838
+ constructor(cause, context) {
1839
+ super("Create thread failed.");
1840
+ this.cause = cause;
1841
+ this.context = context;
1842
+ this.name = "CreateThreadError";
1843
+ }
1844
+ };
1845
+ var DeleteThreadError = class extends Error {
1846
+ constructor(cause, context) {
1847
+ super("Delete thread failed.");
1848
+ this.cause = cause;
1849
+ this.context = context;
1850
+ this.name = "DeleteThreadError";
1851
+ }
1852
+ };
1853
+ var EditThreadMetadataError = class extends Error {
1854
+ constructor(cause, context) {
1855
+ super("Edit thread metadata failed.");
1856
+ this.cause = cause;
1857
+ this.context = context;
1858
+ this.name = "EditThreadMetadataError";
1859
+ }
1860
+ };
1861
+ var MarkThreadAsResolvedError = class extends Error {
1862
+ constructor(cause, context) {
1863
+ super("Mark thread as resolved failed.");
1864
+ this.cause = cause;
1865
+ this.context = context;
1866
+ this.name = "MarkThreadAsResolvedError";
1867
+ }
1868
+ };
1869
+ var MarkThreadAsUnresolvedError = class extends Error {
1870
+ constructor(cause, context) {
1871
+ super("Mark thread as unresolved failed.");
1872
+ this.cause = cause;
1873
+ this.context = context;
1874
+ this.name = "MarkThreadAsUnresolvedError";
1875
+ }
1876
+ };
1877
+ var CreateCommentError = class extends Error {
1878
+ constructor(cause, context) {
1879
+ super("Create comment failed.");
1880
+ this.cause = cause;
1881
+ this.context = context;
1882
+ this.name = "CreateCommentError";
1883
+ }
1884
+ };
1885
+ var EditCommentError = class extends Error {
1886
+ constructor(cause, context) {
1887
+ super("Edit comment failed.");
1888
+ this.cause = cause;
1889
+ this.context = context;
1890
+ this.name = "EditCommentError";
1891
+ }
1892
+ };
1893
+ var DeleteCommentError = class extends Error {
1894
+ constructor(cause, context) {
1895
+ super("Delete comment failed.");
1896
+ this.cause = cause;
1897
+ this.context = context;
1898
+ this.name = "DeleteCommentError";
1899
+ }
1900
+ };
1901
+ var AddReactionError = class extends Error {
1902
+ constructor(cause, context) {
1903
+ super("Add reaction failed.");
1904
+ this.cause = cause;
1905
+ this.context = context;
1906
+ this.name = "AddReactionError";
1907
+ }
1908
+ };
1909
+ var RemoveReactionError = class extends Error {
1910
+ constructor(cause, context) {
1911
+ super("Remove reaction failed.");
1912
+ this.cause = cause;
1913
+ this.context = context;
1914
+ this.name = "RemoveReactionError";
1915
+ }
1916
+ };
1917
+ var MarkInboxNotificationAsReadError = class extends Error {
1918
+ constructor(cause, context) {
1919
+ super("Mark inbox notification as read failed.");
1920
+ this.cause = cause;
1921
+ this.context = context;
1922
+ this.name = "MarkInboxNotificationAsReadError";
1923
+ }
1924
+ };
1925
+ var UpdateNotificationSettingsError = class extends Error {
1926
+ constructor(cause, context) {
1927
+ super("Update notification settings failed.");
1928
+ this.cause = cause;
1929
+ this.context = context;
1930
+ this.name = "UpdateNotificationSettingsError";
1719
1931
  }
1720
- const selector = useCallback2(
1721
- (state) => {
1722
- return {
1723
- threads: selectUserThreads(state, options),
1724
- isLoading: false
1725
- };
1726
- },
1727
- [options]
1728
- );
1729
- return useSyncExternalStoreWithSelector(
1730
- store.subscribe,
1731
- store.get,
1732
- store.get,
1733
- selector,
1734
- shallow
1735
- );
1736
- }
1737
- function useInboxNotifications() {
1738
- return useInboxNotifications_withClient(useClient());
1739
- }
1740
- function useInboxNotificationsSuspense() {
1741
- return useInboxNotificationsSuspense_withClient(useClient());
1742
- }
1743
- function useInboxNotificationThread(inboxNotificationId) {
1744
- return useInboxNotificationThread_withClient(
1745
- useClient(),
1746
- inboxNotificationId
1747
- );
1748
- }
1749
- function useMarkAllInboxNotificationsAsRead() {
1750
- return useMarkAllInboxNotificationsAsRead_withClient(useClient());
1751
- }
1752
- function useMarkInboxNotificationAsRead() {
1753
- return useMarkInboxNotificationAsRead_withClient(useClient());
1754
- }
1755
- function useDeleteAllInboxNotifications() {
1756
- return useDeleteAllInboxNotifications_withClient(useClient());
1757
- }
1758
- function useDeleteInboxNotification() {
1759
- return useDeleteInboxNotification_withClient(useClient());
1760
- }
1761
- function useUnreadInboxNotificationsCount() {
1762
- return useUnreadInboxNotificationsCount_withClient(useClient());
1763
- }
1764
- function useUnreadInboxNotificationsCountSuspense() {
1765
- return useUnreadInboxNotificationsCountSuspense_withClient(useClient());
1766
- }
1767
- function useUser(userId) {
1768
- const client = useClient();
1769
- return useUser_withClient(client, userId);
1770
- }
1771
- function useUserSuspense(userId) {
1772
- const client = useClient();
1773
- return useUserSuspense_withClient(client, userId);
1774
- }
1775
- function useRoomInfo(roomId) {
1776
- return useRoomInfo_withClient(useClient(), roomId);
1777
- }
1778
- function useRoomInfoSuspense(roomId) {
1779
- return useRoomInfoSuspense_withClient(useClient(), roomId);
1780
- }
1781
- var _useInboxNotificationThread = useInboxNotificationThread;
1782
- var _useUser = useUser;
1783
- var _useUserSuspense = useUserSuspense;
1784
- var _useUserThreads_experimental = useUserThreads_experimental;
1785
- var _useUserThreadsSuspense_experimental = useUserThreadsSuspense_experimental;
1786
- var makeUserThreadsQueryKey = (options) => `${USER_THREADS_QUERY}:${stringify(options)}`;
1932
+ };
1933
+
1934
+ // src/room.tsx
1935
+ import { shallow as shallow4 } from "@liveblocks/client";
1936
+ import {
1937
+ CommentsApiError,
1938
+ console as console3,
1939
+ createCommentId,
1940
+ createThreadId,
1941
+ deprecateIf,
1942
+ errorIf,
1943
+ kInternal as kInternal2,
1944
+ makeEventSource,
1945
+ makePoller as makePoller2,
1946
+ NotificationsApiError,
1947
+ ServerMsgCode,
1948
+ stringify as stringify2
1949
+ } from "@liveblocks/core";
1950
+ import * as React5 from "react";
1951
+ import { useSyncExternalStoreWithSelector as useSyncExternalStoreWithSelector2 } from "use-sync-external-store/shim/with-selector.js";
1787
1952
 
1788
1953
  // src/use-scroll-to-comment-on-load-effect.ts
1789
- import * as React3 from "react";
1954
+ import * as React4 from "react";
1790
1955
  function handleScrollToCommentOnLoad(shouldScrollOnLoad, state) {
1791
1956
  if (shouldScrollOnLoad === false) return;
1792
1957
  if (state.isLoading) return;
@@ -1805,7 +1970,7 @@ function handleScrollToCommentOnLoad(shouldScrollOnLoad, state) {
1805
1970
  comment.scrollIntoView();
1806
1971
  }
1807
1972
  function useScrollToCommentOnLoadEffect(shouldScrollOnLoad, state) {
1808
- React3.useEffect(
1973
+ React4.useEffect(
1809
1974
  () => {
1810
1975
  handleScrollToCommentOnLoad(shouldScrollOnLoad, state);
1811
1976
  },
@@ -1818,7 +1983,7 @@ function useScrollToCommentOnLoadEffect(shouldScrollOnLoad, state) {
1818
1983
  var SMOOTH_DELAY = 1e3;
1819
1984
  var noop2 = () => {
1820
1985
  };
1821
- var identity = (x) => x;
1986
+ var identity2 = (x) => x;
1822
1987
  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:
1823
1988
 
1824
1989
  import { unstable_batchedUpdates } from "react-dom"; // or "react-native"
@@ -1832,13 +1997,10 @@ var missing_unstable_batchedUpdates = (reactVersion, roomId) => `We noticed you\
1832
1997
  Why? Please see https://liveblocks.io/docs/platform/troubleshooting#stale-props-zombie-child for more information`;
1833
1998
  var superfluous_unstable_batchedUpdates = "You don\u2019t need to pass unstable_batchedUpdates to RoomProvider anymore, since you\u2019re on React 18+ already.";
1834
1999
  function useSyncExternalStore2(s, gs, gss) {
1835
- return useSyncExternalStoreWithSelector2(s, gs, gss, identity);
2000
+ return useSyncExternalStoreWithSelector2(s, gs, gss, identity2);
1836
2001
  }
1837
2002
  var STABLE_EMPTY_LIST = Object.freeze([]);
1838
2003
  var POLLING_INTERVAL2 = 5 * 60 * 1e3;
1839
- function makeNotificationSettingsQueryKey(roomId) {
1840
- return `${roomId}:NOTIFICATION_SETTINGS`;
1841
- }
1842
2004
  function alwaysEmptyList() {
1843
2005
  return STABLE_EMPTY_LIST;
1844
2006
  }
@@ -1848,22 +2010,6 @@ function alwaysNull() {
1848
2010
  function selectorFor_useOthersConnectionIds(others) {
1849
2011
  return others.map((user) => user.connectionId);
1850
2012
  }
1851
- function selectRoomThreads(roomId, state, options) {
1852
- const result = applyOptimisticUpdates(state);
1853
- let threads = Object.values(result.threads).filter(
1854
- (thread) => !thread.deletedAt
1855
- );
1856
- threads = threads.filter((thread) => thread.roomId === roomId);
1857
- const query = options.query;
1858
- if (query) {
1859
- threads = threads.filter(makeThreadsFilter(query));
1860
- }
1861
- return threads.sort(byFirstCreated);
1862
- }
1863
- function selectNotificationSettings(roomId, state) {
1864
- const { notificationSettings } = applyOptimisticUpdates(state);
1865
- return nn(notificationSettings[roomId]);
1866
- }
1867
2013
  function makeMutationContext(room) {
1868
2014
  const cannotUseUntil = "This mutation cannot be used until";
1869
2015
  const needsPresence = `${cannotUseUntil} connected to the Liveblocks room`;
@@ -1992,7 +2138,7 @@ function makeExtrasForClient2(client) {
1992
2138
  }
1993
2139
  }
1994
2140
  async function getRoomVersions(room, { retryCount } = { retryCount: 0 }) {
1995
- const queryKey = getVersionsQueryKey(room.id);
2141
+ const queryKey = makeVersionsQueryKey(room.id);
1996
2142
  const existingRequest = requestsByQuery.get(queryKey);
1997
2143
  if (existingRequest !== void 0) return existingRequest;
1998
2144
  const request = room[kInternal2].listTextVersions();
@@ -2052,7 +2198,8 @@ function makeExtrasForClient2(client) {
2052
2198
  }
2053
2199
  return;
2054
2200
  }
2055
- async function getInboxNotificationSettings(room, queryKey, { retryCount } = { retryCount: 0 }) {
2201
+ async function getInboxNotificationSettings(room, { retryCount } = { retryCount: 0 }) {
2202
+ const queryKey = makeNotificationSettingsQueryKey(room.id);
2056
2203
  const existingRequest = requestsByQuery.get(queryKey);
2057
2204
  if (existingRequest !== void 0) return existingRequest;
2058
2205
  try {
@@ -2064,7 +2211,7 @@ function makeExtrasForClient2(client) {
2064
2211
  } catch (err) {
2065
2212
  requestsByQuery.delete(queryKey);
2066
2213
  retryError(() => {
2067
- void getInboxNotificationSettings(room, queryKey, {
2214
+ void getInboxNotificationSettings(room, {
2068
2215
  retryCount: retryCount + 1
2069
2216
  });
2070
2217
  }, retryCount);
@@ -2097,10 +2244,9 @@ function makeExtrasForClient2(client) {
2097
2244
  onMutationFailure
2098
2245
  };
2099
2246
  }
2100
- var RoomContext = React4.createContext(null);
2101
2247
  function makeRoomContextBundle(client) {
2102
2248
  function RoomProvider_withImplicitLiveblocksProvider(props) {
2103
- return /* @__PURE__ */ React4.createElement(LiveblocksProviderWithClient, { client, allowNesting: true }, /* @__PURE__ */ React4.createElement(RoomProvider, { ...props }));
2249
+ return /* @__PURE__ */ React5.createElement(LiveblocksProviderWithClient, { client, allowNesting: true }, /* @__PURE__ */ React5.createElement(RoomProvider, { ...props }));
2104
2250
  }
2105
2251
  const shared = createSharedContext(client);
2106
2252
  const bundle = {
@@ -2202,10 +2348,10 @@ function makeRoomContextBundle(client) {
2202
2348
  }
2203
2349
  function RoomProvider(props) {
2204
2350
  const client = useClient();
2205
- const [cache] = React4.useState(
2351
+ const [cache] = React5.useState(
2206
2352
  () => /* @__PURE__ */ new Map()
2207
2353
  );
2208
- const stableEnterRoom = React4.useCallback(
2354
+ const stableEnterRoom = React5.useCallback(
2209
2355
  (roomId, options) => {
2210
2356
  const cached = cache.get(roomId);
2211
2357
  if (cached) return cached;
@@ -2220,7 +2366,7 @@ function RoomProvider(props) {
2220
2366
  },
2221
2367
  [client, cache]
2222
2368
  );
2223
- return /* @__PURE__ */ React4.createElement(
2369
+ return /* @__PURE__ */ React5.createElement(
2224
2370
  RoomProviderInner,
2225
2371
  {
2226
2372
  ...props,
@@ -2240,7 +2386,7 @@ function RoomProviderInner(props) {
2240
2386
  if (!isString(roomId)) {
2241
2387
  throw new Error("RoomProvider id property should be a string.");
2242
2388
  }
2243
- const majorReactVersion = parseInt(React4.version) || 1;
2389
+ const majorReactVersion = parseInt(React5.version) || 1;
2244
2390
  const oldReactVersion = majorReactVersion < 18;
2245
2391
  errorIf(
2246
2392
  oldReactVersion && props.unstable_batchedUpdates === void 0,
@@ -2257,14 +2403,14 @@ function RoomProviderInner(props) {
2257
2403
  unstable_batchedUpdates: props.unstable_batchedUpdates,
2258
2404
  autoConnect: props.autoConnect ?? typeof window !== "undefined"
2259
2405
  });
2260
- const [{ room }, setRoomLeavePair] = React4.useState(
2406
+ const [{ room }, setRoomLeavePair] = React5.useState(
2261
2407
  () => stableEnterRoom(roomId, {
2262
2408
  ...frozenProps,
2263
2409
  autoConnect: false
2264
2410
  // Deliberately using false here on the first render, see below
2265
2411
  })
2266
2412
  );
2267
- React4.useEffect(() => {
2413
+ React5.useEffect(() => {
2268
2414
  const { store } = getExtrasForClient2(client);
2269
2415
  async function handleCommentEvent(message) {
2270
2416
  if (message.type === ServerMsgCode.THREAD_DELETED) {
@@ -2277,7 +2423,7 @@ function RoomProviderInner(props) {
2277
2423
  return;
2278
2424
  }
2279
2425
  const { thread, inboxNotification } = info;
2280
- const existingThread = store.get().threads[message.threadId];
2426
+ const existingThread = store.getThreads().threadsById[message.threadId];
2281
2427
  switch (message.type) {
2282
2428
  case ServerMsgCode.COMMENT_EDITED:
2283
2429
  case ServerMsgCode.THREAD_METADATA_UPDATED:
@@ -2299,11 +2445,11 @@ function RoomProviderInner(props) {
2299
2445
  (message) => void handleCommentEvent(message)
2300
2446
  );
2301
2447
  }, [client, room]);
2302
- React4.useEffect(() => {
2448
+ React5.useEffect(() => {
2303
2449
  const { getThreadsUpdates } = getExtrasForClient2(client);
2304
2450
  void getThreadsUpdates(room.id);
2305
2451
  }, [client, room.id]);
2306
- React4.useEffect(() => {
2452
+ React5.useEffect(() => {
2307
2453
  function handleIsOnline() {
2308
2454
  const { getThreadsUpdates } = getExtrasForClient2(client);
2309
2455
  void getThreadsUpdates(room.id);
@@ -2313,7 +2459,7 @@ function RoomProviderInner(props) {
2313
2459
  window.removeEventListener("online", handleIsOnline);
2314
2460
  };
2315
2461
  }, [client, room.id]);
2316
- React4.useEffect(() => {
2462
+ React5.useEffect(() => {
2317
2463
  const pair = stableEnterRoom(roomId, frozenProps);
2318
2464
  setRoomLeavePair(pair);
2319
2465
  const { room: room2, leave } = pair;
@@ -2324,7 +2470,7 @@ function RoomProviderInner(props) {
2324
2470
  leave();
2325
2471
  };
2326
2472
  }, [roomId, frozenProps, stableEnterRoom]);
2327
- return /* @__PURE__ */ React4.createElement(RoomContext.Provider, { value: room }, props.children);
2473
+ return /* @__PURE__ */ React5.createElement(RoomContext.Provider, { value: room }, props.children);
2328
2474
  }
2329
2475
  function useRoom() {
2330
2476
  const room = useRoomOrNull();
@@ -2333,10 +2479,6 @@ function useRoom() {
2333
2479
  }
2334
2480
  return room;
2335
2481
  }
2336
- function useIsInsideRoom() {
2337
- const room = useRoomOrNull();
2338
- return room !== null;
2339
- }
2340
2482
  function useStatus() {
2341
2483
  const room = useRoom();
2342
2484
  const subscribe = room.events.status.subscribe;
@@ -2361,9 +2503,9 @@ function useStorageStatusImmediate() {
2361
2503
  }
2362
2504
  function useStorageStatusSmooth() {
2363
2505
  const room = useRoom();
2364
- const [status, setStatus] = React4.useState(room.getStorageStatus);
2506
+ const [status, setStatus] = React5.useState(room.getStorageStatus);
2365
2507
  const oldStatus = useLatest(room.getStorageStatus());
2366
- React4.useEffect(() => {
2508
+ React5.useEffect(() => {
2367
2509
  let timeoutId;
2368
2510
  const unsub = room.events.storageStatus.subscribe((newStatus) => {
2369
2511
  if (oldStatus.current === "synchronizing" && newStatus === "synchronized") {
@@ -2385,7 +2527,7 @@ function useBatch() {
2385
2527
  }
2386
2528
  function useBroadcastEvent() {
2387
2529
  const room = useRoom();
2388
- return React4.useCallback(
2530
+ return React5.useCallback(
2389
2531
  (event, options = { shouldQueueEventIfNotReady: false }) => {
2390
2532
  room.broadcastEvent(event, options);
2391
2533
  },
@@ -2395,7 +2537,7 @@ function useBroadcastEvent() {
2395
2537
  function useOthersListener(callback) {
2396
2538
  const room = useRoom();
2397
2539
  const savedCallback = useLatest(callback);
2398
- React4.useEffect(
2540
+ React5.useEffect(
2399
2541
  () => room.events.others.subscribe((event) => savedCallback.current(event)),
2400
2542
  [room, savedCallback]
2401
2543
  );
@@ -2403,7 +2545,7 @@ function useOthersListener(callback) {
2403
2545
  function useLostConnectionListener(callback) {
2404
2546
  const room = useRoom();
2405
2547
  const savedCallback = useLatest(callback);
2406
- React4.useEffect(
2548
+ React5.useEffect(
2407
2549
  () => room.events.lostConnection.subscribe(
2408
2550
  (event) => savedCallback.current(event)
2409
2551
  ),
@@ -2413,7 +2555,7 @@ function useLostConnectionListener(callback) {
2413
2555
  function useErrorListener(callback) {
2414
2556
  const room = useRoom();
2415
2557
  const savedCallback = useLatest(callback);
2416
- React4.useEffect(
2558
+ React5.useEffect(
2417
2559
  () => room.events.error.subscribe((e) => savedCallback.current(e)),
2418
2560
  [room, savedCallback]
2419
2561
  );
@@ -2421,7 +2563,7 @@ function useErrorListener(callback) {
2421
2563
  function useEventListener(callback) {
2422
2564
  const room = useRoom();
2423
2565
  const savedCallback = useLatest(callback);
2424
- React4.useEffect(() => {
2566
+ React5.useEffect(() => {
2425
2567
  const listener = (eventData) => {
2426
2568
  savedCallback.current(eventData);
2427
2569
  };
@@ -2453,8 +2595,8 @@ function useSelf(maybeSelector, isEqual) {
2453
2595
  const room = useRoom();
2454
2596
  const subscribe = room.events.self.subscribe;
2455
2597
  const getSnapshot = room.getSelf;
2456
- const selector = maybeSelector ?? identity;
2457
- const wrappedSelector = React4.useCallback(
2598
+ const selector = maybeSelector ?? identity2;
2599
+ const wrappedSelector = React5.useCallback(
2458
2600
  (me) => me !== null ? selector(me) : null,
2459
2601
  [selector]
2460
2602
  );
@@ -2487,16 +2629,16 @@ function useOthers(selector, isEqual) {
2487
2629
  subscribe,
2488
2630
  getSnapshot,
2489
2631
  getServerSnapshot,
2490
- selector ?? identity,
2632
+ selector ?? identity2,
2491
2633
  isEqual
2492
2634
  );
2493
2635
  }
2494
2636
  function useOthersMapped(itemSelector, itemIsEqual) {
2495
- const wrappedSelector = React4.useCallback(
2637
+ const wrappedSelector = React5.useCallback(
2496
2638
  (others) => others.map((other) => [other.connectionId, itemSelector(other)]),
2497
2639
  [itemSelector]
2498
2640
  );
2499
- const wrappedIsEqual = React4.useCallback(
2641
+ const wrappedIsEqual = React5.useCallback(
2500
2642
  (a, b) => {
2501
2643
  const eq = itemIsEqual ?? Object.is;
2502
2644
  return a.length === b.length && a.every((atuple, index) => {
@@ -2509,18 +2651,18 @@ function useOthersMapped(itemSelector, itemIsEqual) {
2509
2651
  return useOthers(wrappedSelector, wrappedIsEqual);
2510
2652
  }
2511
2653
  function useOthersConnectionIds() {
2512
- return useOthers(selectorFor_useOthersConnectionIds, shallow2);
2654
+ return useOthers(selectorFor_useOthersConnectionIds, shallow4);
2513
2655
  }
2514
2656
  var NOT_FOUND = Symbol();
2515
2657
  function useOther(connectionId, selector, isEqual) {
2516
- const wrappedSelector = React4.useCallback(
2658
+ const wrappedSelector = React5.useCallback(
2517
2659
  (others) => {
2518
2660
  const other2 = others.find((other3) => other3.connectionId === connectionId);
2519
2661
  return other2 !== void 0 ? selector(other2) : NOT_FOUND;
2520
2662
  },
2521
2663
  [connectionId, selector]
2522
2664
  );
2523
- const wrappedIsEqual = React4.useCallback(
2665
+ const wrappedIsEqual = React5.useCallback(
2524
2666
  (prev, curr) => {
2525
2667
  if (prev === NOT_FOUND || curr === NOT_FOUND) {
2526
2668
  return prev === curr;
@@ -2551,15 +2693,15 @@ function useStorageRoot() {
2551
2693
  function useStorage(selector, isEqual) {
2552
2694
  const room = useRoom();
2553
2695
  const rootOrNull = useMutableStorageRoot();
2554
- const wrappedSelector = React4.useCallback(
2696
+ const wrappedSelector = React5.useCallback(
2555
2697
  (rootOrNull2) => rootOrNull2 !== null ? selector(rootOrNull2) : null,
2556
2698
  [selector]
2557
2699
  );
2558
- const subscribe = React4.useCallback(
2700
+ const subscribe = React5.useCallback(
2559
2701
  (onStoreChange) => rootOrNull !== null ? room.subscribe(rootOrNull, onStoreChange, { isDeep: true }) : noop2,
2560
2702
  [room, rootOrNull]
2561
2703
  );
2562
- const getSnapshot = React4.useCallback(() => {
2704
+ const getSnapshot = React5.useCallback(() => {
2563
2705
  if (rootOrNull === null) {
2564
2706
  return null;
2565
2707
  } else {
@@ -2579,7 +2721,7 @@ function useStorage(selector, isEqual) {
2579
2721
  }
2580
2722
  function useMutation(callback, deps) {
2581
2723
  const room = useRoom();
2582
- return React4.useMemo(
2724
+ return React5.useMemo(
2583
2725
  () => {
2584
2726
  return (...args) => (
2585
2727
  // eslint-disable-next-line @typescript-eslint/no-unsafe-return
@@ -2604,16 +2746,16 @@ function useThreads(options = {
2604
2746
  const { scrollOnLoad = true } = options;
2605
2747
  const client = useClient();
2606
2748
  const room = useRoom();
2607
- const queryKey = React4.useMemo(
2749
+ const queryKey = React5.useMemo(
2608
2750
  () => generateQueryKey(room.id, options.query),
2609
2751
  [room, options]
2610
2752
  );
2611
2753
  const { store, getThreadsAndInboxNotifications, incrementQuerySubscribers } = getExtrasForClient2(client);
2612
- React4.useEffect(() => {
2754
+ React5.useEffect(() => {
2613
2755
  void getThreadsAndInboxNotifications(room, queryKey, options);
2614
2756
  return incrementQuerySubscribers(queryKey);
2615
2757
  }, [room, queryKey]);
2616
- const selector = React4.useCallback(
2758
+ const selector = React5.useCallback(
2617
2759
  (state2) => {
2618
2760
  const query = state2.queries[queryKey];
2619
2761
  if (query === void 0 || query.isLoading) {
@@ -2622,7 +2764,11 @@ function useThreads(options = {
2622
2764
  };
2623
2765
  }
2624
2766
  return {
2625
- threads: selectRoomThreads(room.id, state2, options),
2767
+ threads: selectThreads(state2, {
2768
+ roomId: room.id,
2769
+ query: options.query,
2770
+ orderBy: "age"
2771
+ }),
2626
2772
  isLoading: false,
2627
2773
  error: query.error
2628
2774
  };
@@ -2631,9 +2777,9 @@ function useThreads(options = {
2631
2777
  // eslint-disable-line react-hooks/exhaustive-deps
2632
2778
  );
2633
2779
  const state = useSyncExternalStoreWithSelector2(
2634
- store.subscribe,
2635
- store.get,
2636
- store.get,
2780
+ store.subscribeThreads,
2781
+ store.getThreads,
2782
+ store.getThreads,
2637
2783
  selector
2638
2784
  );
2639
2785
  useScrollToCommentOnLoadEffect(scrollOnLoad, state);
@@ -2643,14 +2789,14 @@ function useCommentsErrorListener(callback) {
2643
2789
  const client = useClient();
2644
2790
  const savedCallback = useLatest(callback);
2645
2791
  const { commentsErrorEventSource } = getExtrasForClient2(client);
2646
- React4.useEffect(() => {
2792
+ React5.useEffect(() => {
2647
2793
  return commentsErrorEventSource.subscribe(savedCallback.current);
2648
2794
  }, [savedCallback, commentsErrorEventSource]);
2649
2795
  }
2650
2796
  function useCreateThread() {
2651
2797
  const client = useClient();
2652
2798
  const room = useRoom();
2653
- return React4.useCallback(
2799
+ return React5.useCallback(
2654
2800
  (options) => {
2655
2801
  const body = options.body;
2656
2802
  const metadata = options.metadata ?? {};
@@ -2707,10 +2853,10 @@ function useCreateThread() {
2707
2853
  function useDeleteThread() {
2708
2854
  const client = useClient();
2709
2855
  const room = useRoom();
2710
- return React4.useCallback(
2856
+ return React5.useCallback(
2711
2857
  (threadId) => {
2712
2858
  const { store, onMutationFailure } = getExtrasForClient2(client);
2713
- const thread = store.get().threads[threadId];
2859
+ const thread = store.getThreads().threadsById[threadId];
2714
2860
  const userId = getCurrentUserId(room);
2715
2861
  if (thread?.comments?.[0]?.userId !== userId) {
2716
2862
  throw new Error("Only the thread creator can delete the thread");
@@ -2738,7 +2884,7 @@ function useDeleteThread() {
2738
2884
  function useEditThreadMetadata() {
2739
2885
  const client = useClient();
2740
2886
  const room = useRoom();
2741
- return React4.useCallback(
2887
+ return React5.useCallback(
2742
2888
  (options) => {
2743
2889
  if (!options.metadata) {
2744
2890
  return;
@@ -2756,10 +2902,10 @@ function useEditThreadMetadata() {
2756
2902
  room.editThreadMetadata({ threadId, metadata }).then(
2757
2903
  (metadata2) => (
2758
2904
  // Replace the optimistic update by the real thing
2759
- store.updateThread(
2905
+ store.patchThread(
2760
2906
  threadId,
2761
2907
  optimisticUpdateId,
2762
- (thread) => ({ ...thread, metadata: metadata2 }),
2908
+ { metadata: metadata2 },
2763
2909
  updatedAt
2764
2910
  )
2765
2911
  ),
@@ -2780,7 +2926,7 @@ function useEditThreadMetadata() {
2780
2926
  function useCreateComment() {
2781
2927
  const client = useClient();
2782
2928
  const room = useRoom();
2783
- return React4.useCallback(
2929
+ return React5.useCallback(
2784
2930
  ({ threadId, body }) => {
2785
2931
  const commentId = createCommentId();
2786
2932
  const createdAt = /* @__PURE__ */ new Date();
@@ -2822,11 +2968,11 @@ function useCreateComment() {
2822
2968
  function useEditComment() {
2823
2969
  const client = useClient();
2824
2970
  const room = useRoom();
2825
- return React4.useCallback(
2971
+ return React5.useCallback(
2826
2972
  ({ threadId, commentId, body }) => {
2827
2973
  const editedAt = /* @__PURE__ */ new Date();
2828
2974
  const { store, onMutationFailure } = getExtrasForClient2(client);
2829
- const thread = store.get().threads[threadId];
2975
+ const thread = store.getThreads().threadsById[threadId];
2830
2976
  if (thread === void 0) {
2831
2977
  console3.warn(
2832
2978
  `Internal unexpected behavior. Cannot edit comment in thread "${threadId}" because the thread does not exist in the cache.`
@@ -2852,11 +2998,7 @@ function useEditComment() {
2852
2998
  });
2853
2999
  room.editComment({ threadId, commentId, body }).then(
2854
3000
  (editedComment) => {
2855
- store.updateThread(
2856
- threadId,
2857
- optimisticUpdateId,
2858
- (thread2) => upsertComment(thread2, editedComment)
2859
- );
3001
+ store.editComment(threadId, optimisticUpdateId, editedComment);
2860
3002
  },
2861
3003
  (err) => onMutationFailure(
2862
3004
  err,
@@ -2876,7 +3018,7 @@ function useEditComment() {
2876
3018
  function useDeleteComment() {
2877
3019
  const client = useClient();
2878
3020
  const room = useRoom();
2879
- return React4.useCallback(
3021
+ return React5.useCallback(
2880
3022
  ({ threadId, commentId }) => {
2881
3023
  const deletedAt = /* @__PURE__ */ new Date();
2882
3024
  const { store, onMutationFailure } = getExtrasForClient2(client);
@@ -2889,10 +3031,10 @@ function useDeleteComment() {
2889
3031
  });
2890
3032
  room.deleteComment({ threadId, commentId }).then(
2891
3033
  () => {
2892
- store.updateThread(
3034
+ store.deleteComment(
2893
3035
  threadId,
2894
3036
  optimisticUpdateId,
2895
- (thread) => deleteComment(thread, commentId, deletedAt),
3037
+ commentId,
2896
3038
  deletedAt
2897
3039
  );
2898
3040
  },
@@ -2913,7 +3055,7 @@ function useDeleteComment() {
2913
3055
  function useAddReaction() {
2914
3056
  const client = useClient();
2915
3057
  const room = useRoom();
2916
- return React4.useCallback(
3058
+ return React5.useCallback(
2917
3059
  ({ threadId, commentId, emoji }) => {
2918
3060
  const createdAt = /* @__PURE__ */ new Date();
2919
3061
  const userId = getCurrentUserId(room);
@@ -2930,10 +3072,11 @@ function useAddReaction() {
2930
3072
  });
2931
3073
  room.addReaction({ threadId, commentId, emoji }).then(
2932
3074
  (addedReaction) => {
2933
- store.updateThread(
3075
+ store.addReaction(
2934
3076
  threadId,
2935
3077
  optimisticUpdateId,
2936
- (thread) => addReaction(thread, commentId, addedReaction),
3078
+ commentId,
3079
+ addedReaction,
2937
3080
  createdAt
2938
3081
  );
2939
3082
  },
@@ -2955,7 +3098,7 @@ function useAddReaction() {
2955
3098
  function useRemoveReaction() {
2956
3099
  const client = useClient();
2957
3100
  const room = useRoom();
2958
- return React4.useCallback(
3101
+ return React5.useCallback(
2959
3102
  ({ threadId, commentId, emoji }) => {
2960
3103
  const userId = getCurrentUserId(room);
2961
3104
  const removedAt = /* @__PURE__ */ new Date();
@@ -2970,10 +3113,12 @@ function useRemoveReaction() {
2970
3113
  });
2971
3114
  room.removeReaction({ threadId, commentId, emoji }).then(
2972
3115
  () => {
2973
- store.updateThread(
3116
+ store.removeReaction(
2974
3117
  threadId,
2975
3118
  optimisticUpdateId,
2976
- (thread) => removeReaction(thread, commentId, emoji, userId, removedAt),
3119
+ commentId,
3120
+ emoji,
3121
+ userId,
2977
3122
  removedAt
2978
3123
  );
2979
3124
  },
@@ -2995,11 +3140,11 @@ function useRemoveReaction() {
2995
3140
  function useMarkThreadAsRead() {
2996
3141
  const client = useClient();
2997
3142
  const room = useRoom();
2998
- return React4.useCallback(
3143
+ return React5.useCallback(
2999
3144
  (threadId) => {
3000
3145
  const { store, onMutationFailure } = getExtrasForClient2(client);
3001
3146
  const inboxNotification = Object.values(
3002
- store.get().inboxNotifications
3147
+ store.getInboxNotifications().inboxNotificationsById
3003
3148
  ).find(
3004
3149
  (inboxNotification2) => inboxNotification2.kind === "thread" && inboxNotification2.threadId === threadId
3005
3150
  );
@@ -3036,7 +3181,7 @@ function useMarkThreadAsRead() {
3036
3181
  function useMarkThreadAsResolved() {
3037
3182
  const client = useClient();
3038
3183
  const room = useRoom();
3039
- return React4.useCallback(
3184
+ return React5.useCallback(
3040
3185
  (threadId) => {
3041
3186
  const updatedAt = /* @__PURE__ */ new Date();
3042
3187
  const { store, onMutationFailure } = getExtrasForClient2(client);
@@ -3047,10 +3192,10 @@ function useMarkThreadAsResolved() {
3047
3192
  });
3048
3193
  room.markThreadAsResolved(threadId).then(
3049
3194
  () => {
3050
- store.updateThread(
3195
+ store.patchThread(
3051
3196
  threadId,
3052
3197
  optimisticUpdateId,
3053
- (thread) => ({ ...thread, resolved: true }),
3198
+ { resolved: true },
3054
3199
  updatedAt
3055
3200
  );
3056
3201
  },
@@ -3070,7 +3215,7 @@ function useMarkThreadAsResolved() {
3070
3215
  function useMarkThreadAsUnresolved() {
3071
3216
  const client = useClient();
3072
3217
  const room = useRoom();
3073
- return React4.useCallback(
3218
+ return React5.useCallback(
3074
3219
  (threadId) => {
3075
3220
  const updatedAt = /* @__PURE__ */ new Date();
3076
3221
  const { store, onMutationFailure } = getExtrasForClient2(client);
@@ -3081,10 +3226,10 @@ function useMarkThreadAsUnresolved() {
3081
3226
  });
3082
3227
  room.markThreadAsUnresolved(threadId).then(
3083
3228
  () => {
3084
- store.updateThread(
3229
+ store.patchThread(
3085
3230
  threadId,
3086
3231
  optimisticUpdateId,
3087
- (thread) => ({ ...thread, resolved: false }),
3232
+ { resolved: false },
3088
3233
  updatedAt
3089
3234
  );
3090
3235
  },
@@ -3104,12 +3249,12 @@ function useMarkThreadAsUnresolved() {
3104
3249
  function useThreadSubscription(threadId) {
3105
3250
  const client = useClient();
3106
3251
  const { store } = getExtrasForClient2(client);
3107
- const selector = React4.useCallback(
3252
+ const selector = React5.useCallback(
3108
3253
  (state) => {
3109
- const inboxNotification = selectInboxNotifications(state).find(
3254
+ const inboxNotification = state.inboxNotifications.find(
3110
3255
  (inboxNotification2) => inboxNotification2.kind === "thread" && inboxNotification2.threadId === threadId
3111
3256
  );
3112
- const thread = state.threads[threadId];
3257
+ const thread = state.threadsById[threadId];
3113
3258
  if (inboxNotification === void 0 || thread === void 0) {
3114
3259
  return {
3115
3260
  status: "not-subscribed"
@@ -3123,54 +3268,68 @@ function useThreadSubscription(threadId) {
3123
3268
  [threadId]
3124
3269
  );
3125
3270
  return useSyncExternalStoreWithSelector2(
3126
- store.subscribe,
3127
- store.get,
3128
- store.get,
3271
+ store.subscribeThreads,
3272
+ store.getThreads,
3273
+ store.getThreads,
3129
3274
  selector
3130
3275
  );
3131
3276
  }
3132
3277
  function useRoomNotificationSettings() {
3278
+ const updateRoomNotificationSettings = useUpdateRoomNotificationSettings();
3133
3279
  const client = useClient();
3134
3280
  const room = useRoom();
3135
3281
  const { store } = getExtrasForClient2(client);
3136
- React4.useEffect(() => {
3282
+ const getter = React5.useCallback(
3283
+ () => store.getNotificationSettingsAsync(room.id),
3284
+ [store, room.id]
3285
+ );
3286
+ React5.useEffect(() => {
3137
3287
  const { getInboxNotificationSettings } = getExtrasForClient2(client);
3138
- const queryKey = makeNotificationSettingsQueryKey(room.id);
3139
- void getInboxNotificationSettings(room, queryKey);
3288
+ void getInboxNotificationSettings(room);
3140
3289
  }, [client, room]);
3290
+ const settings = useSyncExternalStoreWithSelector2(
3291
+ store.subscribeNotificationSettings,
3292
+ getter,
3293
+ getter,
3294
+ identity2,
3295
+ shallow4
3296
+ );
3297
+ return React5.useMemo(() => {
3298
+ return [settings, updateRoomNotificationSettings];
3299
+ }, [settings, updateRoomNotificationSettings]);
3300
+ }
3301
+ function useRoomNotificationSettingsSuspense() {
3141
3302
  const updateRoomNotificationSettings = useUpdateRoomNotificationSettings();
3142
- const selector = React4.useCallback(
3143
- (state) => {
3144
- const query = state.queries[makeNotificationSettingsQueryKey(room.id)];
3145
- if (query === void 0 || query.isLoading) {
3146
- return { isLoading: true };
3147
- }
3148
- if (query.error !== void 0) {
3149
- return { isLoading: false, error: query.error };
3150
- }
3151
- return {
3152
- isLoading: false,
3153
- settings: selectNotificationSettings(room.id, state)
3154
- };
3155
- },
3156
- [room]
3303
+ const client = useClient();
3304
+ const room = useRoom();
3305
+ const { store } = getExtrasForClient2(client);
3306
+ const getter = React5.useCallback(
3307
+ () => store.getNotificationSettingsAsync(room.id),
3308
+ [store, room.id]
3157
3309
  );
3158
3310
  const settings = useSyncExternalStoreWithSelector2(
3159
- store.subscribe,
3160
- store.get,
3161
- store.get,
3162
- selector
3311
+ store.subscribeNotificationSettings,
3312
+ getter,
3313
+ getter,
3314
+ identity2,
3315
+ shallow4
3163
3316
  );
3164
- return React4.useMemo(() => {
3317
+ if (settings.isLoading) {
3318
+ const { getInboxNotificationSettings } = getExtrasForClient2(client);
3319
+ throw getInboxNotificationSettings(room);
3320
+ } else if (settings.error) {
3321
+ throw settings.error;
3322
+ }
3323
+ return React5.useMemo(() => {
3165
3324
  return [settings, updateRoomNotificationSettings];
3166
3325
  }, [settings, updateRoomNotificationSettings]);
3167
3326
  }
3168
3327
  function useHistoryVersionData(versionId) {
3169
- const [state, setState] = React4.useState({
3328
+ const [state, setState] = React5.useState({
3170
3329
  isLoading: true
3171
3330
  });
3172
3331
  const room = useRoom();
3173
- React4.useEffect(() => {
3332
+ React5.useEffect(() => {
3174
3333
  setState({ isLoading: true });
3175
3334
  const load = async () => {
3176
3335
  try {
@@ -3197,40 +3356,50 @@ function useHistoryVersionData(versionId) {
3197
3356
  function useHistoryVersions() {
3198
3357
  const client = useClient();
3199
3358
  const room = useRoom();
3200
- const queryKey = getVersionsQueryKey(room.id);
3201
3359
  const { store, getRoomVersions } = getExtrasForClient2(client);
3202
- React4.useEffect(() => {
3360
+ const getter = React5.useCallback(
3361
+ () => store.getVersionsAsync(room.id),
3362
+ [store, room.id]
3363
+ );
3364
+ React5.useEffect(() => {
3203
3365
  void getRoomVersions(room);
3204
3366
  }, [room]);
3205
- const selector = React4.useCallback(
3206
- (state2) => {
3207
- const query = state2.queries[queryKey];
3208
- if (query === void 0 || query.isLoading) {
3209
- return {
3210
- isLoading: true
3211
- };
3212
- }
3213
- return {
3214
- versions: state2.versions[room.id],
3215
- isLoading: false,
3216
- error: query.error
3217
- };
3218
- },
3219
- [room, queryKey]
3220
- // eslint-disable-line react-hooks/exhaustive-deps
3221
- );
3222
3367
  const state = useSyncExternalStoreWithSelector2(
3223
- store.subscribe,
3224
- store.get,
3225
- store.get,
3226
- selector
3368
+ store.subscribeVersions,
3369
+ getter,
3370
+ getter,
3371
+ identity2,
3372
+ shallow4
3373
+ );
3374
+ return state;
3375
+ }
3376
+ function useHistoryVersionsSuspense() {
3377
+ const client = useClient();
3378
+ const room = useRoom();
3379
+ const { store } = getExtrasForClient2(client);
3380
+ const getter = React5.useCallback(
3381
+ () => store.getVersionsAsync(room.id),
3382
+ [store, room.id]
3227
3383
  );
3384
+ const state = useSyncExternalStoreWithSelector2(
3385
+ store.subscribeVersions,
3386
+ getter,
3387
+ getter,
3388
+ identity2,
3389
+ shallow4
3390
+ );
3391
+ if (state.isLoading) {
3392
+ const { getRoomVersions } = getExtrasForClient2(client);
3393
+ throw getRoomVersions(room);
3394
+ } else if (state.error) {
3395
+ throw state.error;
3396
+ }
3228
3397
  return state;
3229
3398
  }
3230
3399
  function useUpdateRoomNotificationSettings() {
3231
3400
  const client = useClient();
3232
3401
  const room = useRoom();
3233
- return React4.useCallback(
3402
+ return React5.useCallback(
3234
3403
  (settings) => {
3235
3404
  const { store, onMutationFailure } = getExtrasForClient2(client);
3236
3405
  const optimisticUpdateId = store.addOptimisticUpdate({
@@ -3318,115 +3487,51 @@ function useThreadsSuspense(options = {
3318
3487
  const { scrollOnLoad = true } = options;
3319
3488
  const client = useClient();
3320
3489
  const room = useRoom();
3321
- const queryKey = React4.useMemo(
3490
+ const queryKey = React5.useMemo(
3322
3491
  () => generateQueryKey(room.id, options.query),
3323
3492
  [room, options]
3324
3493
  );
3325
3494
  const { store, getThreadsAndInboxNotifications } = getExtrasForClient2(client);
3326
- const query = store.get().queries[queryKey];
3495
+ const query = store.getThreads().queries[queryKey];
3327
3496
  if (query === void 0 || query.isLoading) {
3328
3497
  throw getThreadsAndInboxNotifications(room, queryKey, options);
3329
3498
  }
3330
3499
  if (query.error) {
3331
3500
  throw query.error;
3332
3501
  }
3333
- const selector = React4.useCallback(
3502
+ const selector = React5.useCallback(
3334
3503
  (state2) => {
3335
3504
  return {
3336
- threads: selectRoomThreads(room.id, state2, options),
3505
+ threads: selectThreads(state2, {
3506
+ roomId: room.id,
3507
+ query: options.query,
3508
+ orderBy: "age"
3509
+ }),
3337
3510
  isLoading: false
3338
3511
  };
3339
3512
  },
3340
3513
  [room, queryKey]
3341
3514
  // eslint-disable-line react-hooks/exhaustive-deps
3342
3515
  );
3343
- React4.useEffect(() => {
3516
+ React5.useEffect(() => {
3344
3517
  const { incrementQuerySubscribers } = getExtrasForClient2(client);
3345
3518
  return incrementQuerySubscribers(queryKey);
3346
3519
  }, [client, queryKey]);
3347
3520
  const state = useSyncExternalStoreWithSelector2(
3348
- store.subscribe,
3349
- store.get,
3350
- store.get,
3521
+ store.subscribeThreads,
3522
+ store.getThreads,
3523
+ store.getThreads,
3351
3524
  selector
3352
3525
  );
3353
3526
  useScrollToCommentOnLoadEffect(scrollOnLoad, state);
3354
3527
  return state;
3355
3528
  }
3356
- function useHistoryVersionsSuspense() {
3357
- const client = useClient();
3358
- const room = useRoom();
3359
- const queryKey = getVersionsQueryKey(room.id);
3360
- const { store, getRoomVersions } = getExtrasForClient2(client);
3361
- const query = store.get().queries[queryKey];
3362
- if (query === void 0 || query.isLoading) {
3363
- throw getRoomVersions(room);
3364
- }
3365
- if (query.error) {
3366
- throw query.error;
3367
- }
3368
- const selector = React4.useCallback(
3369
- (state2) => {
3370
- return {
3371
- versions: state2.versions[room.id],
3372
- isLoading: false
3373
- };
3374
- },
3375
- [room, queryKey]
3376
- // eslint-disable-line react-hooks/exhaustive-deps
3377
- );
3378
- const state = useSyncExternalStoreWithSelector2(
3379
- store.subscribe,
3380
- store.get,
3381
- store.get,
3382
- selector
3383
- );
3384
- return state;
3385
- }
3386
- function useRoomNotificationSettingsSuspense() {
3387
- const updateRoomNotificationSettings = useUpdateRoomNotificationSettings();
3388
- const client = useClient();
3389
- const room = useRoom();
3390
- const queryKey = makeNotificationSettingsQueryKey(room.id);
3391
- const { store, getInboxNotificationSettings } = getExtrasForClient2(client);
3392
- const query = store.get().queries[queryKey];
3393
- if (query === void 0 || query.isLoading) {
3394
- throw getInboxNotificationSettings(room, queryKey);
3395
- }
3396
- if (query.error) {
3397
- throw query.error;
3398
- }
3399
- const selector = React4.useCallback(
3400
- (state) => {
3401
- return {
3402
- isLoading: false,
3403
- settings: selectNotificationSettings(room.id, state)
3404
- };
3405
- },
3406
- [room]
3407
- );
3408
- const settings = useSyncExternalStoreWithSelector2(
3409
- store.subscribe,
3410
- store.get,
3411
- store.get,
3412
- selector
3413
- );
3414
- return React4.useMemo(() => {
3415
- return [settings, updateRoomNotificationSettings];
3416
- }, [settings, updateRoomNotificationSettings]);
3417
- }
3418
- function useRoomOrNull() {
3419
- return React4.useContext(RoomContext);
3420
- }
3421
3529
  function createRoomContext(client) {
3422
3530
  return getOrCreateRoomContextBundle(client);
3423
3531
  }
3424
3532
  function generateQueryKey(roomId, options) {
3425
3533
  return `${roomId}-${stringify2(options ?? {})}`;
3426
3534
  }
3427
- function getVersionsQueryKey(roomId) {
3428
- return `${roomId}-VERSIONS`;
3429
- }
3430
3535
  var _RoomProvider = RoomProvider;
3431
3536
  var _useBroadcastEvent = useBroadcastEvent;
3432
3537
  var _useOthersListener = useOthersListener;
@@ -3469,9 +3574,29 @@ export {
3469
3574
  PKG_VERSION,
3470
3575
  PKG_FORMAT,
3471
3576
  ClientSideSuspense,
3472
- CreateThreadError,
3473
- selectRoomThreads,
3474
3577
  RoomContext,
3578
+ ClientContext,
3579
+ selectThreads,
3580
+ getUmbrellaStoreForClient,
3581
+ useClient,
3582
+ LiveblocksProvider,
3583
+ createLiveblocksContext,
3584
+ useInboxNotifications,
3585
+ useInboxNotificationsSuspense,
3586
+ useMarkAllInboxNotificationsAsRead,
3587
+ useMarkInboxNotificationAsRead,
3588
+ useDeleteAllInboxNotifications,
3589
+ useDeleteInboxNotification,
3590
+ useUnreadInboxNotificationsCount,
3591
+ useUnreadInboxNotificationsCountSuspense,
3592
+ useRoomInfo,
3593
+ useRoomInfoSuspense,
3594
+ _useInboxNotificationThread,
3595
+ _useUser,
3596
+ _useUserSuspense,
3597
+ _useUserThreads_experimental,
3598
+ _useUserThreadsSuspense_experimental,
3599
+ CreateThreadError,
3475
3600
  useStatus,
3476
3601
  useStorageStatus,
3477
3602
  useBatch,
@@ -3525,26 +3650,6 @@ export {
3525
3650
  _useSelf,
3526
3651
  _useSelfSuspense,
3527
3652
  _useStorageRoot,
3528
- _useUpdateMyPresence,
3529
- ClientContext,
3530
- getUmbrellaStoreForClient,
3531
- useClient,
3532
- LiveblocksProvider,
3533
- createLiveblocksContext,
3534
- useInboxNotifications,
3535
- useInboxNotificationsSuspense,
3536
- useMarkAllInboxNotificationsAsRead,
3537
- useMarkInboxNotificationAsRead,
3538
- useDeleteAllInboxNotifications,
3539
- useDeleteInboxNotification,
3540
- useUnreadInboxNotificationsCount,
3541
- useUnreadInboxNotificationsCountSuspense,
3542
- useRoomInfo,
3543
- useRoomInfoSuspense,
3544
- _useInboxNotificationThread,
3545
- _useUser,
3546
- _useUserSuspense,
3547
- _useUserThreads_experimental,
3548
- _useUserThreadsSuspense_experimental
3653
+ _useUpdateMyPresence
3549
3654
  };
3550
- //# sourceMappingURL=chunk-OKR7ROQ5.mjs.map
3655
+ //# sourceMappingURL=chunk-QC6HYSYS.mjs.map