@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.d.mts CHANGED
@@ -2,7 +2,7 @@ import { ReactElement, ReactNode, PropsWithChildren } from 'react';
2
2
  import { JsonObject, LsonObject, BaseUserMeta, LiveObject, User, Json, RoomNotificationSettings, Room, Status, BroadcastOptions, OthersEvent, LostConnectionEvent, History, BaseMetadata as BaseMetadata$1, Client } from '@liveblocks/client';
3
3
  export { Json, JsonObject, shallow } from '@liveblocks/client';
4
4
  import * as _liveblocks_core from '@liveblocks/core';
5
- import { BaseMetadata, Resolve, ToImmutable, kInternal, ThreadData, InboxNotificationData, LiveblocksError, RoomEventMessage, CommentData, RoomInfo, CommentBody, PartialNullable, RoomInitializers, ResolveUsersArgs, OptionalPromise, ResolveMentionSuggestionsArgs, BaseUserMeta as BaseUserMeta$1 } from '@liveblocks/core';
5
+ import { BaseMetadata, QueryMetadata, Resolve, ToImmutable, kInternal, ThreadData, InboxNotificationData, LiveblocksError, RoomEventMessage, CommentData, RoomInfo, CommentBody, PartialNullable, RoomInitializers, ResolveUsersArgs, OptionalPromise, ResolveMentionSuggestionsArgs, BaseUserMeta as BaseUserMeta$1 } from '@liveblocks/core';
6
6
 
