@liveblocks/react 2.24.0-sub1 → 2.24.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});// src/version.ts
2
2
  var PKG_NAME = "@liveblocks/react";
3
- var PKG_VERSION = "2.24.0-sub1";
3
+ var PKG_VERSION = "2.24.0";
4
4
  var PKG_FORMAT = "cjs";
5
5
 
6
6
  // src/ClientSideSuspense.tsx
@@ -20,4 +20,4 @@ function ClientSideSuspense(props) {
20
20
 
21
21
 
22
22
  exports.PKG_NAME = PKG_NAME; exports.PKG_VERSION = PKG_VERSION; exports.PKG_FORMAT = PKG_FORMAT; exports.ClientSideSuspense = ClientSideSuspense;
23
- //# sourceMappingURL=chunk-JYG2E4EZ.cjs.map
23
+ //# sourceMappingURL=chunk-F2Y7N4WI.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/liveblocks/liveblocks/packages/liveblocks-react/dist/chunk-JYG2E4EZ.cjs","../src/version.ts","../src/ClientSideSuspense.tsx"],"names":[],"mappings":"AAAA;ACGO,IAAM,SAAA,EAAW,mBAAA;AACjB,IAAM,YAAA,EAAiD,aAAA;AACvD,IAAM,WAAA,EAAgD,KAAA;ADD7D;AACA;AEJA,8BAA8C;AAkC1C,+CAAA;AAVG,SAAS,kBAAA,CAAmB,KAAA,EAAc;AAC/C,EAAA,MAAM,CAAC,OAAA,EAAS,UAAU,EAAA,EAAI,6BAAA,KAAc,CAAA;AAE5C,EAAA,8BAAA,CAAU,EAAA,GAAM;AAGd,IAAA,UAAA,CAAW,IAAI,CAAA;AAAA,EACjB,CAAA,EAAG,CAAC,CAAC,CAAA;AAEL,EAAA,uBACE,6BAAA,eAAC,EAAA,EAAS,QAAA,EAAU,KAAA,CAAM,QAAA,EACvB,QAAA,EAAA,QAAA,EACG,OAAO,KAAA,CAAM,SAAA,IAAa,WAAA,EACxB,KAAA,CAAM,QAAA,CAAS,EAAA,EACf,KAAA,CAAM,SAAA,EACR,KAAA,CAAM,SAAA,CACZ,CAAA;AAEJ;AF5BA;AACA;AACE;AACA;AACA;AACA;AACF,iJAAC","file":"/home/runner/work/liveblocks/liveblocks/packages/liveblocks-react/dist/chunk-JYG2E4EZ.cjs","sourcesContent":[null,"declare const __VERSION__: string;\ndeclare const TSUP_FORMAT: string;\n\nexport const PKG_NAME = \"@liveblocks/react\";\nexport const PKG_VERSION = typeof __VERSION__ === \"string\" && __VERSION__;\nexport const PKG_FORMAT = typeof TSUP_FORMAT === \"string\" && TSUP_FORMAT;\n","import type { ReactNode } from \"react\";\nimport { Suspense, useEffect, useState } from \"react\";\n\ntype Props = {\n fallback: ReactNode;\n children: (() => ReactNode | undefined) | ReactNode | undefined;\n};\n\n/**\n * Almost like a normal <Suspense> component, except that for server-side\n * renders, the fallback will be used.\n *\n * The child props will have to be provided in a function, i.e. change:\n *\n * <Suspense fallback={<Loading />}>\n * <MyRealComponent a={1} />\n * </Suspense>\n *\n * To:\n *\n * <ClientSideSuspense fallback={<Loading />}>\n * <MyRealComponent a={1} />\n * </ClientSideSuspense>\n *\n */\nexport function ClientSideSuspense(props: Props) {\n const [mounted, setMounted] = useState(false);\n\n useEffect(() => {\n // Effects are never executed on the server side. The point of this is to\n // delay the flipping of this boolean until after hydration has happened.\n setMounted(true);\n }, []);\n\n return (\n <Suspense fallback={props.fallback}>\n {mounted\n ? typeof props.children === \"function\"\n ? props.children()\n : props.children\n : props.fallback}\n </Suspense>\n );\n}\n"]}
1
+ {"version":3,"sources":["/home/runner/work/liveblocks/liveblocks/packages/liveblocks-react/dist/chunk-F2Y7N4WI.cjs","../src/version.ts","../src/ClientSideSuspense.tsx"],"names":[],"mappings":"AAAA;ACGO,IAAM,SAAA,EAAW,mBAAA;AACjB,IAAM,YAAA,EAAiD,QAAA;AACvD,IAAM,WAAA,EAAgD,KAAA;ADD7D;AACA;AEJA,8BAA8C;AAkC1C,+CAAA;AAVG,SAAS,kBAAA,CAAmB,KAAA,EAAc;AAC/C,EAAA,MAAM,CAAC,OAAA,EAAS,UAAU,EAAA,EAAI,6BAAA,KAAc,CAAA;AAE5C,EAAA,8BAAA,CAAU,EAAA,GAAM;AAGd,IAAA,UAAA,CAAW,IAAI,CAAA;AAAA,EACjB,CAAA,EAAG,CAAC,CAAC,CAAA;AAEL,EAAA,uBACE,6BAAA,eAAC,EAAA,EAAS,QAAA,EAAU,KAAA,CAAM,QAAA,EACvB,QAAA,EAAA,QAAA,EACG,OAAO,KAAA,CAAM,SAAA,IAAa,WAAA,EACxB,KAAA,CAAM,QAAA,CAAS,EAAA,EACf,KAAA,CAAM,SAAA,EACR,KAAA,CAAM,SAAA,CACZ,CAAA;AAEJ;AF5BA;AACA;AACE;AACA;AACA;AACA;AACF,iJAAC","file":"/home/runner/work/liveblocks/liveblocks/packages/liveblocks-react/dist/chunk-F2Y7N4WI.cjs","sourcesContent":[null,"declare const __VERSION__: string;\ndeclare const TSUP_FORMAT: string;\n\nexport const PKG_NAME = \"@liveblocks/react\";\nexport const PKG_VERSION = typeof __VERSION__ === \"string\" && __VERSION__;\nexport const PKG_FORMAT = typeof TSUP_FORMAT === \"string\" && TSUP_FORMAT;\n","import type { ReactNode } from \"react\";\nimport { Suspense, useEffect, useState } from \"react\";\n\ntype Props = {\n fallback: ReactNode;\n children: (() => ReactNode | undefined) | ReactNode | undefined;\n};\n\n/**\n * Almost like a normal <Suspense> component, except that for server-side\n * renders, the fallback will be used.\n *\n * The child props will have to be provided in a function, i.e. change:\n *\n * <Suspense fallback={<Loading />}>\n * <MyRealComponent a={1} />\n * </Suspense>\n *\n * To:\n *\n * <ClientSideSuspense fallback={<Loading />}>\n * <MyRealComponent a={1} />\n * </ClientSideSuspense>\n *\n */\nexport function ClientSideSuspense(props: Props) {\n const [mounted, setMounted] = useState(false);\n\n useEffect(() => {\n // Effects are never executed on the server side. The point of this is to\n // delay the flipping of this boolean until after hydration has happened.\n setMounted(true);\n }, []);\n\n return (\n <Suspense fallback={props.fallback}>\n {mounted\n ? typeof props.children === \"function\"\n ? props.children()\n : props.children\n : props.fallback}\n </Suspense>\n );\n}\n"]}
@@ -107,7 +107,7 @@ import {
107
107
  kInternal as kInternal2,
108
108
  makePoller,
109
109
  raise,
110
- shallow as shallow4
110
+ shallow as shallow3
111
111
  } from "@liveblocks/core";
112
112
  import {
113
113
  createContext as createContext2,
@@ -247,7 +247,8 @@ import {
247
247
  nanoid,
248
248
  nn,
249
249
  patchNotificationSettings,
250
- shallow as shallow3,
250
+ shallow,
251
+ shallow2,
251
252
  Signal,
252
253
  stableStringify
253
254
  } from "@liveblocks/core";
@@ -269,21 +270,6 @@ function autobind(self) {
269
270
  } while ((obj = Reflect.getPrototypeOf(obj)) && obj !== Object.prototype);
270
271
  }
271
272
 
272
- // src/lib/shallow2.ts
273
- import { isPlainObject, shallow } from "@liveblocks/core";
274
- function shallow2(a, b) {
275
- if (!isPlainObject(a) || !isPlainObject(b)) {
276
- return shallow(a, b);
277
- }
278
- const keysA = Object.keys(a);
279
- if (keysA.length !== Object.keys(b).length) {
280
- return false;
281
- }
282
- return keysA.every(
283
- (key) => Object.prototype.hasOwnProperty.call(b, key) && shallow(a[key], b[key])
284
- );
285
- }
286
-
287
273
  // src/ThreadDB.ts
288
274
  import { batch, MutableSignal, SortedList } from "@liveblocks/core";
289
275
 
@@ -932,7 +918,7 @@ var UmbrellaStore = class {
932
918
  sortedNotifications: s.sortedNotifications,
933
919
  notificationsById: s.notificationsById
934
920
  }),
