@liveblocks/react 2.2.3-alpha1 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
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(); } } 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; }// src/version.ts
2
2
  var PKG_NAME = "@liveblocks/react";
3
- var PKG_VERSION = "2.2.3-alpha1";
3
+ var PKG_VERSION = "2.3.0";
4
4
  var PKG_FORMAT = "cjs";
5
5
 
6
6
  // src/ClientSideSuspense.tsx
@@ -20,6 +20,8 @@ function ClientSideSuspense(props) {
20
20
 
21
21
 
22
22
 
23
+
24
+
23
25
  var _core = require('@liveblocks/core');
24
26
  var _nanoid = require('nanoid');
25
27
 
@@ -43,6 +45,7 @@ function selectedInboxNotifications(state) {
43
45
  }
44
46
 
45
47
  // src/lib/retry-error.ts
48
+
46
49
  var MAX_ERROR_RETRY_COUNT = 5;
47
50
  var ERROR_RETRY_INTERVAL = 5e3;
48
51
  function retryError(action, retryCount) {
@@ -52,6 +55,23 @@ function retryError(action, retryCount) {
52
55
  void action();
53
56
  }, timeout);
54
57
  }
58
+ async function autoRetry(promiseFn, maxTries, backoff) {
59
+ const fallbackBackoff = backoff.length > 0 ? backoff[backoff.length - 1] : 0;
60
+ let attempt = 0;
61
+ while (true) {
62
+ attempt++;
63
+ const promise = promiseFn();
64
+ try {
65
+ return await promise;
66
+ } catch (err) {
67
+ if (attempt >= maxTries) {
68
+ throw new Error(`Failed after ${maxTries} attempts: ${String(err)}`);
69
+ }
70
+ }
71
+ const delay = _nullishCoalesce(backoff[attempt - 1], () => ( fallbackBackoff));
72
+ await _core.wait.call(void 0, delay);
73
+ }
74
+ }
55
75
 
56
76
  // src/lib/use-initial.ts
57
77
 
@@ -83,6 +103,33 @@ function useInitialUnlessFunction(latestValue) {
83
103
  }
84
104
  }
85
105
 
106
+ // src/lib/use-polyfill.ts
107
+ var use = (
108
+ // React.use ||
109
+ (promise) => {
110
+ if (promise.status === "pending") {
111
+ throw promise;
112
+ } else if (promise.status === "fulfilled") {
113
+ return promise.value;
114
+ } else if (promise.status === "rejected") {
115
+ throw promise.reason;
116
+ } else {
117
+ promise.status = "pending";
118
+ promise.then(
119
+ (v) => {
120
+ promise.status = "fulfilled";
121
+ promise.value = v;
122
+ },
123
+ (e) => {
124
+ promise.status = "rejected";
125
+ promise.reason = e;
126
+ }
127
+ );
128
+ throw promise;
129
+ }
130
+ }
131
+ );
132
+
86
133
  // src/liveblocks.tsx
87
134
  var ClientContext = _react.createContext.call(void 0, null);
88
135
  function missingUserError(userId) {
@@ -115,12 +162,6 @@ function selectorFor_useInboxNotifications(state) {
115
162
  isLoading: false
116
163
  };
117
164
  }