7
7
  declare type Props = {
8
8
  fallback: NonNullable<ReactNode> | null;
@@ -37,7 +37,7 @@ declare type UseThreadsOptions<TThreadMetadata extends BaseMetadata> = {
37
37
  * The metadata to filter the threads by. If provided, only threads with metadata that matches
38
38
  * the provided metadata will be returned. If not provided, all threads will be returned.
39
39
  */
40
- metadata?: Partial<TThreadMetadata>;
40
+ metadata?: Partial<QueryMetadata<TThreadMetadata>>;
41
41
  };
42
42
  /**
43
43
  * Whether to scroll to a comment on load based on the URL hash. Defaults to `true`.
@@ -952,7 +952,7 @@ declare type RoomContextBundle<TPresence extends JsonObject, TStorage extends Ls
952
952
  /**
953
953
  * Properties that are the same in LiveblocksContext and LiveblocksContext["suspense"].
954
954
  */
955
- declare type LiveblocksContextBundleCommon = {
955
+ declare type LiveblocksContextBundleCommon<TThreadMetadata extends BaseMetadata> = {
956
956
  /**
957
957
  * @beta
958
958
  *
@@ -980,6 +980,15 @@ declare type LiveblocksContextBundleCommon = {
980
980
  * markAllInboxNotificationsAsRead();
981
981
  */
982
982
  useMarkAllInboxNotificationsAsRead(): () => void;
983
+ /**
984
+ * @beta
985
+ *
986
+ * Returns the thread associated with a `"thread"` inbox notification.
987
+ *
988
+ * @example
989
+ * const thread = useInboxNotificationThread("in_xxx");
990
+ */
991
+ useInboxNotificationThread(inboxNotificationId: string): ThreadData<TThreadMetadata>;
983
992
  };
984
993
  /**
985
994
  * @private
@@ -989,15 +998,6 @@ declare type LiveblocksContextBundleCommon = {
989
998
  * will probably happen if you do.
990
999
  */
991
1000
  declare type PrivateLiveblocksContextApi = {
992
- /**
993
- * @private
994
- *
995
- * Returns a thread from the cache.
996
- *
997
- * @example
998
- * const thread = useThreadFromCache("th_xxx");
999
- */
1000
- useThreadFromCache(threadId: string): ThreadData<BaseMetadata>;
1001
1001
  /**
1002
1002
  * @private
1003
1003
  *
@@ -1005,7 +1005,7 @@ declare type PrivateLiveblocksContextApi = {
1005
1005
  */
1006
1006
  useCurrentUserId(): string | null;
1007
1007
  };
1008
- declare type LiveblocksContextBundle<TUserMeta extends BaseUserMeta> = Resolve<LiveblocksContextBundleCommon & Omit<SharedContextBundle<TUserMeta>, "suspense"> & {
1008
+ declare type LiveblocksContextBundle<TUserMeta extends BaseUserMeta, TThreadMetadata extends BaseMetadata> = Resolve<LiveblocksContextBundleCommon<TThreadMetadata> & Omit<SharedContextBundle<TUserMeta>, "suspense"> & {
1009
1009
  /**
1010
1010
  * @beta
1011
1011
  *
@@ -1024,7 +1024,7 @@ declare type LiveblocksContextBundle<TUserMeta extends BaseUserMeta> = Resolve<L
1024
1024
  * const { count, error, isLoading } = useUnreadInboxNotificationsCount();
1025
1025
  */
1026
1026
  useUnreadInboxNotificationsCount(): UnreadInboxNotificationsCountState;
1027
- suspense: Resolve<LiveblocksContextBundleCommon & SharedContextBundle<TUserMeta>["suspense"] & {
1027
+ suspense: Resolve<LiveblocksContextBundleCommon<TThreadMetadata> & SharedContextBundle<TUserMeta>["suspense"] & {
1028
1028
  /**
1029
1029
  * @beta
1030
1030
  *
@@ -1060,8 +1060,8 @@ declare type LiveblocksContextBundle<TUserMeta extends BaseUserMeta> = Resolve<L
1060
1060
  *
1061
1061
  * This is an internal API, use "createLiveblocksContext" instead.
1062
1062
  */
1063
- declare function useLiveblocksContextBundle(): LiveblocksContextBundle<BaseUserMeta>;
1064
- declare function createLiveblocksContext<TUserMeta extends BaseUserMeta = BaseUserMeta, TThreadMetadata extends BaseMetadata$1 = never>(client: Client): LiveblocksContextBundle<TUserMeta>;
1063
+ declare function useLiveblocksContextBundle(): LiveblocksContextBundle<BaseUserMeta, BaseMetadata$1>;
1064
+ declare function createLiveblocksContext<TUserMeta extends BaseUserMeta = BaseUserMeta, TThreadMetadata extends BaseMetadata$1 = never>(client: Client): LiveblocksContextBundle<TUserMeta, TThreadMetadata>;
1065
1065
 
1066
1066
  /**
1067
1067
  * @private
@@ -1092,6 +1092,6 @@ declare function createRoomContext<TPresence extends JsonObject, TStorage extend
1092
1092
  *
1093
1093
  * This is an internal API, use `createLiveblocksContext` or `createRoomContext` instead.
1094
1094
  */
1095
- declare function useSharedContextBundle(): RoomContextBundle<_liveblocks_core.JsonObject, _liveblocks_core.LsonObject, BaseUserMeta$1, never, _liveblocks_core.BaseMetadata> | LiveblocksContextBundle<BaseUserMeta$1>;
1095
+ declare function useSharedContextBundle(): RoomContextBundle<_liveblocks_core.JsonObject, _liveblocks_core.LsonObject, BaseUserMeta$1, never, _liveblocks_core.BaseMetadata> | LiveblocksContextBundle<BaseUserMeta$1, _liveblocks_core.BaseMetadata>;
1096
1096
 
1097
1097
  export { ClientSideSuspense, type MutationContext, type UseThreadsOptions, createLiveblocksContext, createRoomContext, useLiveblocksContextBundle, useRoomContextBundle, useSharedContextBundle };
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import { ReactElement, ReactNode, PropsWithChildren } from 'react';
2
2
  import { JsonObject, LsonObject, BaseUserMeta, LiveObject, User, Json, RoomNotificationSettings, Room, Status, BroadcastOptions, OthersEvent, LostConnectionEvent, History, BaseMetadata as BaseMetadata$1, Client } from '@liveblocks/client';
3
3
  export { Json, JsonObject, shallow } from '@liveblocks/client';
4
4
  import * as _liveblocks_core from '@liveblocks/core';
5
- import { BaseMetadata, Resolve, ToImmutable, kInternal, ThreadData, InboxNotificationData, LiveblocksError, RoomEventMessage, CommentData, RoomInfo, CommentBody, PartialNullable, RoomInitializers, ResolveUsersArgs, OptionalPromise, ResolveMentionSuggestionsArgs, BaseUserMeta as BaseUserMeta$1 } from '@liveblocks/core';
5
+ import { BaseMetadata, QueryMetadata, Resolve, ToImmutable, kInternal, ThreadData, InboxNotificationData, LiveblocksError, RoomEventMessage, CommentData, RoomInfo, CommentBody, PartialNullable, RoomInitializers, ResolveUsersArgs, OptionalPromise, ResolveMentionSuggestionsArgs, BaseUserMeta as BaseUserMeta$1 } from '@liveblocks/core';
6
6
 
7
7
  declare type Props = {
8
8
  fallback: NonNullable<ReactNode> | null;
@@ -37,7 +37,7 @@ declare type UseThreadsOptions<TThreadMetadata extends BaseMetadata> = {
37
37
  * The metadata to filter the threads by. If provided, only threads with metadata that matches
38
38
  * the provided metadata will be returned. If not provided, all threads will be returned.
39
39
  */
40
- metadata?: Partial<TThreadMetadata>;
40
+ metadata?: Partial<QueryMetadata<TThreadMetadata>>;
41
41
  };
42
42
  /**
43
43
  * Whether to scroll to a comment on load based on the URL hash. Defaults to `true`.
@@ -952,7 +952,7 @@ declare type RoomContextBundle<TPresence extends JsonObject, TStorage extends Ls
952
952
  /**
953
953
  * Properties that are the same in LiveblocksContext and LiveblocksContext["suspense"].
954
954
  */
955
- declare type LiveblocksContextBundleCommon = {
955
+ declare type LiveblocksContextBundleCommon<TThreadMetadata extends BaseMetadata> = {
956
956
  /**
957
957
  * @beta
958
958
  *
@@ -980,6 +980,15 @@ declare type LiveblocksContextBundleCommon = {
980
980
  * markAllInboxNotificationsAsRead();
981
981
  */
982
982
  useMarkAllInboxNotificationsAsRead(): () => void;
983
+ /**
984
+ * @beta
985
+ *
986
+ * Returns the thread associated with a `"thread"` inbox notification.
987
+ *
988
+ * @example
989
+ * const thread = useInboxNotificationThread("in_xxx");
990
+ */
991
+ useInboxNotificationThread(inboxNotificationId: string): ThreadData<TThreadMetadata>;
983
992
  };
984
993
  /**
985
994
  * @private
@@ -989,15 +998,6 @@ declare type LiveblocksContextBundleCommon = {
989
998
  * will probably happen if you do.
990
999
  */
991
1000
  declare type PrivateLiveblocksContextApi = {
992
- /**
993
- * @private
994
- *
995
- * Returns a thread from the cache.
996
- *
997
- * @example
998
- * const thread = useThreadFromCache("th_xxx");
999
- */
1000
- useThreadFromCache(threadId: string): ThreadData<BaseMetadata>;
1001
1001
  /**
1002
1002
  * @private
1003
1003
  *
@@ -1005,7 +1005,7 @@ declare type PrivateLiveblocksContextApi = {
1005
1005
  */
1006
1006
  useCurrentUserId(): string | null;
1007
1007
  };
1008
- declare type LiveblocksContextBundle<TUserMeta extends BaseUserMeta> = Resolve<LiveblocksContextBundleCommon & Omit<SharedContextBundle<TUserMeta>, "suspense"> & {
1008
+ declare type LiveblocksContextBundle<TUserMeta extends BaseUserMeta, TThreadMetadata extends BaseMetadata> = Resolve<LiveblocksContextBundleCommon<TThreadMetadata> & Omit<SharedContextBundle<TUserMeta>, "suspense"> & {
1009
1009
  /**
1010
1010
  * @beta
1011
1011
  *
@@ -1024,7 +1024,7 @@ declare type LiveblocksContextBundle<TUserMeta extends BaseUserMeta> = Resolve<L
1024
1024
  * const { count, error, isLoading } = useUnreadInboxNotificationsCount();
1025
1025
  */
1026
1026
  useUnreadInboxNotificationsCount(): UnreadInboxNotificationsCountState;
1027
- suspense: Resolve<LiveblocksContextBundleCommon & SharedContextBundle<TUserMeta>["suspense"] & {
1027
+ suspense: Resolve<LiveblocksContextBundleCommon<TThreadMetadata> & SharedContextBundle<TUserMeta>["suspense"] & {
1028
1028
  /**
1029
1029
  * @beta
1030
1030
  *
@@ -1060,8 +1060,8 @@ declare type LiveblocksContextBundle<TUserMeta extends BaseUserMeta> = Resolve<L
1060
1060
  *
1061
1061
  * This is an internal API, use "createLiveblocksContext" instead.
1062
1062
  */
1063
- declare function useLiveblocksContextBundle(): LiveblocksContextBundle<BaseUserMeta>;
1064
- declare function createLiveblocksContext<TUserMeta extends BaseUserMeta = BaseUserMeta, TThreadMetadata extends BaseMetadata$1 = never>(client: Client): LiveblocksContextBundle<TUserMeta>;
1063
+ declare function useLiveblocksContextBundle(): LiveblocksContextBundle<BaseUserMeta, BaseMetadata$1>;
1064
+ declare function createLiveblocksContext<TUserMeta extends BaseUserMeta = BaseUserMeta, TThreadMetadata extends BaseMetadata$1 = never>(client: Client): LiveblocksContextBundle<TUserMeta, TThreadMetadata>;
1065
1065
 
1066
1066
  /**
1067
1067
  * @private
@@ -1092,6 +1092,6 @@ declare function createRoomContext<TPresence extends JsonObject, TStorage extend
1092
1092
  *
1093
1093
  * This is an internal API, use `createLiveblocksContext` or `createRoomContext` instead.
1094
1094
  */
1095
- declare function useSharedContextBundle(): RoomContextBundle<_liveblocks_core.JsonObject, _liveblocks_core.LsonObject, BaseUserMeta$1, never, _liveblocks_core.BaseMetadata> | LiveblocksContextBundle<BaseUserMeta$1>;
1095
+ declare function useSharedContextBundle(): RoomContextBundle<_liveblocks_core.JsonObject, _liveblocks_core.LsonObject, BaseUserMeta$1, never, _liveblocks_core.BaseMetadata> | LiveblocksContextBundle<BaseUserMeta$1, _liveblocks_core.BaseMetadata>;
1096
1096
 
1097
1097
  export { ClientSideSuspense, type MutationContext, type UseThreadsOptions, createLiveblocksContext, createRoomContext, useLiveblocksContextBundle, useRoomContextBundle, useSharedContextBundle };
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ var _core = require('@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 = "cjs";
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
 
@@ -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 = _nanoid.nanoid.call(void 0, );
@@ -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 = _react.useCallback.call(void 0,
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 _withselectorjs.useSyncExternalStoreWithSelector.call(void 0,
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
  [_core.kInternal]: {
2313
- useThreadFromCache,
2314
2347
  useCurrentUserId
2315
2348
  }
2316
2349
  };