935
- shallow3
921
+ shallow
936
922
  );
937
923
  const threadSubscriptions = DerivedSignal.from(
938
924
  notifications,
@@ -1067,7 +1053,7 @@ var UmbrellaStore = class {
1067
1053
  nn(this.roomSubscriptionSettings.signal.get()[roomId])
1068
1054
  );
1069
1055
  }
1070
- }, shallow3);
1056
+ }, shallow);
1071
1057
  return { signal, waitUntilLoaded: resource.waitUntilLoaded };
1072
1058
  }
1073
1059
  );
@@ -1098,7 +1084,7 @@ var UmbrellaStore = class {
1098
1084
  Object.values(this.historyVersions.signal.get()[roomId] ?? {})
1099
1085
  );
1100
1086
  }
1101
- }, shallow3);
1087
+ }, shallow);
1102
1088
  return { signal, waitUntilLoaded: resource.waitUntilLoaded };
1103
1089
  }
1104
1090
  );
@@ -1112,7 +1098,7 @@ var UmbrellaStore = class {
1112
1098
  "settings",
1113
1099
  nn(this.notificationSettings.signal.get())
1114
1100
  );
1115
- }, shallow3),
1101
+ }, shallow),
1116
1102
  waitUntilLoaded: this.#notificationSettings.waitUntilLoaded
