@liveblocks/react 2.17.0-rc1 → 2.17.0-usrnotsettings2

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.17.0-rc1";
3
+ var PKG_VERSION = "2.17.0-usrnotsettings2";
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-XWYTEJGO.mjs.map
23
+ //# sourceMappingURL=chunk-D5P6PENM.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.17.0-rc1";
3
+ var PKG_VERSION = "2.17.0-usrnotsettings2";
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-DR4OUZTF.js.map
23
+ //# sourceMappingURL=chunk-QJATV7TB.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/liveblocks/liveblocks/packages/liveblocks-react/dist/chunk-QJATV7TB.js","../src/version.ts","../src/ClientSideSuspense.tsx"],"names":[],"mappings":"AAAA;ACGO,IAAM,SAAA,EAAW,mBAAA;AACjB,IAAM,YAAA,EAAiD,wBAAA;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-QJATV7TB.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
+ USER_NOTIFICATION_SETTINGS_INTERVAL: 5 * MINUTES,
135
+ USER_NOTIFICATION_SETTINGS_MAX_STALE_TIME: 1 * MINUTES
134
136
  };
135
137
 
136
138
  // src/lib/AsyncResult.ts
@@ -233,6 +235,8 @@ import {
233
235
  console as console2,
234
236
  DefaultMap,
235
237
  DerivedSignal,
238
+ entries,
239
+ keys,
236
240
  kInternal,
237
241
  MutableSignal as MutableSignal2,
238
242
  nanoid,
@@ -723,6 +727,26 @@ function createStore_forPermissionHints() {
723
727
  update
724
728
  };
725
729
  }
