@liveblocks/react 2.16.0-toolbars4 → 2.17.0-channels1

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
  // src/version.ts
2
2
  var PKG_NAME = "@liveblocks/react";
3
- var PKG_VERSION = "2.16.0-toolbars4";
3
+ var PKG_VERSION = "2.17.0-channels1";
4
4
  var PKG_FORMAT = "esm";
5
5
 
6
6
  // src/ClientSideSuspense.tsx
@@ -20,4 +20,4 @@ export {
20
20
  PKG_FORMAT,
21
21
  ClientSideSuspense
22
22
  };
23
- //# sourceMappingURL=chunk-V52BQ2MG.mjs.map
23
+ //# sourceMappingURL=chunk-KFACA6OH.mjs.map
@@ -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.16.0-toolbars4";
3
+ var PKG_VERSION = "2.17.0-channels1";
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-GUS4QAJA.js.map
23
+ //# sourceMappingURL=chunk-RABQO63H.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/liveblocks/liveblocks/packages/liveblocks-react/dist/chunk-GUS4QAJA.js","../src/version.ts","../src/ClientSideSuspense.tsx"],"names":[],"mappings":"AAAA;ACGO,IAAM,SAAA,EAAW,mBAAA;AACjB,IAAM,YAAA,EAAiD,kBAAA;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-GUS4QAJA.js","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-RABQO63H.js","../src/version.ts","../src/ClientSideSuspense.tsx"],"names":[],"mappings":"AAAA;ACGO,IAAM,SAAA,EAAW,mBAAA;AACjB,IAAM,YAAA,EAAiD,kBAAA;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-RABQO63H.js","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"]}
@@ -130,7 +130,9 @@ var config = {
130
130
  HISTORY_VERSIONS_POLL_INTERVAL: 1 * MINUTES,
131
131
  HISTORY_VERSIONS_MAX_STALE_TIME: 5 * SECONDS,
132
132
  NOTIFICATION_SETTINGS_POLL_INTERVAL: 1 * MINUTES,
133
- NOTIFICATION_SETTINGS_MAX_STALE_TIME: 5 * SECONDS
133
+ NOTIFICATION_SETTINGS_MAX_STALE_TIME: 5 * SECONDS,
134
+ CHANNEL_NOTIFICATION_SETTINGS_INTERVAL: 5 * MINUTES,
135
+ CHANNEL_NOTIFICATION_SETTINGS_MAX_STALE_TIME: 1 * MINUTES
134
136
  };
135
137
 
136
138
  // src/lib/AsyncResult.ts
@@ -224,7 +226,9 @@ import {
224
226
  console as console2,
225
227
  DefaultMap,
226
228
  DerivedSignal,
229
+ entries,
227
230
  HttpError,
231
+ keys,
228
232
  kInternal,
229
233
  MutableSignal as MutableSignal2,
230
234
  nanoid,
@@ -716,6 +720,26 @@ function createStore_forPermissionHints() {
716
720
  update
717
721
  };
718
722
  }
