@liveblocks/react 1.11.3 → 1.12.0-test2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -5,7 +5,7 @@ import { detectDupes } from "@liveblocks/core";
5
5
 
6
6
  // src/version.ts
7
7
  var PKG_NAME = "@liveblocks/react";
8
- var PKG_VERSION = "1.11.3";
8
+ var PKG_VERSION = "1.12.0-test2";
9
9
  var PKG_FORMAT = "esm";
10
10
 
11
11
  // src/ClientSideSuspense.tsx
@@ -194,7 +194,14 @@ function selectedThreads(roomId, state, options) {
194
194
  if (!query)
195
195
  return true;
196
196
  for (const key in query.metadata) {
197
- if (thread.metadata[key] !== query.metadata[key]) {
197
+ const metadataValue = thread.metadata[key];
198
+ const filterValue = query.metadata[key];
199
+ if (assertFilterIsStartsWithOperator(filterValue) && assertMetadataValueIsString(metadataValue)) {
200
+ if (metadataValue.startsWith(filterValue.startsWith)) {
201
+ return true;
202
+ }
203
+ }
204
+ if (metadataValue !== filterValue) {
198
205
  return false;
199
206
  }
200
207
  }
@@ -202,6 +209,16 @@ function selectedThreads(roomId, state, options) {
202
209
  });
203
210
  return threads.sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
204
211
  }
212
+ var assertFilterIsStartsWithOperator = (filter) => {
213
+ if (typeof filter === "object" && typeof filter.startsWith === "string") {
214
+ return true;
215
+ } else {
216
+ return false;
217
+ }
218
+ };
219
+ var assertMetadataValueIsString = (value) => {
220
+ return typeof value === "string";
221
+ };
205
222
 
206
223
  // src/lib/use-initial.ts
207
224
  import { useState as useState2 } from "react";
@@ -1304,7 +1321,9 @@ function createRoomContext(client, options) {
1304
1321
  }
1305
1322
  const inboxNotification = Object.values(
1306
1323
  state.inboxNotifications
1307
- ).find((notification) => notification.threadId === threadId);
1324
+ ).find(
1325
+ (notification) => notification.kind === "thread" && notification.threadId === threadId
1326
+ );
1308
1327
  const updatedInboxNotifications = inboxNotification !== void 0 ? {
1309
1328
  ...state.inboxNotifications,
1310
1329
  [inboxNotification.id]: {
@@ -1520,7 +1539,7 @@ function createRoomContext(client, options) {
1520
1539
  const selector = React2.useCallback(
1521
1540
  (state) => {
1522
1541
  const inboxNotification = selectedInboxNotifications(state).find(
1523
- (inboxNotification2) => inboxNotification2.threadId === threadId
1542
+ (inboxNotification2) => inboxNotification2.kind === "thread" && inboxNotification2.threadId === threadId
1524
1543
  );
1525
1544
  const thread = state.threads[threadId];
1526
1545
  if (inboxNotification === void 0 || thread === void 0) {
@@ -1548,7 +1567,9 @@ function createRoomContext(client, options) {
1548
1567
  (threadId) => {
1549
1568
  const inboxNotification = Object.values(
1550
1569
  store.get().inboxNotifications
1551
- ).find((inboxNotification2) => inboxNotification2.threadId === threadId);
1570
+ ).find(
1571
+ (inboxNotification2) => inboxNotification2.kind === "thread" && inboxNotification2.threadId === threadId
1572
+ );
1552
1573
  if (!inboxNotification)
1553
1574
  return;
1554
1575
  const optimisticUpdateId = nanoid2();
@@ -2266,18 +2287,29 @@ function createLiveblocksContext(client) {
2266
2287
  );
2267
2288
  }, []);
2268
2289
  }
2269
- function useThreadFromCache(threadId) {
2290
+ function useInboxNotificationThread(inboxNotificationId) {
2270
2291
  const selector = useCallback3(
2271
2292
  (state) => {
2272
- const thread = state.threads[threadId];
2293
+ const inboxNotification = state.inboxNotifications[inboxNotificationId];
2294
+ if (inboxNotification === void 0) {
2295
+ throw new Error(
2296
+ `Inbox notification with ID "${inboxNotificationId}" not found`
2297
+ );
2298
+ }
2299
+ if (inboxNotification.kind !== "thread") {
2300
+ throw new Error(
2301
+ `Inbox notification with ID "${inboxNotificationId}" is not of kind "thread"`
2302
+ );
2303
+ }
2304
+ const thread = state.threads[inboxNotification.threadId];
2273
2305
  if (thread === void 0) {
2274
2306
  throw new Error(
2275
- `Internal error: thread with id "${threadId}" not found in cache`
2307
+ `Thread with ID "${inboxNotification.threadId}" not found, this inbox notification might not be of kind "thread"`
2276
2308
  );
2277
2309
  }
2278
2310
  return thread;
2279
2311
  },
2280
- [threadId]
2312
+ [inboxNotificationId]
2281
2313
  );
2282
2314
  return useSyncExternalStoreWithSelector2(
2283
2315
  store.subscribe,
@@ -2300,6 +2332,7 @@ function createLiveblocksContext(client) {
2300
2332
  useUnreadInboxNotificationsCount,
2301
2333
  useMarkInboxNotificationAsRead,
2302
2334
  useMarkAllInboxNotificationsAsRead,
2335
+ useInboxNotificationThread,
2303
2336
  ...shared,
2304
2337
  suspense: {
2305
2338
  LiveblocksProvider,
@@ -2307,10 +2340,10 @@ function createLiveblocksContext(client) {
2307
2340
  useUnreadInboxNotificationsCount: useUnreadInboxNotificationsCountSuspense,
2308
2341
  useMarkInboxNotificationAsRead,
2309
2342
  useMarkAllInboxNotificationsAsRead,
2343
+ useInboxNotificationThread,
2310
2344
  ...shared.suspense
2311
2345
  },
2312
2346
  [kInternal3]: {
2313
- useThreadFromCache,
2314
2347
  useCurrentUserId
2315
2348
  }
2316
2349
  };