730
+ function createStore_forUserNotificationSettings(updates) {
731
+ const signal = new Signal({});
732
+ function update(settings) {
733
+ signal.set((prevSettings) => {
734
+ return {
735
+ ...prevSettings,
736
+ ...settings
737
+ };
738
+ });
739
+ }
740
+ return {
741
+ signal: DerivedSignal.from(
742
+ signal,
743
+ updates,
744
+ (base, updates2) => applyOptimisticUpdates_forUserNotificationSettings(base, updates2)
745
+ ),
746
+ // Mutations
747
+ update
748
+ };
749
+ }
726
750
  function createStore_forOptimistic(client) {
727
751
  const signal = new Signal([]);
728
752
  const syncSource = client[kInternal].createSyncSource();
@@ -756,15 +780,17 @@ var UmbrellaStore = class {
756
780
  //
757
781
  // Mutate inputs... ...observe clean/consistent output!
758
782
  //
759
- // .-> Base ThreadDB ---------+ +----> Clean threads by ID (Part 1)
783
+ // .-> Base ThreadDB ---------+ +----> Clean threads by ID (Part 1)
760
784
  // / | |
761
- // mutate ----> Base Notifications --+ | | +--> Clean notifications (Part 1)
785
+ // mutate ----> Base Notifications --+ | | +--> Clean notifications (Part 1)
762
786
  // \ | | | | & notifications by ID
763
787
  // | \ | | Apply | |
764
- // | `-> OptimisticUpdates --+--+--> Optimistic --+-+--> Notification Settings (Part 2)
765
- // \ | Updates |
766
- // `------- etc etc ---------+ +--> History Versions (Part 3)
767
- // ^
788
+ // | `-> OptimisticUpdates --+--+--> Optimistic --+-+--> Room Notification Settings (Part 2)
789
+ // \ | Updates | |
790
+ // `------- etc etc ---------+ | +--> History Versions (Part 3)
791
+ // ^ |
792
+ // | +-----> User Notification Settings (Part 4)
793
+ // |
768
794
  // |
769
795
  // | ^ ^
770
796
  // Signal | |
@@ -785,6 +811,7 @@ var UmbrellaStore = class {
785
811
  // prettier-ignore
786
812
  historyVersions;
787
813
  permissionHints;
814
+ userNotificationSettings;
788
815
  optimisticUpdates;
789
816
  //
790
817
  // Output signals.
@@ -805,6 +832,8 @@ var UmbrellaStore = class {
805
832
  #userThreadsLastRequestedAt = null;
806
833
  // Room versions
807
834
  #roomVersionsLastRequestedAtByRoom = /* @__PURE__ */ new Map();
835
+ // User Notification Settings
836
+ #userNotificationSettings;
808
837
  constructor(client) {
809
838
  this.#client = client[kInternal].as();
810
839
  this.optimisticUpdates = createStore_forOptimistic(this.#client);
@@ -820,6 +849,16 @@ var UmbrellaStore = class {
820
849
  return nextCursor;
821
850
  }
822
851
  );
852
+ const userNotificationSettingsFetcher = async () => {
853
+ const result = await this.#client.getNotificationSettings();
854
+ this.userNotificationSettings.update(result);
855
+ };
856
+ this.userNotificationSettings = createStore_forUserNotificationSettings(
857
+ this.optimisticUpdates.signal
858
+ );
859
+ this.#userNotificationSettings = new SinglePageResource(
860
+ userNotificationSettingsFetcher
861
+ );
823
862
  this.threads = new ThreadDB();
824
863
  this.notifications = createStore_forNotifications();
825
864
  this.roomNotificationSettings = createStore_forRoomNotificationSettings(
@@ -997,6 +1036,19 @@ var UmbrellaStore = class {
997
1036
  return { signal, waitUntilLoaded: resource.waitUntilLoaded };
998
1037
  }
999
1038
  );
1039
+ const userNotificationSettings = {
1040
+ signal: DerivedSignal.from(() => {
1041
+ const result = this.#userNotificationSettings.get();
1042
+ if (result.isLoading || result.error) {
1043
+ return result;
1044
+ }
1045
+ return ASYNC_OK(
1046
+ "settings",
1047
+ nn(this.userNotificationSettings.signal.get())
1048
+ );
1049
+ }, shallow3),
1050
+ waitUntilLoaded: this.#userNotificationSettings.waitUntilLoaded
1051
+ };
1000
1052
  this.outputs = {
1001
1053
  threadifications,
1002
1054
  threads,
@@ -1005,7 +1057,8 @@ var UmbrellaStore = class {
1005
1057
  notifications,
1006
1058
  loadingNotifications,
1007
1059
  settingsByRoomId,
1008
- versionsByRoomId
1060
+ versionsByRoomId,
1061
+ userNotificationSettings
1009
1062
  };
1010
1063
  autobind(this);
1011
1064
  }
@@ -1250,6 +1303,25 @@ var UmbrellaStore = class {
1250
1303
  const result = await room.getNotificationSettings({ signal });
1251
1304
  this.roomNotificationSettings.update(roomId, result);
1252
1305
  }
1306
+ /**
1307
+ * Refresh User Notification Settings from poller
1308
+ */
1309
+ async refreshUserNotificationSettings(signal) {
1310
+ const result = await this.#client.getNotificationSettings({
1311
+ signal
1312
+ });
1313
+ this.userNotificationSettings.update(result);
1314
+ }
1315
+ /**
1316
+ * Updates user notification settings with a new value, replacing the
1317
+ * corresponding optimistic update.
1318
+ */
1319
+ updateUserNotificationSettings_confirmOptimisticUpdate(settings, optimisticUpdateId) {
1320
+ batch2(() => {
1321
+ this.optimisticUpdates.remove(optimisticUpdateId);
1322
+ this.userNotificationSettings.update(settings);
1323
+ });
1324
+ }
1253
1325
  };
1254
1326
  function applyOptimisticUpdates_forThreadifications(baseThreadsDB, notificationsLUT, optimisticUpdates) {
1255
1327
  const threadsDB = baseThreadsDB.clone();
@@ -1424,6 +1496,33 @@ function applyOptimisticUpdates_forSettings(settingsLUT, optimisticUpdates) {
1424
1496
  }
1425
1497
  return settingsByRoomId;
1426
1498
  }
1499
+ function applyOptimisticUpdates_forUserNotificationSettings(baseSettings, optimisticUpdates) {
1500
+ const outcomingSettings = { ...baseSettings };
1501
+ for (const optimisticUpdate of optimisticUpdates) {
1502
+ switch (optimisticUpdate.type) {
1503
+ case "update-user-notification-settings": {
1504
+ const incomingSettings = optimisticUpdate.settings;
1505
+ for (const channelKey of keys(incomingSettings)) {
1506
+ const key = channelKey;
1507
+ const channelUpdates = incomingSettings[key];
1508
+ if (channelUpdates) {
1509
+ const realChannelUpdates = Object.fromEntries(
1510
+ entries(channelUpdates).filter(
1511
+ ([_, value]) => value !== void 0
1512
+ )
1513
+ );
1514
+ outcomingSettings[key] = {
1515
+ ...outcomingSettings[key],
1516
+ ...realChannelUpdates
1517
+ };
1518
+ }
1519
+ }
1520
+ break;
1521
+ }
1522
+ }
1523
+ }
1524
+ return outcomingSettings;
1525
+ }
1427
1526
  function compareInboxNotifications(inboxNotificationA, inboxNotificationB) {
1428
1527
  if (inboxNotificationA.notifiedAt > inboxNotificationB.notifiedAt) {
1429
1528
  return 1;
@@ -1717,10 +1816,25 @@ function makeLiveblocksExtrasForClient(client) {
1717
1816
  config.USER_THREADS_POLL_INTERVAL,
1718
1817
  { maxStaleTimeMs: config.USER_THREADS_MAX_STALE_TIME }
1719
1818
  );
1819
+ const userNotificationSettingsPoller = makePoller(
1820
+ async (signal) => {
1821
+ try {
1822
+ return await store.refreshUserNotificationSettings(signal);
1823
+ } catch (err) {
1824
+ console.warn(
1825
+ `Polling new user notification settings failed: ${String(err)}`
1826
+ );
1827
+ throw err;
1828
+ }
1829
+ },
1830
+ config.USER_NOTIFICATION_SETTINGS_INTERVAL,
1831
+ { maxStaleTimeMs: config.USER_NOTIFICATION_SETTINGS_MAX_STALE_TIME }
1832
+ );
1720
1833
  return {
1721
1834
  store,
1722
1835
  notificationsPoller,
1723
- userThreadsPoller
1836
+ userThreadsPoller,
1837
+ userNotificationSettingsPoller
1724
1838
  };
1725
1839
  }
1726
1840
  function makeLiveblocksContextBundle(client) {
@@ -1729,6 +1843,7 @@ function makeLiveblocksContextBundle(client) {
1729
1843
  const useMarkAllInboxNotificationsAsRead2 = () => useMarkAllInboxNotificationsAsRead_withClient(client);
1730
1844
  const useDeleteInboxNotification2 = () => useDeleteInboxNotification_withClient(client);
1731
1845
  const useDeleteAllInboxNotifications2 = () => useDeleteAllInboxNotifications_withClient(client);
1846
+ const useUpdateNotificationSettings2 = () => useUpdateNotificationSettings_withClient(client);
1732
1847
  function LiveblocksProvider2(props) {
1733
1848
  useEnsureNoLiveblocksProvider();
1734
1849
  return /* @__PURE__ */ jsx(ClientContext.Provider, { value: client, children: props.children });
@@ -1742,6 +1857,8 @@ function makeLiveblocksContextBundle(client) {
1742
1857
  useMarkAllInboxNotificationsAsRead: useMarkAllInboxNotificationsAsRead2,
1743
1858
  useDeleteInboxNotification: useDeleteInboxNotification2,
1744
1859
  useDeleteAllInboxNotifications: useDeleteAllInboxNotifications2,
1860
+ useNotificationSettings: () => useNotificationSettings_withClient(client),
1861
+ useUpdateNotificationSettings: useUpdateNotificationSettings2,
1745
1862
  useInboxNotificationThread: useInboxNotificationThread2,
1746
1863
  useUserThreads_experimental,
1747
1864
  ...shared.classic,
@@ -1754,6 +1871,8 @@ function makeLiveblocksContextBundle(client) {
1754
1871
  useDeleteInboxNotification: useDeleteInboxNotification2,
1755
1872
  useDeleteAllInboxNotifications: useDeleteAllInboxNotifications2,
1756
1873
  useInboxNotificationThread: useInboxNotificationThread2,
1874
+ useNotificationSettings: () => useNotificationSettingsSuspense_withClient(client),
1875
+ useUpdateNotificationSettings: useUpdateNotificationSettings2,
1757
1876
  useUserThreads_experimental: useUserThreadsSuspense_experimental,
1758
1877
  ...shared.suspense
1759
1878
  }
@@ -1938,6 +2057,58 @@ function useInboxNotificationThread_withClient(client, inboxNotificationId) {
1938
2057
  )
1939
2058
  );
1940
2059
  }
2060
+ function useUpdateNotificationSettings_withClient(client) {
2061
+ return useCallback2(
2062
+ (settings) => {
2063
+ const { store } = getLiveblocksExtrasForClient(client);
2064
+ const optimisticUpdateId = store.optimisticUpdates.add({
2065
+ type: "update-user-notification-settings",
2066
+ settings
2067
+ });
2068
+ client.updateNotificationSettings(settings).then(
2069
+ (settings2) => {
2070
+ store.updateUserNotificationSettings_confirmOptimisticUpdate(
2071
+ settings2,
2072
+ optimisticUpdateId
2073
+ );
2074
+ },
2075
+ () => {
2076
+ store.optimisticUpdates.remove(optimisticUpdateId);
2077
+ }
2078
+ );
2079
+ },
2080
+ [client]
2081
+ );
2082
+ }
2083
+ function useNotificationSettings_withClient(client) {
2084
+ const updateNotificationSettings = useUpdateNotificationSettings_withClient(client);
2085
+ const { store, userNotificationSettingsPoller: poller } = getLiveblocksExtrasForClient(client);
2086
+ useEffect3(() => {
2087
+ void store.outputs.userNotificationSettings.waitUntilLoaded();
2088
+ });
2089
+ useEffect3(() => {
2090
+ poller.inc();
2091
+ poller.pollNowIfStale();
2092
+ return () => {
2093
+ poller.dec();
2094
+ };
2095
+ }, [poller]);
2096
+ const settings = useSignal(store.outputs.userNotificationSettings.signal);
2097
+ return useMemo2(() => {
2098
+ return [settings, updateNotificationSettings];
2099
+ }, [settings, updateNotificationSettings]);
2100
+ }
2101
+ function useNotificationSettingsSuspense_withClient(client) {
2102
+ ensureNotServerSide();
2103
+ const store = getLiveblocksExtrasForClient(client).store;
2104
+ use(store.outputs.userNotificationSettings.waitUntilLoaded());
2105
+ const [settings, updateNotificationSettings] = useNotificationSettings_withClient(client);
2106
+ assert(!settings.error, "Did not expect error");
2107
+ assert(!settings.isLoading, "Did not expect loading");
2108
+ return useMemo2(() => {
2109
+ return [settings, updateNotificationSettings];
2110
+ }, [settings, updateNotificationSettings]);
2111
+ }
1941
2112
  function useUser_withClient(client, userId) {
1942
2113
  const usersStore = client[kInternal2].usersStore;
1943
2114
  const getUserState = useCallback2(
@@ -2111,7 +2282,6 @@ function LiveblocksProvider(props) {
2111
2282
  lostConnectionTimeout: useInitial(o.lostConnectionTimeout),
2112
2283
  backgroundKeepAliveTimeout: useInitial(o.backgroundKeepAliveTimeout),
2113
2284
  polyfills: useInitial(o.polyfills),
2114
- largeMessageStrategy: useInitial(o.largeMessageStrategy),
2115
2285
  unstable_fallbackToHTTP: useInitial(o.unstable_fallbackToHTTP),
2116
2286
  unstable_streamData: useInitial(o.unstable_streamData),
2117
2287
  preventUnsavedChanges: useInitial(o.preventUnsavedChanges),
@@ -2203,6 +2373,15 @@ function useUnreadInboxNotificationsCount() {
2203
2373
  function useUnreadInboxNotificationsCountSuspense() {
2204
2374
  return useUnreadInboxNotificationsCountSuspense_withClient(useClient());
2205
2375
  }
2376
+ function useNotificationSettings() {
2377
+ return useNotificationSettings_withClient(useClient());
2378
+ }
2379
+ function useNotificationSettingsSuspense() {
2380
+ return useNotificationSettingsSuspense_withClient(useClient());
2381
+ }
2382
+ function useUpdateNotificationSettings() {
2383
+ return useUpdateNotificationSettings_withClient(useClient());
2384
+ }
2206
2385
  function useUser(userId) {
2207
2386
  const client = useClient();
2208
2387
  return useUser_withClient(client, userId);
@@ -3850,6 +4029,9 @@ export {
3850
4029
  useDeleteInboxNotification,
3851
4030
  useUnreadInboxNotificationsCount,
3852
4031
  useUnreadInboxNotificationsCountSuspense,
4032
+ useNotificationSettings,
4033
+ useNotificationSettingsSuspense,
4034
+ useUpdateNotificationSettings,
3853
4035
  useRoomInfo,
3854
4036
  useRoomInfoSuspense,
3855
4037
  _useInboxNotificationThread,
@@ -3934,4 +4116,4 @@ export {
3934
4116
  _useStorageRoot,
3935
4117
  _useUpdateMyPresence
3936
4118
  };
3937
- //# sourceMappingURL=chunk-4KNGHD4I.mjs.map
4119
+ //# sourceMappingURL=chunk-X2FQ2FNK.mjs.map