118
- function selectorFor_useInboxNotificationsSuspense(state) {
119
- return {
120
- inboxNotifications: selectedInboxNotifications(state),
121
- isLoading: false
122
- };
123
- }
124
165
  function selectUnreadInboxNotificationsCount(state) {
125
166
  let count = 0;
126
167
  for (const notification of selectedInboxNotifications(state)) {
@@ -148,10 +189,40 @@ function selectorFor_useUnreadInboxNotificationsCount(state) {
148
189
  count: selectUnreadInboxNotificationsCount(state)
149
190
  };
150
191
  }
151
- function selectorFor_useUnreadInboxNotificationsCountSuspense(state) {
192
+ function selectorFor_useUser(state, userId) {
193
+ if (state === void 0 || _optionalChain([state, 'optionalAccess', _2 => _2.isLoading])) {
194
+ return _nullishCoalesce(state, () => ( { isLoading: true }));
195
+ }
196
+ if (state.error) {
197
+ return state;
198
+ }
199
+ if (!state.data) {
200
+ return {
201
+ isLoading: false,
202
+ error: missingUserError(userId)
203
+ };
204
+ }
205
+ return {
206
+ isLoading: false,
207
+ user: state.data
208
+ };
209
+ }
210
+ function selectorFor_useRoomInfo(state, roomId) {
211
+ if (state === void 0 || _optionalChain([state, 'optionalAccess', _3 => _3.isLoading])) {
212
+ return _nullishCoalesce(state, () => ( { isLoading: true }));
213
+ }
214
+ if (state.error) {
215
+ return state;
216
+ }
217
+ if (!state.data) {
218
+ return {
219
+ isLoading: false,
220
+ error: missingRoomInfoError(roomId)
221
+ };
222
+ }
152
223
  return {
153
224
  isLoading: false,
154
- count: selectUnreadInboxNotificationsCount(state)
225
+ info: state.data
155
226
  };
156
227
  }
157
228
  function getOrCreateContextBundle(client) {
@@ -174,93 +245,84 @@ function makeExtrasForClient(client) {
174
245
  const internals = client[_core.kInternal];
175
246
  const store = internals.cacheStore;
176
247
  const notifications = internals.notifications;
177
- let fetchInboxNotifications$ = null;
178
248
  let lastRequestedAt;
179
- const poller = _core.makePoller.call(void 0,
180
- () => notifications.getInboxNotifications({ since: lastRequestedAt }).then(
181
- (result) => {
182
- lastRequestedAt = result.meta.requestedAt;
183
- store.updateThreadsAndNotifications(
184
- result.threads,
185
- result.inboxNotifications,
186
- result.deletedThreads,
187
- result.deletedInboxNotifications,
188
- INBOX_NOTIFICATIONS_QUERY
189
- );
190
- },
191
- () => {
192
- }
193
- )
194
- );
195
- async function fetchInboxNotifications({ retryCount } = { retryCount: 0 }) {
196
- if (fetchInboxNotifications$ !== null) {
197
- return fetchInboxNotifications$;
249
+ async function fetchInboxNotifications() {
250
+ const since = lastRequestedAt !== void 0 ? { since: lastRequestedAt } : void 0;
251
+ const result = await notifications.getInboxNotifications(since);
252
+ store.updateThreadsAndNotifications(
253
+ result.threads,
254
+ result.inboxNotifications,
255
+ result.deletedThreads,
256
+ result.deletedInboxNotifications,
257
+ INBOX_NOTIFICATIONS_QUERY
258
+ );
259
+ if (lastRequestedAt === void 0 || lastRequestedAt < result.meta.requestedAt) {
260
+ lastRequestedAt = result.meta.requestedAt;
198
261
  }
262
+ }
263
+ let pollerSubscribers = 0;
264
+ const poller = _core.makePoller.call(void 0, async () => {
265
+ try {
266
+ await waitUntilInboxNotificationsLoaded();
267
+ await fetchInboxNotifications();
268
+ } catch (err) {
269
+ console.warn(`Polling new inbox notifications failed: ${String(err)}`);
270
+ }
271
+ });
272
+ const waitUntilInboxNotificationsLoaded = _core.memoizeOnSuccess.call(void 0, async () => {
199
273
  store.setQueryState(INBOX_NOTIFICATIONS_QUERY, {
200
274
  isLoading: true
201
275
  });
202
276
  try {
203
- fetchInboxNotifications$ = notifications.getInboxNotifications();
204
- const result = await fetchInboxNotifications$;
205
- store.updateThreadsAndNotifications(
206
- result.threads,
207
- result.inboxNotifications,
208
- result.deletedThreads,
209
- result.deletedInboxNotifications,
210
- INBOX_NOTIFICATIONS_QUERY
277
+ await autoRetry(
278
+ () => fetchInboxNotifications(),
279
+ 5,
280
+ [5e3, 5e3, 1e4, 15e3]
211
281
  );
212
- if (lastRequestedAt === void 0 || lastRequestedAt > result.meta.requestedAt) {
213
- lastRequestedAt = result.meta.requestedAt;
214
- }
215
- poller.start(POLLING_INTERVAL);
216
- } catch (er) {
217
- fetchInboxNotifications$ = null;
218
- retryError(() => {
219
- void fetchInboxNotifications({
220
- retryCount: retryCount + 1
221
- });
222
- }, retryCount);
282
+ } catch (err) {
223
283
  store.setQueryState(INBOX_NOTIFICATIONS_QUERY, {
224
284
  isLoading: false,
225
- error: er
285
+ error: err
226
286
  });
287
+ throw err;
227
288
  }
228
- return;
289
+ });
290
+ function loadInboxNotifications() {
291
+ void waitUntilInboxNotificationsLoaded().catch(() => {
292
+ });
229
293
  }
230
- let inboxNotificationsSubscribers = 0;
231
- function useSubscribeToInboxNotificationsEffect(options) {
232
- const autoFetch = useInitial(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _ => _.autoFetch]), () => ( true)));
294
+ function useEnableInboxNotificationsPolling() {
233
295
  _react.useEffect.call(void 0, () => {
234
- if (autoFetch) {
235
- void fetchInboxNotifications();
236
- }
237
- inboxNotificationsSubscribers++;
296
+ pollerSubscribers++;
238
297
  poller.start(POLLING_INTERVAL);
239
298
  return () => {
240
- if (inboxNotificationsSubscribers <= 0) {
299
+ if (pollerSubscribers <= 0) {
241
300
  console.warn(
242
301
  `Internal unexpected behavior. Cannot decrease subscriber count for query "${INBOX_NOTIFICATIONS_QUERY}"`
243
302
  );
244
303
  return;
245
304
  }
246
- inboxNotificationsSubscribers--;
247
- if (inboxNotificationsSubscribers <= 0) {
305
+ pollerSubscribers--;
306
+ if (pollerSubscribers <= 0) {
248
307
  poller.stop();
249
308
  }
250
309
  };
251
- }, [autoFetch]);
310
+ }, []);
252
311
  }
253
312
  return {
254
313
  store,
255
314
  notifications,
256
- fetchInboxNotifications,
257
- useSubscribeToInboxNotificationsEffect
315
+ useEnableInboxNotificationsPolling,
316
+ waitUntilInboxNotificationsLoaded,
317
+ loadInboxNotifications
258
318
  };
259
319
  }
260
320
  function makeLiveblocksContextBundle(client) {
261
321
  const useInboxNotificationThread2 = (inboxNotificationId) => useInboxNotificationThread_withClient(client, inboxNotificationId);
262
322
  const useMarkInboxNotificationAsRead2 = () => useMarkInboxNotificationAsRead_withClient(client);
263
323
  const useMarkAllInboxNotificationsAsRead2 = () => useMarkAllInboxNotificationsAsRead_withClient(client);
324
+ const useDeleteInboxNotification2 = () => useDeleteInboxNotification_withClient(client);
325
+ const useDeleteAllInboxNotifications2 = () => useDeleteAllInboxNotifications_withClient(client);
264
326
  function LiveblocksProvider2(props) {
265
327
  useEnsureNoLiveblocksProvider();
266
328
  return /* @__PURE__ */ React.default.createElement(ClientContext.Provider, { value: client }, props.children);
@@ -272,6 +334,8 @@ function makeLiveblocksContextBundle(client) {
272
334
  useUnreadInboxNotificationsCount: () => useUnreadInboxNotificationsCount_withClient(client),
273
335
  useMarkInboxNotificationAsRead: useMarkInboxNotificationAsRead2,
274
336
  useMarkAllInboxNotificationsAsRead: useMarkAllInboxNotificationsAsRead2,
337
+ useDeleteInboxNotification: useDeleteInboxNotification2,
338
+ useDeleteAllInboxNotifications: useDeleteAllInboxNotifications2,
275
339
  useInboxNotificationThread: useInboxNotificationThread2,
276
340
  ...shared.classic,
277
341
  suspense: {
@@ -280,6 +344,8 @@ function makeLiveblocksContextBundle(client) {
280
344
  useUnreadInboxNotificationsCount: () => useUnreadInboxNotificationsCountSuspense_withClient(client),
281
345
  useMarkInboxNotificationAsRead: useMarkInboxNotificationAsRead2,
282
346
  useMarkAllInboxNotificationsAsRead: useMarkAllInboxNotificationsAsRead2,
347
+ useDeleteInboxNotification: useDeleteInboxNotification2,
348
+ useDeleteAllInboxNotifications: useDeleteAllInboxNotifications2,
283
349
  useInboxNotificationThread: useInboxNotificationThread2,
284
350
  ...shared.suspense
285
351
  }
@@ -287,8 +353,11 @@ function makeLiveblocksContextBundle(client) {
287
353
  return bundle;
288
354
  }
289
355
  function useInboxNotifications_withClient(client) {
290
- const { store, useSubscribeToInboxNotificationsEffect } = getExtrasForClient(client);
291
- useSubscribeToInboxNotificationsEffect();
356
+ const { loadInboxNotifications, store, useEnableInboxNotificationsPolling } = getExtrasForClient(client);
357
+ _react.useEffect.call(void 0, () => {
358
+ loadInboxNotifications();
359
+ }, [loadInboxNotifications]);
360
+ useEnableInboxNotificationsPolling();
292
361
  return _withselectorjs.useSyncExternalStoreWithSelector.call(void 0,
293
362
  store.subscribe,
294
363
  store.get,
@@ -298,30 +367,19 @@ function useInboxNotifications_withClient(client) {
298
367
  );
299
368
  }
300
369
  function useInboxNotificationsSuspense_withClient(client) {
301
- const {
302
- store,
303
- fetchInboxNotifications,
304
- useSubscribeToInboxNotificationsEffect
305
- } = getExtrasForClient(client);
306
- const query = store.get().queries[INBOX_NOTIFICATIONS_QUERY];
307
- if (query === void 0 || query.isLoading) {
308
- throw fetchInboxNotifications();
309
- }
310
- if (query.error !== void 0) {
311
- throw query.error;
312
- }
313
- useSubscribeToInboxNotificationsEffect({ autoFetch: false });
314
- return _withselectorjs.useSyncExternalStoreWithSelector.call(void 0,
315
- store.subscribe,
316
- store.get,
317
- store.get,
318
- selectorFor_useInboxNotificationsSuspense,
319
- _core.shallow
320
- );
370
+ const { waitUntilInboxNotificationsLoaded } = getExtrasForClient(client);
371
+ use(waitUntilInboxNotificationsLoaded());
372
+ const result = useInboxNotifications_withClient(client);
373
+ _core.assert.call(void 0, !result.error, "Did not expect error");
374
+ _core.assert.call(void 0, !result.isLoading, "Did not expect loading");
375
+ return result;
321
376
  }
322
377
  function useUnreadInboxNotificationsCount_withClient(client) {
323
- const { store, useSubscribeToInboxNotificationsEffect } = getExtrasForClient(client);
324
- useSubscribeToInboxNotificationsEffect();
378
+ const { store, loadInboxNotifications, useEnableInboxNotificationsPolling } = getExtrasForClient(client);
379
+ _react.useEffect.call(void 0, () => {
380
+ loadInboxNotifications();
381
+ }, [loadInboxNotifications]);
382
+ useEnableInboxNotificationsPolling();
325
383
  return _withselectorjs.useSyncExternalStoreWithSelector.call(void 0,
326
384
  store.subscribe,
327
385
  store.get,
@@ -331,23 +389,12 @@ function useUnreadInboxNotificationsCount_withClient(client) {
331
389
  );
332
390
  }
333
391
  function useUnreadInboxNotificationsCountSuspense_withClient(client) {
334
- const {
335
- store,
336
- fetchInboxNotifications,
337
- useSubscribeToInboxNotificationsEffect
338
- } = getExtrasForClient(client);
339
- const query = store.get().queries[INBOX_NOTIFICATIONS_QUERY];
340
- if (query === void 0 || query.isLoading) {
341
- throw fetchInboxNotifications();
342
- }
343
- useSubscribeToInboxNotificationsEffect({ autoFetch: false });
344
- return _withselectorjs.useSyncExternalStoreWithSelector.call(void 0,
345
- store.subscribe,
346
- store.get,
347
- store.get,
348
- selectorFor_useUnreadInboxNotificationsCountSuspense,
349
- _core.shallow
350
- );
392
+ const { waitUntilInboxNotificationsLoaded } = getExtrasForClient(client);
393
+ use(waitUntilInboxNotificationsLoaded());
394
+ const result = useUnreadInboxNotificationsCount_withClient(client);
395
+ _core.assert.call(void 0, !result.isLoading, "Did not expect loading");
396
+ _core.assert.call(void 0, !result.error, "Did not expect error");
397
+ return result;
351
398
  }
352
399
  function useMarkInboxNotificationAsRead_withClient(client) {
353
400
  return _react.useCallback.call(void 0,
@@ -407,7 +454,7 @@ function useMarkAllInboxNotificationsAsRead_withClient(client) {
407
454
  const optimisticUpdateId = _nanoid.nanoid.call(void 0, );
408
455
  const readAt = /* @__PURE__ */ new Date();
409
456
  store.pushOptimisticUpdate({
410
- type: "mark-inbox-notifications-as-read",
457
+ type: "mark-all-inbox-notifications-as-read",
411
458
  id: optimisticUpdateId,
412
459
  readAt
413
460
  });
@@ -439,6 +486,84 @@ function useMarkAllInboxNotificationsAsRead_withClient(client) {
439
486
  );
440
487
  }, [client]);
441
488
  }
489
+ function useDeleteInboxNotification_withClient(client) {
490
+ return _react.useCallback.call(void 0,
491
+ (inboxNotificationId) => {
492
+ const { store, notifications } = getExtrasForClient(client);
493
+ const optimisticUpdateId = _nanoid.nanoid.call(void 0, );
494
+ const deletedAt = /* @__PURE__ */ new Date();
495
+ store.pushOptimisticUpdate({
496
+ type: "delete-inbox-notification",
497
+ id: optimisticUpdateId,
498
+ inboxNotificationId,
499
+ deletedAt
500
+ });
501
+ notifications.deleteInboxNotification(inboxNotificationId).then(
502
+ () => {
503
+ store.set((state) => {
504
+ const existingNotification = state.inboxNotifications[inboxNotificationId];
505
+ if (existingNotification === void 0) {
506
+ return {
507
+ ...state,
508
+ optimisticUpdates: state.optimisticUpdates.filter(
509
+ (update) => update.id !== optimisticUpdateId
510
+ )
511
+ };
512
+ }
513
+ const { [inboxNotificationId]: _, ...inboxNotifications } = state.inboxNotifications;
514
+ return {
515
+ ...state,
516
+ inboxNotifications,
517
+ optimisticUpdates: state.optimisticUpdates.filter(
518
+ (update) => update.id !== optimisticUpdateId
519
+ )
520
+ };
521
+ });
522
+ },
523
+ () => {
524
+ store.set((state) => ({
525
+ ...state,
526
+ optimisticUpdates: state.optimisticUpdates.filter(
527
+ (update) => update.id !== optimisticUpdateId
528
+ )
529
+ }));
530
+ }
531
+ );
532
+ },
533
+ [client]
534
+ );
535
+ }
536
+ function useDeleteAllInboxNotifications_withClient(client) {
537
+ return _react.useCallback.call(void 0, () => {
538
+ const { store, notifications } = getExtrasForClient(client);
539
+ const optimisticUpdateId = _nanoid.nanoid.call(void 0, );
540
+ const deletedAt = /* @__PURE__ */ new Date();
541
+ store.pushOptimisticUpdate({
542
+ type: "delete-all-inbox-notifications",
543
+ id: optimisticUpdateId,
544
+ deletedAt
545
+ });
546
+ notifications.deleteAllInboxNotifications().then(
547
+ () => {
548
+ store.set((state) => ({
549
+ ...state,
550
+ inboxNotifications: {},
551
+ optimisticUpdates: state.optimisticUpdates.filter(
552
+ (update) => update.id !== optimisticUpdateId
553
+ )
554
+ }));
555
+ },
556
+ () => {
557
+ store.set((state) => ({
558
+ ...state,
559
+ optimisticUpdates: state.optimisticUpdates.filter(
560
+ (update) => update.id !== optimisticUpdateId
561
+ )
562
+ }));
563
+ }
564
+ );
565
+ }, [client]);
566
+ }
442
567
  function useInboxNotificationThread_withClient(client, inboxNotificationId) {
443
568
  const { store } = getExtrasForClient(client);
444
569
  const selector = _react.useCallback.call(void 0,
@@ -472,17 +597,17 @@ function useUser_withClient(client, userId) {
472
597
  _react.useEffect.call(void 0, () => {
473
598
  void usersStore.get(userId);
474
599
  }, [usersStore, userId]);
475
- const state = _indexjs.useSyncExternalStore.call(void 0,
600
+ const selector = _react.useCallback.call(void 0,
601
+ (state) => selectorFor_useUser(state, userId),
602
+ [userId]
603
+ );
604
+ return _withselectorjs.useSyncExternalStoreWithSelector.call(void 0,
476
605
  usersStore.subscribe,
477
606
  getUserState,
478
- getUserState
607
+ getUserState,
608
+ selector,
609
+ _core.shallow
479
610
  );
480
- return state ? {
481
- isLoading: state.isLoading,
482
- user: state.data,
483
- // Return an error if `undefined` was returned by `resolveUsers` for this user ID
484
- error: !state.isLoading && !state.data && !state.error ? missingUserError(userId) : state.error
485
- } : { isLoading: true };
486
611
  }
487
612
  function useUserSuspense_withClient(client, userId) {
488
613
  const usersStore = client[_core.kInternal].usersStore;
@@ -505,10 +630,13 @@ function useUserSuspense_withClient(client, userId) {
505
630
  getUserState,
506
631
  getUserState
507
632
  );
633
+ _core.assert.call(void 0, state !== void 0, "Unexpected missing state");
634
+ _core.assert.call(void 0, !state.isLoading, "Unexpected loading state");
635
+ _core.assert.call(void 0, !state.error, "Unexpected error state");
508
636
  return {
509
637
  isLoading: false,
510
- user: _optionalChain([state, 'optionalAccess', _2 => _2.data]),
511
- error: _optionalChain([state, 'optionalAccess', _3 => _3.error])
638
+ user: state.data,
639
+ error: void 0
512
640
  };
513
641
  }
514
642
  function useRoomInfo_withClient(client, roomId) {
@@ -517,20 +645,20 @@ function useRoomInfo_withClient(client, roomId) {
517
645
  () => roomsInfoStore.getState(roomId),
518
646
  [roomsInfoStore, roomId]
519
647
  );
648
+ const selector = _react.useCallback.call(void 0,
649
+ (state) => selectorFor_useRoomInfo(state, roomId),
650
+ [roomId]
651
+ );
520
652
  _react.useEffect.call(void 0, () => {
521
653
  void roomsInfoStore.get(roomId);
522
654
  }, [roomsInfoStore, roomId]);
523
- const state = _indexjs.useSyncExternalStore.call(void 0,
655
+ return _withselectorjs.useSyncExternalStoreWithSelector.call(void 0,
524
656
  roomsInfoStore.subscribe,
525
657
  getRoomInfoState,
526
- getRoomInfoState
658
+ getRoomInfoState,
659
+ selector,
660
+ _core.shallow
527
661
  );
528
- return state ? {
529
- isLoading: state.isLoading,
530
- info: state.data,
531
- // Return an error if `undefined` was returned by `resolveRoomsInfo` for this room ID
532
- error: !state.isLoading && !state.data && !state.error ? missingRoomInfoError(roomId) : state.error
533
- } : { isLoading: true };
534
662
  }
535
663
  function useRoomInfoSuspense_withClient(client, roomId) {
536
664
  const roomsInfoStore = client[_core.kInternal].roomsInfoStore;
@@ -553,10 +681,14 @@ function useRoomInfoSuspense_withClient(client, roomId) {
553
681
  getRoomInfoState,
554
682
  getRoomInfoState
555
683
  );
684
+ _core.assert.call(void 0, state !== void 0, "Unexpected missing state");
685
+ _core.assert.call(void 0, !state.isLoading, "Unexpected loading state");
686
+ _core.assert.call(void 0, !state.error, "Unexpected error state");
687
+ _core.assert.call(void 0, state.data !== void 0, "Unexpected missing room info data");
556
688
  return {
557
689
  isLoading: false,
558
- info: _optionalChain([state, 'optionalAccess', _4 => _4.data]),
559
- error: _optionalChain([state, 'optionalAccess', _5 => _5.error])
690
+ info: state.data,
691
+ error: void 0
560
692
  };
561
693
  }
562
694
  function createSharedContext(client) {
@@ -576,7 +708,7 @@ function createSharedContext(client) {
576
708
  }
577
709
  function useEnsureNoLiveblocksProvider(options) {
578
710
  const existing = useClientOrNull();
579
- if (!_optionalChain([options, 'optionalAccess', _6 => _6.allowNesting]) && existing !== null) {
711
+ if (!_optionalChain([options, 'optionalAccess', _4 => _4.allowNesting]) && existing !== null) {
580
712
  throw new Error(
581
713
  "You cannot nest multiple LiveblocksProvider instances in the same React tree."
582
714
  );
@@ -641,6 +773,12 @@ function useMarkAllInboxNotificationsAsRead() {
641
773
  function useMarkInboxNotificationAsRead() {
642
774
  return useMarkInboxNotificationAsRead_withClient(useClient());
643
775
  }
776
+ function useDeleteAllInboxNotifications() {
777
+ return useDeleteAllInboxNotifications_withClient(useClient());
778
+ }
779
+ function useDeleteInboxNotification() {
780
+ return useDeleteInboxNotification_withClient(useClient());
781
+ }
644
782
  function useUnreadInboxNotificationsCount() {
645
783
  return useUnreadInboxNotificationsCount_withClient(useClient());
646
784
  }
@@ -777,6 +915,9 @@ function selectedThreads(roomId, state, options) {
777
915
  }
778
916
  const query = options.query;
779
917
  if (!query) return true;
918
+ if (query.resolved !== void 0 && thread.resolved !== query.resolved) {
919
+ return false;
920
+ }
780
921
  for (const key in query.metadata) {
781
922
  const metadataValue = thread.metadata[key];
782
923
  const filterValue = query.metadata[key];
@@ -851,33 +992,6 @@ function selectNotificationSettings(roomId, state) {
851
992
  return _core.nn.call(void 0, notificationSettings[roomId]);
852
993
  }
853
994
 
854
- // src/lib/use-polyfill.ts
855
- var use = (
856
- // React.use ||
857
- (promise) => {
858
- if (promise.status === "pending") {
859
- throw promise;
860
- } else if (promise.status === "fulfilled") {
861
- return promise.value;
862
- } else if (promise.status === "rejected") {
863
- throw promise.reason;
864
- } else {
865
- promise.status = "pending";
866
- promise.then(
867
- (v) => {
868
- promise.status = "fulfilled";
869
- promise.value = v;
870
- },
871
- (e) => {
872
- promise.status = "rejected";
873
- promise.reason = e;
874
- }
875
- );
876
- throw promise;
877
- }
878
- }
879
- );
880
-
881
995
  // src/use-scroll-to-comment-on-load-effect.ts
882
996
 
883
997
  function handleScrollToCommentOnLoad(shouldScrollOnLoad, state) {
@@ -980,7 +1094,7 @@ function getCurrentUserId(room) {
980
1094
  }
981
1095
  function handleApiError(err) {
982
1096
  const message = `Request failed with status ${err.status}: ${err.message}`;
983
- if (_optionalChain([err, 'access', _7 => _7.details, 'optionalAccess', _8 => _8.error]) === "FORBIDDEN") {
1097
+ if (_optionalChain([err, 'access', _5 => _5.details, 'optionalAccess', _6 => _6.error]) === "FORBIDDEN") {
984
1098
  const detailedMessage = [message, err.details.suggestion, err.details.docs].filter(Boolean).join("\n");
985
1099
  _core.console.error(detailedMessage);
986
1100
  }
@@ -1402,7 +1516,7 @@ function useStatus() {
1402
1516
  return useSyncExternalStore2(subscribe, getSnapshot, getServerSnapshot);
1403
1517
  }
1404
1518
  function useStorageStatus(options) {
1405
- const smooth = useInitial(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _9 => _9.smooth]), () => ( false)));
1519
+ const smooth = useInitial(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _7 => _7.smooth]), () => ( false)));
1406
1520
  if (smooth) {
1407
1521
  return useStorageStatusSmooth();
1408
1522
  } else {
@@ -1782,7 +1896,7 @@ function useDeleteThread() {
1782
1896
  const { store, onMutationFailure } = getExtrasForClient2(client);
1783
1897
  const thread = store.get().threads[threadId];
1784
1898
  const userId = getCurrentUserId(room);
1785
- if (_optionalChain([thread, 'optionalAccess', _10 => _10.comments, 'optionalAccess', _11 => _11[0], 'optionalAccess', _12 => _12.userId]) !== userId) {
1899
+ if (_optionalChain([thread, 'optionalAccess', _8 => _8.comments, 'optionalAccess', _9 => _9[0], 'optionalAccess', _10 => _10.userId]) !== userId) {
1786
1900
  throw new Error("Only the thread creator can delete the thread");
1787
1901
  }
1788
1902
  store.pushOptimisticUpdate({
@@ -2753,5 +2867,7 @@ var _useUpdateMyPresence = useUpdateMyPresence;
2753
2867
 
2754
2868
 
2755
2869
 
2756
- exports.PKG_NAME = PKG_NAME; exports.PKG_VERSION = PKG_VERSION; exports.PKG_FORMAT = PKG_FORMAT; exports.ClientSideSuspense = ClientSideSuspense; exports.ClientContext = ClientContext; exports.useClient = useClient; exports.LiveblocksProvider = LiveblocksProvider; exports.createLiveblocksContext = createLiveblocksContext; exports.useInboxNotifications = useInboxNotifications; exports.useInboxNotificationsSuspense = useInboxNotificationsSuspense; exports.useMarkAllInboxNotificationsAsRead = useMarkAllInboxNotificationsAsRead; exports.useMarkInboxNotificationAsRead = useMarkInboxNotificationAsRead; exports.useUnreadInboxNotificationsCount = useUnreadInboxNotificationsCount; exports.useUnreadInboxNotificationsCountSuspense = useUnreadInboxNotificationsCountSuspense; exports.useRoomInfo = useRoomInfo; exports.useRoomInfoSuspense = useRoomInfoSuspense; exports._useInboxNotificationThread = _useInboxNotificationThread; exports._useUser = _useUser; exports._useUserSuspense = _useUserSuspense; exports.CreateThreadError = CreateThreadError; exports.selectedThreads = selectedThreads; exports.RoomContext = RoomContext; exports.useStatus = useStatus; exports.useStorageStatus = useStorageStatus; exports.useBatch = useBatch; exports.useLostConnectionListener = useLostConnectionListener; exports.useErrorListener = useErrorListener; exports.useHistory = useHistory; exports.useUndo = useUndo; exports.useRedo = useRedo; exports.useCanUndo = useCanUndo; exports.useCanRedo = useCanRedo; exports.useOthersConnectionIds = useOthersConnectionIds; exports.useCommentsErrorListener = useCommentsErrorListener; exports.useCreateComment = useCreateComment; exports.useEditComment = useEditComment; exports.useDeleteComment = useDeleteComment; exports.useRemoveReaction = useRemoveReaction; exports.useMarkThreadAsRead = useMarkThreadAsRead; exports.useMarkThreadAsResolved = useMarkThreadAsResolved; exports.useMarkThreadAsUnresolved = useMarkThreadAsUnresolved; exports.useThreadSubscription = useThreadSubscription; exports.useRoomNotificationSettings = useRoomNotificationSettings; exports.useUpdateRoomNotificationSettings = useUpdateRoomNotificationSettings; exports.useOthersConnectionIdsSuspense = useOthersConnectionIdsSuspense; exports.useStorageStatusSuspense = useStorageStatusSuspense; exports.createRoomContext = createRoomContext; exports._RoomProvider = _RoomProvider; exports._useBroadcastEvent = _useBroadcastEvent; exports._useOthersListener = _useOthersListener; exports._useRoom = _useRoom; exports._useAddReaction = _useAddReaction; exports._useMutation = _useMutation; exports._useCreateThread = _useCreateThread; exports._useDeleteThread = _useDeleteThread; exports._useEditThreadMetadata = _useEditThreadMetadata; exports._useEventListener = _useEventListener; exports._useMyPresence = _useMyPresence; exports._useOthersMapped = _useOthersMapped; exports._useOthersMappedSuspense = _useOthersMappedSuspense; exports._useThreads = _useThreads; exports._useThreadsSuspense = _useThreadsSuspense; exports._useOther = _useOther; exports._useOthers = _useOthers; exports._useOtherSuspense = _useOtherSuspense; exports._useOthersSuspense = _useOthersSuspense; exports._useStorage = _useStorage; exports._useStorageSuspense = _useStorageSuspense; exports._useSelf = _useSelf; exports._useSelfSuspense = _useSelfSuspense; exports._useStorageRoot = _useStorageRoot; exports._useUpdateMyPresence = _useUpdateMyPresence;
2757
- //# sourceMappingURL=chunk-OV7CUYL2.js.map
2870
+
2871
+
2872
+ exports.PKG_NAME = PKG_NAME; exports.PKG_VERSION = PKG_VERSION; exports.PKG_FORMAT = PKG_FORMAT; exports.ClientSideSuspense = ClientSideSuspense; exports.ClientContext = ClientContext; exports.useClient = useClient; exports.LiveblocksProvider = LiveblocksProvider; exports.createLiveblocksContext = createLiveblocksContext; exports.useInboxNotifications = useInboxNotifications; exports.useInboxNotificationsSuspense = useInboxNotificationsSuspense; exports.useMarkAllInboxNotificationsAsRead = useMarkAllInboxNotificationsAsRead; exports.useMarkInboxNotificationAsRead = useMarkInboxNotificationAsRead; exports.useDeleteAllInboxNotifications = useDeleteAllInboxNotifications; exports.useDeleteInboxNotification = useDeleteInboxNotification; exports.useUnreadInboxNotificationsCount = useUnreadInboxNotificationsCount; exports.useUnreadInboxNotificationsCountSuspense = useUnreadInboxNotificationsCountSuspense; exports.useRoomInfo = useRoomInfo; exports.useRoomInfoSuspense = useRoomInfoSuspense; exports._useInboxNotificationThread = _useInboxNotificationThread; exports._useUser = _useUser; exports._useUserSuspense = _useUserSuspense; exports.CreateThreadError = CreateThreadError; exports.selectedThreads = selectedThreads; exports.RoomContext = RoomContext; exports.useStatus = useStatus; exports.useStorageStatus = useStorageStatus; exports.useBatch = useBatch; exports.useLostConnectionListener = useLostConnectionListener; exports.useErrorListener = useErrorListener; exports.useHistory = useHistory; exports.useUndo = useUndo; exports.useRedo = useRedo; exports.useCanUndo = useCanUndo; exports.useCanRedo = useCanRedo; exports.useOthersConnectionIds = useOthersConnectionIds; exports.useCommentsErrorListener = useCommentsErrorListener; exports.useCreateComment = useCreateComment; exports.useEditComment = useEditComment; exports.useDeleteComment = useDeleteComment; exports.useRemoveReaction = useRemoveReaction; exports.useMarkThreadAsRead = useMarkThreadAsRead; exports.useMarkThreadAsResolved = useMarkThreadAsResolved; exports.useMarkThreadAsUnresolved = useMarkThreadAsUnresolved; exports.useThreadSubscription = useThreadSubscription; exports.useRoomNotificationSettings = useRoomNotificationSettings; exports.useUpdateRoomNotificationSettings = useUpdateRoomNotificationSettings; exports.useOthersConnectionIdsSuspense = useOthersConnectionIdsSuspense; exports.useStorageStatusSuspense = useStorageStatusSuspense; exports.createRoomContext = createRoomContext; exports._RoomProvider = _RoomProvider; exports._useBroadcastEvent = _useBroadcastEvent; exports._useOthersListener = _useOthersListener; exports._useRoom = _useRoom; exports._useAddReaction = _useAddReaction; exports._useMutation = _useMutation; exports._useCreateThread = _useCreateThread; exports._useDeleteThread = _useDeleteThread; exports._useEditThreadMetadata = _useEditThreadMetadata; exports._useEventListener = _useEventListener; exports._useMyPresence = _useMyPresence; exports._useOthersMapped = _useOthersMapped; exports._useOthersMappedSuspense = _useOthersMappedSuspense; exports._useThreads = _useThreads; exports._useThreadsSuspense = _useThreadsSuspense; exports._useOther = _useOther; exports._useOthers = _useOthers; exports._useOtherSuspense = _useOtherSuspense; exports._useOthersSuspense = _useOthersSuspense; exports._useStorage = _useStorage; exports._useStorageSuspense = _useStorageSuspense; exports._useSelf = _useSelf; exports._useSelfSuspense = _useSelfSuspense; exports._useStorageRoot = _useStorageRoot; exports._useUpdateMyPresence = _useUpdateMyPresence;
2873
+ //# sourceMappingURL=chunk-K5EDPAZP.js.map