@liveblocks/react 3.8.0-next4 → 3.8.0-tiptap1

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.
@@ -172,7 +172,6 @@ import {
172
172
  assert,
173
173
  console as console2,
174
174
  createClient,
175
- DefaultMap as DefaultMap2,
176
175
  HttpError,
177
176
  kInternal as kInternal3,
178
177
  makePoller,
@@ -217,6 +216,21 @@ function ASYNC_OK(fieldOrData, data) {
217
216
  }
218
217
  }
219
218
 
219
+ // src/lib/itertools.ts
220
+ function find(it, predicate) {
221
+ for (const item of it) {
222
+ if (predicate(item)) return item;
223
+ }
224
+ return void 0;
225
+ }
226
+ function count(it, predicate) {
227
+ let total = 0;
228
+ for (const item of it) {
229
+ if (predicate(item)) total++;
230
+ }
231
+ return total;
232
+ }
233
+
220
234
  // src/lib/ssr.ts
221
235
  function ensureNotServerSide() {
222
236
  if (typeof window === "undefined") {
@@ -310,14 +324,6 @@ function autobind(self) {
310
324
  } while ((obj = Reflect.getPrototypeOf(obj)) && obj !== Object.prototype);
311
325
  }
312
326
 
313
- // src/lib/itertools.ts
314
- function find(it, predicate) {
315
- for (const item of it) {
316
- if (predicate(item)) return item;
317
- }
318
- return void 0;
319
- }
320
-
321
327
  // src/lib/querying.ts
322
328
  import { isStartsWithOperator } from "@liveblocks/core";
323
329
  function makeThreadsFilter(query) {
@@ -716,21 +722,6 @@ function createStore_forNotifications() {
716
722
  upsert
717
723
  };
718
724
  }
719
- function createStore_forUnreadNotificationsCount() {
720
- const baseSignal = new MutableSignal3(
721
- /* @__PURE__ */ new Map()
722
- );
723
- function update(queryKey, count) {
724
- baseSignal.mutate((lut) => {
725
- lut.set(queryKey, count);
726
- });
727
- }
728
- return {
729
- signal: DerivedSignal.from(baseSignal, (c) => Object.fromEntries(c)),
730
- // Mutations
731
- update
732
- };
733
- }
734
725
  function createStore_forSubscriptions(updates, threads) {
735
726
  const baseSignal = new MutableSignal3(/* @__PURE__ */ new Map());
736
727
  function applyDelta(newSubscriptions, deletedSubscriptions) {
@@ -920,7 +911,6 @@ var UmbrellaStore = class {
920
911
  roomSubscriptionSettings;
921
912
  // prettier-ignore
922
913
  historyVersions;
923
- unreadNotificationsCount;
924
914
  permissionHints;
925
915
  notificationSettings;
926
916
  optimisticUpdates;
@@ -968,7 +958,6 @@ var UmbrellaStore = class {
968
958
  this.optimisticUpdates.signal
969
959
  );
970
960
  this.historyVersions = createStore_forHistoryVersions();
971
- this.unreadNotificationsCount = createStore_forUnreadNotificationsCount();
972
961
  const threadifications = DerivedSignal.from(
973
962
  this.threads.signal,
974
963
  this.notifications.signal,
@@ -1125,35 +1114,6 @@ var UmbrellaStore = class {
1125
1114
  };
1126
1115
  }
1127
1116
  );
1128
- const unreadNotificationsCount = new DefaultMap(
1129
- (queryKey) => {
1130
- const query = JSON.parse(queryKey);
1131
- const resource = new SinglePageResource(async () => {
1132
- const result = await this.#client.getUnreadInboxNotificationsCount({
1133
- query
1134
- });
1135
- this.unreadNotificationsCount.update(queryKey, result);
1136
- });
1137
- const signal = DerivedSignal.from(
1138
- () => {
1139
- const result = resource.get();
1140
- if (result.isLoading || result.error) {
1141
- return result;
1142
- } else {
1143
- return ASYNC_OK(
1144
- "count",
1145
- nn(this.unreadNotificationsCount.signal.get()[queryKey])
1146
- );
1147
- }
1148
- },
1149
- shallow
1150
- );
1151
- return {
1152
- signal,
1153
- waitUntilLoaded: resource.waitUntilLoaded
1154
- };
1155
- }
1156
- );
1157
1117
  const roomSubscriptionSettingsByRoomId = new DefaultMap(
1158
1118
  (roomId) => {
1159
1119
  const resource = new SinglePageResource(async () => {
@@ -1302,7 +1262,6 @@ var UmbrellaStore = class {
1302
1262
  loadingUserThreads,
1303
1263
  notifications,
1304
1264
  loadingNotifications,
1305
- unreadNotificationsCount,
1306
1265
  roomSubscriptionSettingsByRoomId,
1307
1266
  versionsByRoomId,
1308
1267
  notificationSettings,
@@ -1510,14 +1469,6 @@ var UmbrellaStore = class {
1510
1469
  result.subscriptions.deleted
1511
1470
  );
1512
1471
  }
1513
- async fetchUnreadNotificationsCount(queryKey, signal) {
1514
- const query = JSON.parse(queryKey);
1515
- const result = await this.#client.getUnreadInboxNotificationsCount({
1516
- query,
1517
- signal
1518
- });
1519
- this.unreadNotificationsCount.update(queryKey, result);
1520
- }
1521
1472
  async fetchRoomThreadsDeltaUpdate(roomId, signal) {
1522
1473
  const lastRequestedAt = this.#roomThreadsLastRequestedAtByRoom.get(roomId);
1523
1474
  if (lastRequestedAt === void 0) {
@@ -2032,10 +1983,16 @@ var _umbrellaStores = /* @__PURE__ */ new WeakMap();
2032
1983
  var _extras = /* @__PURE__ */ new WeakMap();
2033
1984
  var _bundles = /* @__PURE__ */ new WeakMap();
2034
1985
  function selectorFor_useUnreadInboxNotificationsCount(result) {
2035
- if (!("count" in result) || result.count === void 0) {
1986
+ if (!result.inboxNotifications) {
2036
1987
  return result;
2037
1988
  }
2038
- return ASYNC_OK("count", result.count);
1989
+ return ASYNC_OK(
1990
+ "count",
1991
+ count(
1992
+ result.inboxNotifications,
1993
+ (n) => n.readAt === null || n.readAt < n.notifiedAt
1994
+ )
1995
+ );
2039
1996
  }
2040
1997
  function selectorFor_useUser(state, userId) {
2041
1998
  if (state === void 0 || state?.isLoading) {
@@ -2134,22 +2091,6 @@ function makeLiveblocksExtrasForClient(client) {
2134
2091
  config.NOTIFICATIONS_POLL_INTERVAL,
2135
2092
  { maxStaleTimeMs: config.NOTIFICATIONS_MAX_STALE_TIME }
2136
2093
  );
2137
- const unreadNotificationsCountPollersByQueryKey = new DefaultMap2(
2138
- (queryKey) => makePoller(
2139
- async (signal) => {
2140
- try {
2141
- return await store.fetchUnreadNotificationsCount(queryKey, signal);
2142
- } catch (err) {
2143
- console2.warn(
2144
- `Polling unread inbox notifications countfailed: ${String(err)}`
2145
- );
2146
- throw err;
2147
- }
2148
- },
2149
- config.NOTIFICATIONS_POLL_INTERVAL,
2150
- { maxStaleTimeMs: config.NOTIFICATIONS_MAX_STALE_TIME }
2151
- )
2152
- );
2153
2094
  const userThreadsPoller = makePoller(
2154
2095
  async (signal) => {
2155
2096
  try {
@@ -2180,8 +2121,7 @@ function makeLiveblocksExtrasForClient(client) {
2180
2121
  store,
2181
2122
  notificationsPoller,
2182
2123
  userThreadsPoller,
2183
- notificationSettingsPoller,
2184
- unreadNotificationsCountPollersByQueryKey
2124
+ notificationSettingsPoller
2185
2125
  };
2186
2126
  }
2187
2127
  function makeLiveblocksContextBundle(client) {
@@ -2211,7 +2151,6 @@ function makeLiveblocksContextBundle(client) {
2211
2151
  useAiChats,
2212
2152
  useAiChat,
2213
2153
  useAiChatMessages,
2214
- useAiChatStatus,
2215
2154
  useCreateAiChat,
2216
2155
  useDeleteAiChat,
2217
2156
  useSendAiMessage,
@@ -2231,7 +2170,6 @@ function makeLiveblocksContextBundle(client) {
2231
2170
  useAiChats: useAiChatsSuspense,
2232
2171
  useAiChat: useAiChatSuspense,
2233
2172
  useAiChatMessages: useAiChatMessagesSuspense,
2234
- useAiChatStatus,
2235
2173
  useCreateAiChat,
2236
2174
  useDeleteAiChat,
2237
2175
  useSendAiMessage,
@@ -2285,31 +2223,11 @@ function useInboxNotificationsSuspense_withClient(client, options) {
2285
2223
  return result;
2286
2224
  }
2287
2225
  function useUnreadInboxNotificationsCount_withClient(client, options) {
2288
- const { store, unreadNotificationsCountPollersByQueryKey: pollers } = getLiveblocksExtrasForClient(client);
2289
- const queryKey = makeInboxNotificationsQueryKey(options?.query);
2290
- const poller = pollers.getOrCreate(queryKey);
2291
- useEffect4(
2292
- () => void store.outputs.unreadNotificationsCount.getOrCreate(queryKey).waitUntilLoaded()
2293
- // NOTE: Deliberately *not* using a dependency array here!
2294
- //
2295
- // It is important to call waitUntil on *every* render.
2296
- // This is harmless though, on most renders, except:
2297
- // 1. The very first render, in which case we'll want to trigger the initial page fetch.
2298
- // 2. All other subsequent renders now "just" return the same promise (a quick operation).
2299
- // 3. If ever the promise would fail, then after 5 seconds it would reset, and on the very
2300
- // *next* render after that, a *new* fetch/promise will get created.
2301
- );
2302
- useEffect4(() => {
2303
- poller.inc();
2304
- poller.pollNowIfStale();
2305
- return () => {
2306
- poller.dec();
2307
- };
2308
- }, [poller]);
2309
- return useSignal(
2310
- store.outputs.unreadNotificationsCount.getOrCreate(queryKey).signal,
2226
+ return useInboxNotifications_withClient(
2227
+ client,
2311
2228
  selectorFor_useUnreadInboxNotificationsCount,
2312
- shallow3
2229
+ shallow3,
2230
+ options
2313
2231
  );
2314
2232
  }
2315
2233
  function useUnreadInboxNotificationsCountSuspense_withClient(client, options) {
@@ -2317,7 +2235,7 @@ function useUnreadInboxNotificationsCountSuspense_withClient(client, options) {
2317
2235
  const store = getLiveblocksExtrasForClient(client).store;
2318
2236
  const queryKey = makeInboxNotificationsQueryKey(options?.query);
2319
2237
  use(
2320
- store.outputs.unreadNotificationsCount.getOrCreate(queryKey).waitUntilLoaded()
2238
+ store.outputs.loadingNotifications.getOrCreate(queryKey).waitUntilLoaded()
2321
2239
  );
2322
2240
  const result = useUnreadInboxNotificationsCount_withClient(client, options);
2323
2241
  assert(!result.isLoading, "Did not expect loading");
@@ -2327,7 +2245,7 @@ function useUnreadInboxNotificationsCountSuspense_withClient(client, options) {
2327
2245
  function useMarkInboxNotificationAsRead_withClient(client) {
2328
2246
  return useCallback2(
2329
2247
  (inboxNotificationId) => {
2330
- const { store, unreadNotificationsCountPollersByQueryKey } = getLiveblocksExtrasForClient(client);
2248
+ const { store } = getLiveblocksExtrasForClient(client);
2331
2249
  const readAt = /* @__PURE__ */ new Date();
2332
2250
  const optimisticId = store.optimisticUpdates.add({
2333
2251
  type: "mark-inbox-notification-as-read",
@@ -2341,10 +2259,6 @@ function useMarkInboxNotificationAsRead_withClient(client) {
2341
2259
  readAt,
2342
2260
  optimisticId
2343
2261
  );
2344
- for (const poller of unreadNotificationsCountPollersByQueryKey.values()) {
2345
- poller.markAsStale();
2346
- poller.pollNowIfStale();
2347
- }
2348
2262
  },
2349
2263
  (err) => {
2350
2264
  store.optimisticUpdates.remove(optimisticId);
@@ -2363,7 +2277,7 @@ function useMarkInboxNotificationAsRead_withClient(client) {
2363
2277
  }
2364
2278
  function useMarkAllInboxNotificationsAsRead_withClient(client) {
2365
2279
  return useCallback2(() => {
2366
- const { store, unreadNotificationsCountPollersByQueryKey } = getLiveblocksExtrasForClient(client);
2280
+ const { store } = getLiveblocksExtrasForClient(client);
2367
2281
  const readAt = /* @__PURE__ */ new Date();
2368
2282
  const optimisticId = store.optimisticUpdates.add({
2369
2283
  type: "mark-all-inbox-notifications-as-read",
@@ -2372,10 +2286,6 @@ function useMarkAllInboxNotificationsAsRead_withClient(client) {
2372
2286
  client.markAllInboxNotificationsAsRead().then(
2373
2287
  () => {
2374
2288
  store.markAllInboxNotificationsRead(optimisticId, readAt);
2375
- for (const poller of unreadNotificationsCountPollersByQueryKey.values()) {
2376
- poller.markAsStale();
2377
- poller.pollNowIfStale();
2378
- }
2379
2289
  },
2380
2290
  (err) => {
2381
2291
  store.optimisticUpdates.remove(optimisticId);
@@ -2391,7 +2301,7 @@ function useMarkAllInboxNotificationsAsRead_withClient(client) {
2391
2301
  function useDeleteInboxNotification_withClient(client) {
2392
2302
  return useCallback2(
2393
2303
  (inboxNotificationId) => {
2394
- const { store, unreadNotificationsCountPollersByQueryKey } = getLiveblocksExtrasForClient(client);
2304
+ const { store } = getLiveblocksExtrasForClient(client);
2395
2305
  const deletedAt = /* @__PURE__ */ new Date();
2396
2306
  const optimisticId = store.optimisticUpdates.add({
2397
2307
  type: "delete-inbox-notification",
@@ -2401,10 +2311,6 @@ function useDeleteInboxNotification_withClient(client) {
2401
2311
  client.deleteInboxNotification(inboxNotificationId).then(
2402
2312
  () => {
2403
2313
  store.deleteInboxNotification(inboxNotificationId, optimisticId);
2404
- for (const poller of unreadNotificationsCountPollersByQueryKey.values()) {
2405
- poller.markAsStale();
2406
- poller.pollNowIfStale();
2407
- }
2408
2314
  },
2409
2315
  (err) => {
2410
2316
  store.optimisticUpdates.remove(optimisticId);
@@ -2420,7 +2326,7 @@ function useDeleteInboxNotification_withClient(client) {
2420
2326
  }
2421
2327
  function useDeleteAllInboxNotifications_withClient(client) {
2422
2328
  return useCallback2(() => {
2423
- const { store, unreadNotificationsCountPollersByQueryKey } = getLiveblocksExtrasForClient(client);
2329
+ const { store } = getLiveblocksExtrasForClient(client);
2424
2330
  const deletedAt = /* @__PURE__ */ new Date();
2425
2331
  const optimisticId = store.optimisticUpdates.add({
2426
2332
  type: "delete-all-inbox-notifications",
@@ -2429,10 +2335,6 @@ function useDeleteAllInboxNotifications_withClient(client) {
2429
2335
  client.deleteAllInboxNotifications().then(
2430
2336
  () => {
2431
2337
  store.deleteAllInboxNotifications(optimisticId);
2432
- for (const poller of unreadNotificationsCountPollersByQueryKey.values()) {
2433
- poller.markAsStale();
2434
- poller.pollNowIfStale();
2435
- }
2436
2338
  },
2437
2339
  (err) => {
2438
2340
  store.optimisticUpdates.remove(optimisticId);
@@ -2844,43 +2746,6 @@ function useDeleteAiChat() {
2844
2746
  [client]
2845
2747
  );
2846
2748
  }
2847
- var LOADING = Object.freeze({ status: "loading" });
2848
- var IDLE = Object.freeze({ status: "idle" });
2849
- function useAiChatStatus(chatId, branchId) {
2850
- const client = useClient();
2851
- const store = getUmbrellaStoreForClient(client);
2852
- useEnsureAiConnection(client);
2853
- useEffect4(
2854
- () => void store.outputs.messagesByChatId.getOrCreate(chatId).getOrCreate(branchId ?? null).waitUntilLoaded()
2855
- );
2856
- return useSignal(
2857
- // Signal
2858
- store.outputs.messagesByChatId.getOrCreate(chatId).getOrCreate(branchId ?? null).signal,
2859
- // Selector
2860
- (result) => {
2861
- if (result.isLoading) return LOADING;
2862
- if (result.error) return IDLE;
2863
- const messages = result.messages;
2864
- const lastMessage = messages[messages.length - 1];
2865
- if (lastMessage?.role !== "assistant") return IDLE;
2866
- if (lastMessage.status !== "generating" && lastMessage.status !== "awaiting-tool")
2867
- return IDLE;
2868
- const contentSoFar = lastMessage.contentSoFar;
2869
- const lastPart = contentSoFar[contentSoFar.length - 1];
2870
- if (lastPart?.type === "tool-invocation") {
2871
- return {
2872
- status: "generating",
2873
- partType: "tool-invocation",
2874
- toolName: lastPart.name
2875
- };
2876
- } else {
2877
- return { status: "generating", partType: lastPart?.type };
2878
- }
2879
- },
2880
- // Consider { status: "generating", partType: "text" } and { status: "generating", partType: "text" } equal
2881
- shallow3
2882
- );
2883
- }
2884
2749
  function useSendAiMessage(chatId, options) {
2885
2750
  const client = useClient();
2886
2751
  return useCallback2(
@@ -3199,7 +3064,7 @@ import {
3199
3064
  console as console3,
3200
3065
  createCommentId,
3201
3066
  createThreadId,
3202
- DefaultMap as DefaultMap3,
3067
+ DefaultMap as DefaultMap2,
3203
3068
  errorIf,
3204
3069
  getSubscriptionKey as getSubscriptionKey2,
3205
3070
  HttpError as HttpError2,
@@ -3333,7 +3198,7 @@ function makeRoomExtrasForClient(client) {
3333
3198
  throw innerError;
3334
3199
  }
3335
3200
  }
3336
- const threadsPollersByRoomId = new DefaultMap3(
3201
+ const threadsPollersByRoomId = new DefaultMap2(
3337
3202
  (roomId) => makePoller2(
3338
3203
  async (signal) => {
3339
3204
  try {
@@ -3347,7 +3212,7 @@ function makeRoomExtrasForClient(client) {
3347
3212
  { maxStaleTimeMs: config.ROOM_THREADS_MAX_STALE_TIME }
3348
3213
  )
3349
3214
  );
3350
- const versionsPollersByRoomId = new DefaultMap3(
3215
+ const versionsPollersByRoomId = new DefaultMap2(
3351
3216
  (roomId) => makePoller2(
3352
3217
  async (signal) => {
3353
3218
  try {
@@ -3361,7 +3226,7 @@ function makeRoomExtrasForClient(client) {
3361
3226
  { maxStaleTimeMs: config.HISTORY_VERSIONS_MAX_STALE_TIME }
3362
3227
  )
3363
3228
  );
3364
- const roomSubscriptionSettingsPollersByRoomId = new DefaultMap3(
3229
+ const roomSubscriptionSettingsPollersByRoomId = new DefaultMap2(
3365
3230
  (roomId) => makePoller2(
3366
3231
  async (signal) => {
3367
3232
  try {
@@ -4827,7 +4692,6 @@ export {
4827
4692
  getUmbrellaStoreForClient,
4828
4693
  useCreateAiChat,
4829
4694
  useDeleteAiChat,
4830
- useAiChatStatus,
4831
4695
  useSendAiMessage,
4832
4696
  LiveblocksProvider,
4833
4697
  createLiveblocksContext,
@@ -4934,4 +4798,4 @@ export {
4934
4798
  _useStorageRoot,
4935
4799
  _useUpdateMyPresence
4936
4800
  };
4937
- //# sourceMappingURL=chunk-DL5PAL6E.js.map
4801
+ //# sourceMappingURL=chunk-OKYUUXNY.js.map