723
+ function createStore_forChannelsNotificationSettings(updates) {
724
+ const signal = new Signal({});
725
+ function update(settings) {
726
+ signal.set((prevSettings) => {
727
+ return {
728
+ ...prevSettings,
729
+ ...settings
730
+ };
731
+ });
732
+ }
733
+ return {
734
+ signal: DerivedSignal.from(
735
+ signal,
736
+ updates,
737
+ (base, updates2) => applyOptimisticUpdates_forChannelNotificationSettings(base, updates2)
738
+ ),
739
+ // Mutations
740
+ update
741
+ };
742
+ }
719
743
  function createStore_forOptimistic(client) {
720
744
  const signal = new Signal([]);
721
745
  const syncSource = client[kInternal].createSyncSource();
@@ -755,9 +779,11 @@ var UmbrellaStore = class {
755
779
  // \ | | | | & notifications by ID
756
780
  // | \ | | Apply | |
757
781
  // | `-> OptimisticUpdates --+--+--> Optimistic --+-+--> Notification Settings (Part 2)
758
- // \ | Updates |
759
- // `------- etc etc ---------+ +--> History Versions (Part 3)
760
- // ^
782
+ // \ | Updates | |
783
+ // `------- etc etc ---------+ | +--> History Versions (Part 3)
784
+ // ^ |
785
+ // | +-----> Channels Notification Settings (Part 4)
786
+ // |
761
787
  // |
762
788
  // | ^ ^
763
789
  // Signal | |
@@ -778,6 +804,7 @@ var UmbrellaStore = class {
778
804
  // prettier-ignore
779
805
  historyVersions;
780
806
  permissionHints;
807
+ channelNotificationSettings;
781
808
  optimisticUpdates;
782
809
  //
783
810
  // Output signals.
@@ -798,6 +825,8 @@ var UmbrellaStore = class {
798
825
  #userThreadsLastRequestedAt = null;
799
826
  // Room versions
800
827
  #roomVersionsLastRequestedAtByRoom = /* @__PURE__ */ new Map();
828
+ // Channels Notification Settings
829
+ #channelsNotificationSettings;
801
830
  constructor(client) {
802
831
  this.#client = client[kInternal].as();
803
832
  this.optimisticUpdates = createStore_forOptimistic(this.#client);
@@ -813,6 +842,16 @@ var UmbrellaStore = class {
813
842
  return nextCursor;
814
843
  }
815
844
  );
845
+ const channelsNotificationSettingsFetcher = async () => {
846
+ const result = await this.#client.getChannelsNotificationSettings();
847
+ this.channelNotificationSettings.update(result);
848
+ };
849
+ this.channelNotificationSettings = createStore_forChannelsNotificationSettings(
850
+ this.optimisticUpdates.signal
851
+ );
852
+ this.#channelsNotificationSettings = new SinglePageResource(
853
+ channelsNotificationSettingsFetcher
854
+ );
816
855
  this.threads = new ThreadDB();
817
856
  this.notifications = createStore_forNotifications();
818
857
  this.roomNotificationSettings = createStore_forRoomNotificationSettings(
@@ -996,6 +1035,22 @@ var UmbrellaStore = class {
996
1035
  return { signal, waitUntilLoaded: resource.waitUntilLoaded };
997
1036
  }
998
1037
  );
1038
+ const channelNotificationSettings = {
1039
+ signal: DerivedSignal.from(
1040
+ () => {
1041
+ const result = this.#channelsNotificationSettings.get();
1042
+ if (result.isLoading || result.error) {
1043
+ return result;
1044
+ }
1045
+ return ASYNC_OK(
1046
+ "settings",
1047
+ nn(this.channelNotificationSettings.signal.get())
1048
+ );
1049
+ },
1050
+ shallow3
1051
+ ),
1052
+ waitUntilLoaded: this.#channelsNotificationSettings.waitUntilLoaded
1053
+ };
999
1054
  this.outputs = {
1000
1055
  threadifications,
1001
1056
  threads,
@@ -1004,7 +1059,8 @@ var UmbrellaStore = class {
1004
1059
  notifications,
1005
1060
  loadingNotifications,
1006
1061
  settingsByRoomId,
1007
- versionsByRoomId
1062
+ versionsByRoomId,
1063
+ channelNotificationSettings
1008
1064
  };
1009
1065
  autobind(this);
1010
1066
  }
@@ -1249,6 +1305,25 @@ var UmbrellaStore = class {
1249
1305
  const result = await room.getNotificationSettings({ signal });
1250
1306
  this.roomNotificationSettings.update(roomId, result);
1251
1307
  }
1308
+ /**
1309
+ * Refresh Channels Notification Settings from poller
1310
+ */
1311
+ async refreshChannelsNotificationSettings(signal) {
1312
+ const result = await this.#client.getChannelsNotificationSettings({
1313
+ signal
1314
+ });
1315
+ this.channelNotificationSettings.update(result);
1316
+ }
1317
+ /**
1318
+ * Updates channels notification settings with a new value, replacing the
1319
+ * corresponding optimistic update.
1320
+ */
1321
+ updateChannelsNotificationSettings_confirmOptimisticUpdate(settings, optimisticUpdateId) {
1322
+ batch2(() => {
1323
+ this.optimisticUpdates.remove(optimisticUpdateId);
1324
+ this.channelNotificationSettings.update(settings);
1325
+ });
1326
+ }
1252
1327
  };
1253
1328
  function applyOptimisticUpdates_forThreadifications(baseThreadsDB, notificationsLUT, optimisticUpdates) {
1254
1329
  const threadsDB = baseThreadsDB.clone();
@@ -1423,6 +1498,33 @@ function applyOptimisticUpdates_forSettings(settingsLUT, optimisticUpdates) {
1423
1498
  }
1424
1499
  return settingsByRoomId;
1425
1500
  }
1501
+ function applyOptimisticUpdates_forChannelNotificationSettings(baseChannelsNotificationSettings, optimisticUpdates) {
1502
+ const outcomingSettings = { ...baseChannelsNotificationSettings };
1503
+ for (const optimisticUpdate of optimisticUpdates) {
1504
+ switch (optimisticUpdate.type) {
1505
+ case "update-channels-notification-settings": {
1506
+ const incomingSettings = optimisticUpdate.settings;
1507
+ for (const channelKey of keys(incomingSettings)) {
1508
+ const key = channelKey;
1509
+ const channelUpdates = incomingSettings[key];
1510
+ if (channelUpdates) {
1511
+ const realChannelUpdates = Object.fromEntries(
1512
+ entries(channelUpdates).filter(
1513
+ ([_, value]) => value !== void 0
1514
+ )
1515
+ );
1516
+ outcomingSettings[key] = {
1517
+ ...outcomingSettings[key],
1518
+ ...realChannelUpdates
1519
+ };
1520
+ }
1521
+ }
1522
+ break;
1523
+ }
1524
+ }
1525
+ }
1526
+ return outcomingSettings;
1527
+ }
1426
1528
  function compareInboxNotifications(inboxNotificationA, inboxNotificationB) {
1427
1529
  if (inboxNotificationA.notifiedAt > inboxNotificationB.notifiedAt) {
1428
1530
  return 1;
@@ -1716,10 +1818,25 @@ function makeLiveblocksExtrasForClient(client) {
1716
1818
  config.USER_THREADS_POLL_INTERVAL,
1717
1819
  { maxStaleTimeMs: config.USER_THREADS_MAX_STALE_TIME }
1718
1820
  );
1821
+ const channelNotificationSettingsPoller = makePoller(
1822
+ async (signal) => {
1823
+ try {
1824
+ return await store.refreshChannelsNotificationSettings(signal);
1825
+ } catch (err) {
1826
+ console.warn(
1827
+ `Polling new channel notification settings failed: ${String(err)}`
1828
+ );
1829
+ throw err;
1830
+ }
1831
+ },
1832
+ config.CHANNEL_NOTIFICATION_SETTINGS_INTERVAL,
1833
+ { maxStaleTimeMs: config.CHANNEL_NOTIFICATION_SETTINGS_MAX_STALE_TIME }
1834
+ );
1719
1835
  return {
1720
1836
  store,
1721
1837
  notificationsPoller,
1722
- userThreadsPoller
1838
+ userThreadsPoller,
1839
+ channelNotificationSettingsPoller
1723
1840
  };
1724
1841
  }
1725
1842
  function makeLiveblocksContextBundle(client) {
@@ -1728,6 +1845,7 @@ function makeLiveblocksContextBundle(client) {
1728
1845
  const useMarkAllInboxNotificationsAsRead2 = () => useMarkAllInboxNotificationsAsRead_withClient(client);
1729
1846
  const useDeleteInboxNotification2 = () => useDeleteInboxNotification_withClient(client);
1730
1847
  const useDeleteAllInboxNotifications2 = () => useDeleteAllInboxNotifications_withClient(client);
1848
+ const useUpdateChannelsNotificationSettings2 = () => useUpdateChannelsNotificationSettings_withClient(client);
1731
1849
  function LiveblocksProvider2(props) {
1732
1850
  useEnsureNoLiveblocksProvider();
1733
1851
  return /* @__PURE__ */ jsx(ClientContext.Provider, { value: client, children: props.children });
@@ -1741,6 +1859,8 @@ function makeLiveblocksContextBundle(client) {
1741
1859
  useMarkAllInboxNotificationsAsRead: useMarkAllInboxNotificationsAsRead2,
1742
1860
  useDeleteInboxNotification: useDeleteInboxNotification2,
1743
1861
  useDeleteAllInboxNotifications: useDeleteAllInboxNotifications2,
1862
+ useChannelsNotificationSettings: () => useChannelsNotificationSettings_withClient(client),
1863
+ useUpdateChannelsNotificationSettings: useUpdateChannelsNotificationSettings2,
1744
1864
  useInboxNotificationThread: useInboxNotificationThread2,
1745
1865
  useUserThreads_experimental,
1746
1866
  ...shared.classic,
@@ -1753,6 +1873,8 @@ function makeLiveblocksContextBundle(client) {
1753
1873
  useDeleteInboxNotification: useDeleteInboxNotification2,
1754
1874
  useDeleteAllInboxNotifications: useDeleteAllInboxNotifications2,
1755
1875
  useInboxNotificationThread: useInboxNotificationThread2,
1876
+ useChannelsNotificationSettings: () => useChannelsNotificationSettingsSuspense_withClient(client),
1877
+ useUpdateChannelsNotificationSettings: useUpdateChannelsNotificationSettings2,
1756
1878
  useUserThreads_experimental: useUserThreadsSuspense_experimental,
1757
1879
  ...shared.suspense
1758
1880
  }
@@ -1915,6 +2037,57 @@ function useInboxNotificationThread_withClient(client, inboxNotificationId) {
1915
2037
  )
1916
2038
  );
1917
2039
  }
2040
+ function useUpdateChannelsNotificationSettings_withClient(client) {
2041
+ return useCallback2(
2042
+ (settings) => {
2043
+ const { store } = getLiveblocksExtrasForClient(client);
2044
+ const optimisticUpdateId = store.optimisticUpdates.add({
2045
+ type: "update-channels-notification-settings",
2046
+ settings
2047
+ });
2048
+ client.updateChannelsNotificationSettings(settings).then(
2049
+ (settings2) => {
2050
+ store.updateChannelsNotificationSettings_confirmOptimisticUpdate(
2051
+ settings2,
2052
+ optimisticUpdateId
2053
+ );
2054
+ },
2055
+ () => {
2056
+ store.optimisticUpdates.remove(optimisticUpdateId);
2057
+ }
2058
+ );
2059
+ },
2060
+ [client]
2061
+ );
2062
+ }
2063
+ function useChannelsNotificationSettings_withClient(client) {
2064
+ const updateChannelsNotificationSettings = useUpdateChannelsNotificationSettings_withClient(client);
2065
+ const { store, channelNotificationSettingsPoller: poller } = getLiveblocksExtrasForClient(client);
2066
+ useEffect3(() => {
2067
+ void store.outputs.channelNotificationSettings.waitUntilLoaded();
2068
+ });
2069
+ useEffect3(() => {
2070
+ poller.inc();
2071
+ poller.pollNowIfStale();
2072
+ return () => {
2073
+ poller.dec();
2074
+ };
2075
+ }, [poller]);
2076
+ const settings = useSignal(store.outputs.channelNotificationSettings.signal);
2077
+ return useMemo2(() => {
2078
+ return [settings, updateChannelsNotificationSettings];
2079
+ }, [settings, updateChannelsNotificationSettings]);
2080
+ }
2081
+ function useChannelsNotificationSettingsSuspense_withClient(client) {
2082
+ const store = getLiveblocksExtrasForClient(client).store;
2083
+ use(store.outputs.channelNotificationSettings.waitUntilLoaded());
2084
+ const [settings, updateChannelsNotificationSettings] = useChannelsNotificationSettings_withClient(client);
2085
+ assert(!settings.error, "Did not expect error");
2086
+ assert(!settings.isLoading, "Did not expect loading");
2087
+ return useMemo2(() => {
2088
+ return [settings, updateChannelsNotificationSettings];
2089
+ }, [settings, updateChannelsNotificationSettings]);
2090
+ }
1918
2091
  function useUser_withClient(client, userId) {
1919
2092
  const usersStore = client[kInternal2].usersStore;
1920
2093
  const getUserState = useCallback2(
@@ -2176,6 +2349,15 @@ function useUnreadInboxNotificationsCount() {
2176
2349
  function useUnreadInboxNotificationsCountSuspense() {
2177
2350
  return useUnreadInboxNotificationsCountSuspense_withClient(useClient());
2178
2351
  }
2352
+ function useChannelsNotificationSettings() {
2353
+ return useChannelsNotificationSettings_withClient(useClient());
2354
+ }
2355
+ function useChannelsNotificationSettingsSuspense() {
2356
+ return useChannelsNotificationSettingsSuspense_withClient(useClient());
2357
+ }
2358
+ function useUpdateChannelsNotificationSettings() {
2359
+ return useUpdateChannelsNotificationSettings_withClient(useClient());
2360
+ }
2179
2361
  function useUser(userId) {
2180
2362
  const client = useClient();
2181
2363
  return useUser_withClient(client, userId);
@@ -3954,6 +4136,9 @@ export {
3954
4136
  useDeleteInboxNotification,
3955
4137
  useUnreadInboxNotificationsCount,
3956
4138
  useUnreadInboxNotificationsCountSuspense,
4139
+ useChannelsNotificationSettings,
4140
+ useChannelsNotificationSettingsSuspense,
4141
+ useUpdateChannelsNotificationSettings,
3957
4142
  useRoomInfo,
3958
4143
  useRoomInfoSuspense,
3959
4144
  _useInboxNotificationThread,
@@ -4040,4 +4225,4 @@ export {
4040
4225
  _useStorageRoot,
4041
4226
  _useUpdateMyPresence
4042
4227
  };
4043
- //# sourceMappingURL=chunk-FQKGWA7O.mjs.map
4228
+ //# sourceMappingURL=chunk-VX6Y3GQO.mjs.map