1117
1103
  };
1118
1104
  this.outputs = {
@@ -1168,7 +1154,7 @@ var UmbrellaStore = class {
1168
1154
  });
1169
1155
  }
1170
1156
  /**
1171
- * Creates a existing subscription, replacing the corresponding
1157
+ * Creates an existing subscription, replacing the corresponding
1172
1158
  * optimistic update.
1173
1159
  */
1174
1160
  createSubscription(subscription, optimisticId) {
@@ -1593,47 +1579,45 @@ function applyOptimisticUpdates_forRoomSubscriptionSettings(settingsLUT, optimis
1593
1579
  function applyOptimisticUpdates_forSubscriptions(subscriptionsLUT, threads, optimisticUpdates) {
1594
1580
  const subscriptions = Object.fromEntries(subscriptionsLUT);
1595
1581
  for (const update of optimisticUpdates) {
1596
- if (update.type === "update-room-subscription-settings") {
1597
- if (update.settings.threads) {
1582
+ switch (update.type) {
1583
+ case "update-room-subscription-settings": {
1584
+ if (!update.settings.threads) {
1585
+ continue;
1586
+ }
1598
1587
  const roomThreads = threads.findMany(update.roomId, void 0, "desc");
1599
1588
  for (const thread of roomThreads) {
1600
1589
  const subscriptionKey = getSubscriptionKey("thread", thread.id);
1601
- if (update.settings.threads === "all") {
1602
- subscriptions[subscriptionKey] = {
1603
- kind: "thread",
1604
- subjectId: thread.id,
1605
- createdAt: /* @__PURE__ */ new Date()
1606
- };
1607
- } else if (update.settings.threads === "none") {
1608
- delete subscriptions[subscriptionKey];
1609
- } else if (update.settings.threads === "replies_and_mentions") {
1610
- let isParticipant = false;
1611
- for (const comment of thread.comments) {
1612
- if (comment.deletedAt) {
1613
- continue;
1614
- }
1615
- if (comment.userId === update.userId) {
1616
- isParticipant = true;
1617
- break;
1618
- }
1619
- const mentionedIds = getMentionedIdsFromCommentBody(comment.body);
1620
- if (mentionedIds.includes(update.userId)) {
1621
- isParticipant = true;
1622
- break;
1623
- }
1624
- }
1625
- if (isParticipant && !subscriptions[subscriptionKey]) {
1590
+ switch (update.settings.threads) {
1591
+ // Create subscriptions for all existing threads in the room
1592
+ case "all": {
1626
1593
  subscriptions[subscriptionKey] = {
1627
1594
  kind: "thread",
1628
1595
  subjectId: thread.id,
1629
1596
  createdAt: /* @__PURE__ */ new Date()
1630
1597
  };
1598
+ break;
1631
1599
  }
1632
- } else {
1633
- assertNever(
1634
- update.settings.threads,
1635
- "Unexpected room subscription settings."
1636
- );
1600
+ // Delete subscriptions for all existing threads in the room
1601
+ case "none": {
1602
+ delete subscriptions[subscriptionKey];
1603
+ break;
1604
+ }
1605
+ // Create subscriptions for every threads in the room which the user participates in but doesn't have a subscription for yet
1606
+ case "replies_and_mentions": {
1607
+ if (isThreadParticipant(thread, update.userId) && !subscriptions[subscriptionKey]) {
1608
+ subscriptions[subscriptionKey] = {
1609
+ kind: "thread",
1610
+ subjectId: thread.id,
1611
+ createdAt: /* @__PURE__ */ new Date()
1612
+ };
1613
+ }
1614
+ break;
1615
+ }
1616
+ default:
1617
+ assertNever(
1618
+ update.settings.threads,
1619
+ "Unexpected thread subscription settings."
1620
+ );
1637
1621
  }
1638
1622
  }
1639
1623
  }
@@ -1827,6 +1811,24 @@ function upsertReaction(reactions, reaction) {
1827
1811
  }
1828
1812
  return reactions;
1829
1813
  }
1814
+ function isThreadParticipant(thread, userId) {
1815
+ let isParticipant = false;
1816
+ for (const comment of thread.comments) {
1817
+ if (comment.deletedAt) {
1818
+ continue;
1819
+ }
1820
+ if (comment.userId === userId) {
1821
+ isParticipant = true;
1822
+ break;
1823
+ }
1824
+ const mentionedIds = getMentionedIdsFromCommentBody(comment.body);
1825
+ if (mentionedIds.includes(userId)) {
1826
+ isParticipant = true;
1827
+ break;
1828
+ }
1829
+ }
1830
+ return isParticipant;
1831
+ }
1830
1832
 
1831
1833
  // src/liveblocks.tsx
1832
1834
  import { jsx } from "react/jsx-runtime";
@@ -1978,7 +1980,7 @@ function makeLiveblocksContextBundle(client) {
1978
1980
  const shared = createSharedContext(client);
1979
1981
  const bundle = {
1980
1982
  LiveblocksProvider: LiveblocksProvider2,
1981
- useInboxNotifications: () => useInboxNotifications_withClient(client, identity2, shallow4),
1983
+ useInboxNotifications: () => useInboxNotifications_withClient(client, identity2, shallow3),
1982
1984
  useUnreadInboxNotificationsCount: () => useUnreadInboxNotificationsCount_withClient(client),
1983
1985
  useMarkInboxNotificationAsRead: useMarkInboxNotificationAsRead2,
1984
1986
  useMarkAllInboxNotificationsAsRead: useMarkAllInboxNotificationsAsRead2,
@@ -2036,7 +2038,7 @@ function useInboxNotificationsSuspense_withClient(client) {
2036
2038
  ensureNotServerSide();
2037
2039
  const store = getLiveblocksExtrasForClient(client).store;
2038
2040
  use(store.outputs.loadingNotifications.waitUntilLoaded());
2039
- const result = useInboxNotifications_withClient(client, identity2, shallow4);
2041
+ const result = useInboxNotifications_withClient(client, identity2, shallow3);
2040
2042
  assert(!result.error, "Did not expect error");
2041
2043
  assert(!result.isLoading, "Did not expect loading");
2042
2044
  return result;
@@ -2045,7 +2047,7 @@ function useUnreadInboxNotificationsCount_withClient(client) {
2045
2047
  return useInboxNotifications_withClient(
2046
2048
  client,
2047
2049
  selectorFor_useUnreadInboxNotificationsCount,
2048
- shallow4
2050
+ shallow3
2049
2051
  );
2050
2052
  }
2051
2053
  function useUnreadInboxNotificationsCountSuspense_withClient(client) {
@@ -2265,7 +2267,7 @@ function useUser_withClient(client, userId) {
2265
2267
  getUserState,
2266
2268
  getUserState,
2267
2269
  selector,
2268
- shallow4
2270
+ shallow3
2269
2271
  );
2270
2272
  useEffect3(
2271
2273
  () => void usersStore.enqueue(userId)
@@ -2326,7 +2328,7 @@ function useRoomInfo_withClient(client, roomId) {
2326
2328
  getRoomInfoState,
2327
2329
  getRoomInfoState,
2328
2330
  selector,
2329
- shallow4
2331
+ shallow3
2330
2332
  );
2331
2333
  useEffect3(
2332
2334
  () => void roomsInfoStore.enqueue(roomId)
@@ -2486,7 +2488,7 @@ function useUserThreadsSuspense_experimental(options = {}) {
2486
2488
  return result;
2487
2489
  }
2488
2490
  function useInboxNotifications() {
2489
- return useInboxNotifications_withClient(useClient(), identity2, shallow4);
2491
+ return useInboxNotifications_withClient(useClient(), identity2, shallow3);
2490
2492
  }
2491
2493
  function useInboxNotificationsSuspense() {
2492
2494
  return useInboxNotificationsSuspense_withClient(useClient());
@@ -2593,7 +2595,7 @@ function useErrorListener(callback) {
2593
2595
  }
2594
2596
 
2595
2597
  // src/room.tsx
2596
- import { shallow as shallow5 } from "@liveblocks/client";
2598
+ import { shallow as shallow4 } from "@liveblocks/client";
2597
2599
  import {
2598
2600
  assert as assert2,
2599
2601
  console as console3,
@@ -3255,7 +3257,7 @@ function useOthersMapped(itemSelector, itemIsEqual) {
3255
3257
  return useOthers(wrappedSelector, wrappedIsEqual);
3256
3258
  }
3257
3259
  function useOthersConnectionIds() {
3258
- return useOthers(selectorFor_useOthersConnectionIds, shallow5);
3260
+ return useOthers(selectorFor_useOthersConnectionIds, shallow4);
3259
3261
  }
3260
3262
  var NOT_FOUND = Symbol();
3261
3263
  function useOther(connectionId, selector, isEqual) {
@@ -3945,7 +3947,7 @@ function useRoomThreadSubscription(roomId, threadId) {
3945
3947
  },
3946
3948
  [subscriptionKey, threadId, subscribe, unsubscribe]
3947
3949
  );
3948
- return useSignal(signal, selector, shallow5);
3950
+ return useSignal(signal, selector, shallow4);
3949
3951
  }
3950
3952
  function useRoomNotificationSettings() {
3951
3953
  const updateRoomNotificationSettings = useUpdateRoomNotificationSettings();
@@ -4264,7 +4266,7 @@ function useRoomAttachmentUrl(attachmentId, roomId) {
4264
4266
  getAttachmentUrlState,
4265
4267
  getAttachmentUrlState,
4266
4268
  selectorFor_useAttachmentUrl,
4267
- shallow5
4269
+ shallow4
4268
4270
  );
4269
4271
  }
4270
4272
  function useAttachmentUrlSuspense(attachmentId) {
@@ -4459,4 +4461,4 @@ export {
4459
4461
  _useStorageRoot,
4460
4462
  _useUpdateMyPresence
4461
4463
  };
4462
- //# sourceMappingURL=chunk-ZWYRZR44.js.map
4464
+ //# sourceMappingURL=chunk-N6OQQVYV.js.map