@liveblocks/react 2.11.1 → 2.12.0-rc1

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.
Files changed (33) hide show
  1. package/dist/_private.d.mts +8 -3
  2. package/dist/_private.d.ts +8 -3
  3. package/dist/_private.js +20 -4
  4. package/dist/_private.js.map +1 -1
  5. package/dist/_private.mjs +18 -2
  6. package/dist/_private.mjs.map +1 -1
  7. package/dist/{chunk-OVU4MAZA.js → chunk-6ESOPOJR.js} +2 -2
  8. package/dist/{chunk-A7GJNN4L.mjs → chunk-CX62YECU.mjs} +60 -15
  9. package/dist/chunk-CX62YECU.mjs.map +1 -0
  10. package/dist/{chunk-3MM4G6XB.js → chunk-IACZPXTY.js} +68 -23
  11. package/dist/chunk-IACZPXTY.js.map +1 -0
  12. package/dist/{chunk-JF4QXLDE.mjs → chunk-MYFO7YF7.mjs} +2 -2
  13. package/dist/index.d.mts +2 -2
  14. package/dist/index.d.ts +2 -2
  15. package/dist/index.js +6 -4
  16. package/dist/index.js.map +1 -1
  17. package/dist/index.mjs +4 -2
  18. package/dist/index.mjs.map +1 -1
  19. package/dist/{liveblocks-SAVcXwMX.d.mts → liveblocks-1ujmr05d.d.mts} +53 -7
  20. package/dist/{liveblocks-SAVcXwMX.d.ts → liveblocks-1ujmr05d.d.ts} +53 -7
  21. package/dist/{suspense-W7Cp9ygn.d.ts → suspense-560_K0iP.d.ts} +5 -1
  22. package/dist/{suspense-vGJE9Mgq.d.mts → suspense-TeBnnKGw.d.mts} +5 -1
  23. package/dist/suspense.d.mts +2 -2
  24. package/dist/suspense.d.ts +2 -2
  25. package/dist/suspense.js +6 -4
  26. package/dist/suspense.js.map +1 -1
  27. package/dist/suspense.mjs +4 -2
  28. package/dist/suspense.mjs.map +1 -1
  29. package/package.json +3 -3
  30. package/dist/chunk-3MM4G6XB.js.map +0 -1
  31. package/dist/chunk-A7GJNN4L.mjs.map +0 -1
  32. /package/dist/{chunk-OVU4MAZA.js.map → chunk-6ESOPOJR.js.map} +0 -0
  33. /package/dist/{chunk-JF4QXLDE.mjs.map → chunk-MYFO7YF7.mjs.map} +0 -0
@@ -1,6 +1,6 @@
1
- export { C as CreateThreadError, g as getUmbrellaStoreForClient } from './liveblocks-SAVcXwMX.mjs';
1
+ export { C as CreateThreadError, g as getUmbrellaStoreForClient } from './liveblocks-1ujmr05d.mjs';
2
+ import { SyncSource } from '@liveblocks/core';
2
3
  import '@liveblocks/client';
3
- import '@liveblocks/core';
4
4
  import 'react';
5
5
 
6
6
  /**
@@ -11,4 +11,9 @@ import 'react';
11
11
  */
12
12
  declare function useMentionSuggestions(search?: string): string[] | undefined;
13
13
 
14
- export { useMentionSuggestions };
14
+ /**
15
+ * @private For internal use only. Do not rely on this hook.
16
+ */
17
+ declare function useSyncSource(): SyncSource | undefined;
18
+
19
+ export { useMentionSuggestions, useSyncSource };
@@ -1,6 +1,6 @@
1
- export { C as CreateThreadError, g as getUmbrellaStoreForClient } from './liveblocks-SAVcXwMX.js';
1
+ export { C as CreateThreadError, g as getUmbrellaStoreForClient } from './liveblocks-1ujmr05d.js';
2
+ import { SyncSource } from '@liveblocks/core';
2
3
  import '@liveblocks/client';
3
- import '@liveblocks/core';
4
4
  import 'react';
5
5
 
6
6
  /**
@@ -11,4 +11,9 @@ import 'react';
11
11
  */
12
12
  declare function useMentionSuggestions(search?: string): string[] | undefined;
13
13
 
14
- export { useMentionSuggestions };
14
+ /**
15
+ * @private For internal use only. Do not rely on this hook.
16
+ */
17
+ declare function useSyncSource(): SyncSource | undefined;
18
+
19
+ export { useMentionSuggestions, useSyncSource };
package/dist/_private.js CHANGED
@@ -3,15 +3,15 @@
3
3
 
4
4
 
5
5
 
6
- var _chunk3MM4G6XBjs = require('./chunk-3MM4G6XB.js');
6
+ var _chunkIACZPXTYjs = require('./chunk-IACZPXTY.js');
7
7
 
8
8
  // src/use-mention-suggestions.ts
9
9
  var _core = require('@liveblocks/core');
10
10
  var _react = require('react'); var _react2 = _interopRequireDefault(_react);
11
11
  var MENTION_SUGGESTIONS_DEBOUNCE = 500;
12
12
  function useMentionSuggestions(search) {
13
- const client = _chunk3MM4G6XBjs.useClient.call(void 0, );
14
- const room = _chunk3MM4G6XBjs._useRoom.call(void 0, );
13
+ const client = _chunkIACZPXTYjs.useClient.call(void 0, );
14
+ const room = _chunkIACZPXTYjs._useRoom.call(void 0, );
15
15
  const [mentionSuggestions, setMentionSuggestions] = _react2.default.useState();
16
16
  const lastInvokedAt = _react2.default.useRef();
17
17
  _react2.default.useEffect(() => {
@@ -60,8 +60,24 @@ function useMentionSuggestions(search) {
60
60
  return mentionSuggestions;
61
61
  }
62
62
 
63
+ // src/use-sync-source.ts
64
+
65
+
66
+ function useSyncSource() {
67
+ const client = _chunkIACZPXTYjs.useClient.call(void 0, );
68
+ const createSyncSource = client[_core.kInternal].createSyncSource;
69
+ const [syncSource, setSyncSource] = _react2.default.useState();
70
+ _react2.default.useEffect(() => {
71
+ const newSyncSource = createSyncSource();
72
+ setSyncSource(newSyncSource);
73
+ return () => newSyncSource.destroy();
74
+ }, [createSyncSource]);
75
+ return syncSource;
76
+ }
77
+
78
+
63
79
 
64
80
 
65
81
 
66
- exports.CreateThreadError = _chunk3MM4G6XBjs.CreateThreadError; exports.getUmbrellaStoreForClient = _chunk3MM4G6XBjs.getUmbrellaStoreForClient; exports.useMentionSuggestions = useMentionSuggestions;
82
+ exports.CreateThreadError = _chunkIACZPXTYjs.CreateThreadError; exports.getUmbrellaStoreForClient = _chunkIACZPXTYjs.getUmbrellaStoreForClient; exports.useMentionSuggestions = useMentionSuggestions; exports.useSyncSource = useSyncSource;
67
83
  //# sourceMappingURL=_private.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/use-mention-suggestions.ts"],"names":["mentionSuggestions"],"mappings":";;;;;;;;AAAA,SAAS,WAAW,iBAAiB;AACrC,OAAO,WAAW;AAKlB,IAAM,+BAA+B;AAQ9B,SAAS,sBAAsB,QAAiB;AACrD,QAAM,SAAS,UAAU;AAEzB,QAAM,OAAO,SAAQ;AACrB,QAAM,CAAC,oBAAoB,qBAAqB,IAC9C,MAAM,SAAmB;AAC3B,QAAM,gBAAgB,MAAM,OAAe;AAE3C,QAAM,UAAU,MAAM;AACpB,UAAM,0BAA0B,OAAO,SAAS,EAAE;AAClD,UAAM,4BACJ,OAAO,SAAS,EAAE;AAEpB,QAAI,WAAW,UAAa,CAAC,2BAA2B;AACtD;AAAA,IACF;AAEA,UAAM,gCAAgC,EAAE,MAAM,QAAQ,QAAQ,KAAK,GAAG;AACtE,UAAM,6BAA6B,UAAU,6BAA6B;AAC1E,QAAI;AACJ,QAAI,aAAa;AAEjB,UAAM,wBAAwB,YAAY;AACxC,UAAI;AACF,sBAAc,UAAU,YAAY,IAAI;AACxC,cAAMA,sBAAqB,MAAM;AAAA,UAC/B;AAAA,QACF;AAEA,YAAI,CAAC,YAAY;AACf,gCAAsBA,mBAAkB;AACxC,kCAAwB;AAAA,YACtB;AAAA,YACAA;AAAA,UACF;AAAA,QACF;AAAA,MACF,SAAS,OAAO;AACd,gBAAQ,MAAO,OAAiB,OAAO;AAAA,MACzC;AAAA,IACF;AAEA,QAAI,wBAAwB,IAAI,0BAA0B,GAAG;AAE3D;AAAA,QACE,wBAAwB,IAAI,0BAA0B;AAAA,MACxD;AAAA,IACF,WACE,CAAC,cAAc,WACf,KAAK,IAAI,YAAY,IAAI,IAAI,cAAc,OAAO,IAChD,8BACF;AAGA,WAAK,sBAAsB;AAAA,IAC7B,OAAO;AAEL,wBAAkB,OAAO,WAAW,MAAM;AACxC,aAAK,sBAAsB;AAAA,MAC7B,GAAG,4BAA4B;AAAA,IACjC;AAEA,WAAO,MAAM;AACX,mBAAa;AACb,aAAO,aAAa,eAAe;AAAA,IACrC;AAAA,EACF,GAAG,CAAC,QAAQ,KAAK,IAAI,MAAM,CAAC;AAE5B,SAAO;AACT","sourcesContent":["import { kInternal, stringify } from \"@liveblocks/core\";\nimport React from \"react\";\n\nimport { useClient } from \"./liveblocks\";\nimport { useRoom } from \"./room\";\n\nconst MENTION_SUGGESTIONS_DEBOUNCE = 500;\n\n/**\n * @private For internal use only. Do not rely on this hook.\n *\n * Simplistic debounced search, we don't need to worry too much about deduping\n * and race conditions as there can only be one search at a time.\n */\nexport function useMentionSuggestions(search?: string) {\n const client = useClient();\n\n const room = useRoom();\n const [mentionSuggestions, setMentionSuggestions] =\n React.useState<string[]>();\n const lastInvokedAt = React.useRef<number>();\n\n React.useEffect(() => {\n const mentionSuggestionsCache = client[kInternal].mentionSuggestionsCache;\n const resolveMentionSuggestions =\n client[kInternal].resolveMentionSuggestions;\n\n if (search === undefined || !resolveMentionSuggestions) {\n return;\n }\n\n const resolveMentionSuggestionsArgs = { text: search, roomId: room.id };\n const mentionSuggestionsCacheKey = stringify(resolveMentionSuggestionsArgs);\n let debounceTimeout: number | undefined;\n let isCanceled = false;\n\n const getMentionSuggestions = async () => {\n try {\n lastInvokedAt.current = performance.now();\n const mentionSuggestions = await resolveMentionSuggestions(\n resolveMentionSuggestionsArgs\n );\n\n if (!isCanceled) {\n setMentionSuggestions(mentionSuggestions);\n mentionSuggestionsCache.set(\n mentionSuggestionsCacheKey,\n mentionSuggestions\n );\n }\n } catch (error) {\n console.error((error as Error)?.message);\n }\n };\n\n if (mentionSuggestionsCache.has(mentionSuggestionsCacheKey)) {\n // If there are already cached mention suggestions, use them immediately.\n setMentionSuggestions(\n mentionSuggestionsCache.get(mentionSuggestionsCacheKey)\n );\n } else if (\n !lastInvokedAt.current ||\n Math.abs(performance.now() - lastInvokedAt.current) >\n MENTION_SUGGESTIONS_DEBOUNCE\n ) {\n // If on the debounce's leading edge (either because it's the first invokation or enough\n // time has passed since the last debounce), get mention suggestions immediately.\n void getMentionSuggestions();\n } else {\n // Otherwise, wait for the debounce delay.\n debounceTimeout = window.setTimeout(() => {\n void getMentionSuggestions();\n }, MENTION_SUGGESTIONS_DEBOUNCE);\n }\n\n return () => {\n isCanceled = true;\n window.clearTimeout(debounceTimeout);\n };\n }, [client, room.id, search]);\n\n return mentionSuggestions;\n}\n"]}
1
+ {"version":3,"sources":["../src/use-mention-suggestions.ts","../src/use-sync-source.ts"],"names":["mentionSuggestions","kInternal","React"],"mappings":";;;;;;;;AAAA,SAAS,WAAW,iBAAiB;AACrC,OAAO,WAAW;AAKlB,IAAM,+BAA+B;AAQ9B,SAAS,sBAAsB,QAAiB;AACrD,QAAM,SAAS,UAAU;AAEzB,QAAM,OAAO,SAAQ;AACrB,QAAM,CAAC,oBAAoB,qBAAqB,IAC9C,MAAM,SAAmB;AAC3B,QAAM,gBAAgB,MAAM,OAAe;AAE3C,QAAM,UAAU,MAAM;AACpB,UAAM,0BAA0B,OAAO,SAAS,EAAE;AAClD,UAAM,4BACJ,OAAO,SAAS,EAAE;AAEpB,QAAI,WAAW,UAAa,CAAC,2BAA2B;AACtD;AAAA,IACF;AAEA,UAAM,gCAAgC,EAAE,MAAM,QAAQ,QAAQ,KAAK,GAAG;AACtE,UAAM,6BAA6B,UAAU,6BAA6B;AAC1E,QAAI;AACJ,QAAI,aAAa;AAEjB,UAAM,wBAAwB,YAAY;AACxC,UAAI;AACF,sBAAc,UAAU,YAAY,IAAI;AACxC,cAAMA,sBAAqB,MAAM;AAAA,UAC/B;AAAA,QACF;AAEA,YAAI,CAAC,YAAY;AACf,gCAAsBA,mBAAkB;AACxC,kCAAwB;AAAA,YACtB;AAAA,YACAA;AAAA,UACF;AAAA,QACF;AAAA,MACF,SAAS,OAAO;AACd,gBAAQ,MAAO,OAAiB,OAAO;AAAA,MACzC;AAAA,IACF;AAEA,QAAI,wBAAwB,IAAI,0BAA0B,GAAG;AAE3D;AAAA,QACE,wBAAwB,IAAI,0BAA0B;AAAA,MACxD;AAAA,IACF,WACE,CAAC,cAAc,WACf,KAAK,IAAI,YAAY,IAAI,IAAI,cAAc,OAAO,IAChD,8BACF;AAGA,WAAK,sBAAsB;AAAA,IAC7B,OAAO;AAEL,wBAAkB,OAAO,WAAW,MAAM;AACxC,aAAK,sBAAsB;AAAA,MAC7B,GAAG,4BAA4B;AAAA,IACjC;AAEA,WAAO,MAAM;AACX,mBAAa;AACb,aAAO,aAAa,eAAe;AAAA,IACrC;AAAA,EACF,GAAG,CAAC,QAAQ,KAAK,IAAI,MAAM,CAAC;AAE5B,SAAO;AACT;;;ACjFA,SAAS,aAAAC,kBAAiB;AAC1B,OAAOC,YAAW;AAOX,SAAS,gBAAwC;AACtD,QAAM,SAAS,UAAU;AACzB,QAAM,mBAAmB,OAAOD,UAAS,EAAE;AAC3C,QAAM,CAAC,YAAY,aAAa,IAAIC,OAAM,SAAiC;AAE3E,EAAAA,OAAM,UAAU,MAAM;AAEpB,UAAM,gBAAgB,iBAAiB;AACvC,kBAAc,aAAa;AAC3B,WAAO,MAAM,cAAc,QAAQ;AAAA,EACrC,GAAG,CAAC,gBAAgB,CAAC;AAErB,SAAO;AACT","sourcesContent":["import { kInternal, stringify } from \"@liveblocks/core\";\nimport React from \"react\";\n\nimport { useClient } from \"./liveblocks\";\nimport { useRoom } from \"./room\";\n\nconst MENTION_SUGGESTIONS_DEBOUNCE = 500;\n\n/**\n * @private For internal use only. Do not rely on this hook.\n *\n * Simplistic debounced search, we don't need to worry too much about deduping\n * and race conditions as there can only be one search at a time.\n */\nexport function useMentionSuggestions(search?: string) {\n const client = useClient();\n\n const room = useRoom();\n const [mentionSuggestions, setMentionSuggestions] =\n React.useState<string[]>();\n const lastInvokedAt = React.useRef<number>();\n\n React.useEffect(() => {\n const mentionSuggestionsCache = client[kInternal].mentionSuggestionsCache;\n const resolveMentionSuggestions =\n client[kInternal].resolveMentionSuggestions;\n\n if (search === undefined || !resolveMentionSuggestions) {\n return;\n }\n\n const resolveMentionSuggestionsArgs = { text: search, roomId: room.id };\n const mentionSuggestionsCacheKey = stringify(resolveMentionSuggestionsArgs);\n let debounceTimeout: number | undefined;\n let isCanceled = false;\n\n const getMentionSuggestions = async () => {\n try {\n lastInvokedAt.current = performance.now();\n const mentionSuggestions = await resolveMentionSuggestions(\n resolveMentionSuggestionsArgs\n );\n\n if (!isCanceled) {\n setMentionSuggestions(mentionSuggestions);\n mentionSuggestionsCache.set(\n mentionSuggestionsCacheKey,\n mentionSuggestions\n );\n }\n } catch (error) {\n console.error((error as Error)?.message);\n }\n };\n\n if (mentionSuggestionsCache.has(mentionSuggestionsCacheKey)) {\n // If there are already cached mention suggestions, use them immediately.\n setMentionSuggestions(\n mentionSuggestionsCache.get(mentionSuggestionsCacheKey)\n );\n } else if (\n !lastInvokedAt.current ||\n Math.abs(performance.now() - lastInvokedAt.current) >\n MENTION_SUGGESTIONS_DEBOUNCE\n ) {\n // If on the debounce's leading edge (either because it's the first invokation or enough\n // time has passed since the last debounce), get mention suggestions immediately.\n void getMentionSuggestions();\n } else {\n // Otherwise, wait for the debounce delay.\n debounceTimeout = window.setTimeout(() => {\n void getMentionSuggestions();\n }, MENTION_SUGGESTIONS_DEBOUNCE);\n }\n\n return () => {\n isCanceled = true;\n window.clearTimeout(debounceTimeout);\n };\n }, [client, room.id, search]);\n\n return mentionSuggestions;\n}\n","import type { SyncSource } from \"@liveblocks/core\";\nimport { kInternal } from \"@liveblocks/core\";\nimport React from \"react\";\n\nimport { useClient } from \"./liveblocks\";\n\n/**\n * @private For internal use only. Do not rely on this hook.\n */\nexport function useSyncSource(): SyncSource | undefined {\n const client = useClient();\n const createSyncSource = client[kInternal].createSyncSource;\n const [syncSource, setSyncSource] = React.useState<SyncSource | undefined>();\n\n React.useEffect(() => {\n // Create new sync source on mount\n const newSyncSource = createSyncSource();\n setSyncSource(newSyncSource);\n return () => newSyncSource.destroy();\n }, [createSyncSource]);\n\n return syncSource;\n}\n"]}
package/dist/_private.mjs CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  _useRoom,
4
4
  getUmbrellaStoreForClient,
5
5
  useClient
6
- } from "./chunk-A7GJNN4L.mjs";
6
+ } from "./chunk-CX62YECU.mjs";
7
7
 
8
8
  // src/use-mention-suggestions.ts
9
9
  import { kInternal, stringify } from "@liveblocks/core";
@@ -59,9 +59,25 @@ function useMentionSuggestions(search) {
59
59
  }, [client, room.id, search]);
60
60
  return mentionSuggestions;
61
61
  }
62
+
63
+ // src/use-sync-source.ts
64
+ import { kInternal as kInternal2 } from "@liveblocks/core";
65
+ import React2 from "react";
66
+ function useSyncSource() {
67
+ const client = useClient();
68
+ const createSyncSource = client[kInternal2].createSyncSource;
69
+ const [syncSource, setSyncSource] = React2.useState();
70
+ React2.useEffect(() => {
71
+ const newSyncSource = createSyncSource();
72
+ setSyncSource(newSyncSource);
73
+ return () => newSyncSource.destroy();
74
+ }, [createSyncSource]);
75
+ return syncSource;
76
+ }
62
77
  export {
63
78
  CreateThreadError,
64
79
  getUmbrellaStoreForClient,
65
- useMentionSuggestions
80
+ useMentionSuggestions,
81
+ useSyncSource
66
82
  };
67
83
  //# sourceMappingURL=_private.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/use-mention-suggestions.ts"],"sourcesContent":["import { kInternal, stringify } from \"@liveblocks/core\";\nimport React from \"react\";\n\nimport { useClient } from \"./liveblocks\";\nimport { useRoom } from \"./room\";\n\nconst MENTION_SUGGESTIONS_DEBOUNCE = 500;\n\n/**\n * @private For internal use only. Do not rely on this hook.\n *\n * Simplistic debounced search, we don't need to worry too much about deduping\n * and race conditions as there can only be one search at a time.\n */\nexport function useMentionSuggestions(search?: string) {\n const client = useClient();\n\n const room = useRoom();\n const [mentionSuggestions, setMentionSuggestions] =\n React.useState<string[]>();\n const lastInvokedAt = React.useRef<number>();\n\n React.useEffect(() => {\n const mentionSuggestionsCache = client[kInternal].mentionSuggestionsCache;\n const resolveMentionSuggestions =\n client[kInternal].resolveMentionSuggestions;\n\n if (search === undefined || !resolveMentionSuggestions) {\n return;\n }\n\n const resolveMentionSuggestionsArgs = { text: search, roomId: room.id };\n const mentionSuggestionsCacheKey = stringify(resolveMentionSuggestionsArgs);\n let debounceTimeout: number | undefined;\n let isCanceled = false;\n\n const getMentionSuggestions = async () => {\n try {\n lastInvokedAt.current = performance.now();\n const mentionSuggestions = await resolveMentionSuggestions(\n resolveMentionSuggestionsArgs\n );\n\n if (!isCanceled) {\n setMentionSuggestions(mentionSuggestions);\n mentionSuggestionsCache.set(\n mentionSuggestionsCacheKey,\n mentionSuggestions\n );\n }\n } catch (error) {\n console.error((error as Error)?.message);\n }\n };\n\n if (mentionSuggestionsCache.has(mentionSuggestionsCacheKey)) {\n // If there are already cached mention suggestions, use them immediately.\n setMentionSuggestions(\n mentionSuggestionsCache.get(mentionSuggestionsCacheKey)\n );\n } else if (\n !lastInvokedAt.current ||\n Math.abs(performance.now() - lastInvokedAt.current) >\n MENTION_SUGGESTIONS_DEBOUNCE\n ) {\n // If on the debounce's leading edge (either because it's the first invokation or enough\n // time has passed since the last debounce), get mention suggestions immediately.\n void getMentionSuggestions();\n } else {\n // Otherwise, wait for the debounce delay.\n debounceTimeout = window.setTimeout(() => {\n void getMentionSuggestions();\n }, MENTION_SUGGESTIONS_DEBOUNCE);\n }\n\n return () => {\n isCanceled = true;\n window.clearTimeout(debounceTimeout);\n };\n }, [client, room.id, search]);\n\n return mentionSuggestions;\n}\n"],"mappings":";;;;;;;;AAAA,SAAS,WAAW,iBAAiB;AACrC,OAAO,WAAW;AAKlB,IAAM,+BAA+B;AAQ9B,SAAS,sBAAsB,QAAiB;AACrD,QAAM,SAAS,UAAU;AAEzB,QAAM,OAAO,SAAQ;AACrB,QAAM,CAAC,oBAAoB,qBAAqB,IAC9C,MAAM,SAAmB;AAC3B,QAAM,gBAAgB,MAAM,OAAe;AAE3C,QAAM,UAAU,MAAM;AACpB,UAAM,0BAA0B,OAAO,SAAS,EAAE;AAClD,UAAM,4BACJ,OAAO,SAAS,EAAE;AAEpB,QAAI,WAAW,UAAa,CAAC,2BAA2B;AACtD;AAAA,IACF;AAEA,UAAM,gCAAgC,EAAE,MAAM,QAAQ,QAAQ,KAAK,GAAG;AACtE,UAAM,6BAA6B,UAAU,6BAA6B;AAC1E,QAAI;AACJ,QAAI,aAAa;AAEjB,UAAM,wBAAwB,YAAY;AACxC,UAAI;AACF,sBAAc,UAAU,YAAY,IAAI;AACxC,cAAMA,sBAAqB,MAAM;AAAA,UAC/B;AAAA,QACF;AAEA,YAAI,CAAC,YAAY;AACf,gCAAsBA,mBAAkB;AACxC,kCAAwB;AAAA,YACtB;AAAA,YACAA;AAAA,UACF;AAAA,QACF;AAAA,MACF,SAAS,OAAO;AACd,gBAAQ,MAAO,OAAiB,OAAO;AAAA,MACzC;AAAA,IACF;AAEA,QAAI,wBAAwB,IAAI,0BAA0B,GAAG;AAE3D;AAAA,QACE,wBAAwB,IAAI,0BAA0B;AAAA,MACxD;AAAA,IACF,WACE,CAAC,cAAc,WACf,KAAK,IAAI,YAAY,IAAI,IAAI,cAAc,OAAO,IAChD,8BACF;AAGA,WAAK,sBAAsB;AAAA,IAC7B,OAAO;AAEL,wBAAkB,OAAO,WAAW,MAAM;AACxC,aAAK,sBAAsB;AAAA,MAC7B,GAAG,4BAA4B;AAAA,IACjC;AAEA,WAAO,MAAM;AACX,mBAAa;AACb,aAAO,aAAa,eAAe;AAAA,IACrC;AAAA,EACF,GAAG,CAAC,QAAQ,KAAK,IAAI,MAAM,CAAC;AAE5B,SAAO;AACT;","names":["mentionSuggestions"]}
1
+ {"version":3,"sources":["../src/use-mention-suggestions.ts","../src/use-sync-source.ts"],"sourcesContent":["import { kInternal, stringify } from \"@liveblocks/core\";\nimport React from \"react\";\n\nimport { useClient } from \"./liveblocks\";\nimport { useRoom } from \"./room\";\n\nconst MENTION_SUGGESTIONS_DEBOUNCE = 500;\n\n/**\n * @private For internal use only. Do not rely on this hook.\n *\n * Simplistic debounced search, we don't need to worry too much about deduping\n * and race conditions as there can only be one search at a time.\n */\nexport function useMentionSuggestions(search?: string) {\n const client = useClient();\n\n const room = useRoom();\n const [mentionSuggestions, setMentionSuggestions] =\n React.useState<string[]>();\n const lastInvokedAt = React.useRef<number>();\n\n React.useEffect(() => {\n const mentionSuggestionsCache = client[kInternal].mentionSuggestionsCache;\n const resolveMentionSuggestions =\n client[kInternal].resolveMentionSuggestions;\n\n if (search === undefined || !resolveMentionSuggestions) {\n return;\n }\n\n const resolveMentionSuggestionsArgs = { text: search, roomId: room.id };\n const mentionSuggestionsCacheKey = stringify(resolveMentionSuggestionsArgs);\n let debounceTimeout: number | undefined;\n let isCanceled = false;\n\n const getMentionSuggestions = async () => {\n try {\n lastInvokedAt.current = performance.now();\n const mentionSuggestions = await resolveMentionSuggestions(\n resolveMentionSuggestionsArgs\n );\n\n if (!isCanceled) {\n setMentionSuggestions(mentionSuggestions);\n mentionSuggestionsCache.set(\n mentionSuggestionsCacheKey,\n mentionSuggestions\n );\n }\n } catch (error) {\n console.error((error as Error)?.message);\n }\n };\n\n if (mentionSuggestionsCache.has(mentionSuggestionsCacheKey)) {\n // If there are already cached mention suggestions, use them immediately.\n setMentionSuggestions(\n mentionSuggestionsCache.get(mentionSuggestionsCacheKey)\n );\n } else if (\n !lastInvokedAt.current ||\n Math.abs(performance.now() - lastInvokedAt.current) >\n MENTION_SUGGESTIONS_DEBOUNCE\n ) {\n // If on the debounce's leading edge (either because it's the first invokation or enough\n // time has passed since the last debounce), get mention suggestions immediately.\n void getMentionSuggestions();\n } else {\n // Otherwise, wait for the debounce delay.\n debounceTimeout = window.setTimeout(() => {\n void getMentionSuggestions();\n }, MENTION_SUGGESTIONS_DEBOUNCE);\n }\n\n return () => {\n isCanceled = true;\n window.clearTimeout(debounceTimeout);\n };\n }, [client, room.id, search]);\n\n return mentionSuggestions;\n}\n","import type { SyncSource } from \"@liveblocks/core\";\nimport { kInternal } from \"@liveblocks/core\";\nimport React from \"react\";\n\nimport { useClient } from \"./liveblocks\";\n\n/**\n * @private For internal use only. Do not rely on this hook.\n */\nexport function useSyncSource(): SyncSource | undefined {\n const client = useClient();\n const createSyncSource = client[kInternal].createSyncSource;\n const [syncSource, setSyncSource] = React.useState<SyncSource | undefined>();\n\n React.useEffect(() => {\n // Create new sync source on mount\n const newSyncSource = createSyncSource();\n setSyncSource(newSyncSource);\n return () => newSyncSource.destroy();\n }, [createSyncSource]);\n\n return syncSource;\n}\n"],"mappings":";;;;;;;;AAAA,SAAS,WAAW,iBAAiB;AACrC,OAAO,WAAW;AAKlB,IAAM,+BAA+B;AAQ9B,SAAS,sBAAsB,QAAiB;AACrD,QAAM,SAAS,UAAU;AAEzB,QAAM,OAAO,SAAQ;AACrB,QAAM,CAAC,oBAAoB,qBAAqB,IAC9C,MAAM,SAAmB;AAC3B,QAAM,gBAAgB,MAAM,OAAe;AAE3C,QAAM,UAAU,MAAM;AACpB,UAAM,0BAA0B,OAAO,SAAS,EAAE;AAClD,UAAM,4BACJ,OAAO,SAAS,EAAE;AAEpB,QAAI,WAAW,UAAa,CAAC,2BAA2B;AACtD;AAAA,IACF;AAEA,UAAM,gCAAgC,EAAE,MAAM,QAAQ,QAAQ,KAAK,GAAG;AACtE,UAAM,6BAA6B,UAAU,6BAA6B;AAC1E,QAAI;AACJ,QAAI,aAAa;AAEjB,UAAM,wBAAwB,YAAY;AACxC,UAAI;AACF,sBAAc,UAAU,YAAY,IAAI;AACxC,cAAMA,sBAAqB,MAAM;AAAA,UAC/B;AAAA,QACF;AAEA,YAAI,CAAC,YAAY;AACf,gCAAsBA,mBAAkB;AACxC,kCAAwB;AAAA,YACtB;AAAA,YACAA;AAAA,UACF;AAAA,QACF;AAAA,MACF,SAAS,OAAO;AACd,gBAAQ,MAAO,OAAiB,OAAO;AAAA,MACzC;AAAA,IACF;AAEA,QAAI,wBAAwB,IAAI,0BAA0B,GAAG;AAE3D;AAAA,QACE,wBAAwB,IAAI,0BAA0B;AAAA,MACxD;AAAA,IACF,WACE,CAAC,cAAc,WACf,KAAK,IAAI,YAAY,IAAI,IAAI,cAAc,OAAO,IAChD,8BACF;AAGA,WAAK,sBAAsB;AAAA,IAC7B,OAAO;AAEL,wBAAkB,OAAO,WAAW,MAAM;AACxC,aAAK,sBAAsB;AAAA,MAC7B,GAAG,4BAA4B;AAAA,IACjC;AAEA,WAAO,MAAM;AACX,mBAAa;AACb,aAAO,aAAa,eAAe;AAAA,IACrC;AAAA,EACF,GAAG,CAAC,QAAQ,KAAK,IAAI,MAAM,CAAC;AAE5B,SAAO;AACT;;;ACjFA,SAAS,aAAAC,kBAAiB;AAC1B,OAAOC,YAAW;AAOX,SAAS,gBAAwC;AACtD,QAAM,SAAS,UAAU;AACzB,QAAM,mBAAmB,OAAOC,UAAS,EAAE;AAC3C,QAAM,CAAC,YAAY,aAAa,IAAIC,OAAM,SAAiC;AAE3E,EAAAA,OAAM,UAAU,MAAM;AAEpB,UAAM,gBAAgB,iBAAiB;AACvC,kBAAc,aAAa;AAC3B,WAAO,MAAM,cAAc,QAAQ;AAAA,EACrC,GAAG,CAAC,gBAAgB,CAAC;AAErB,SAAO;AACT;","names":["mentionSuggestions","kInternal","React","kInternal","React"]}
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }// src/version.ts
2
2
  var PKG_NAME = "@liveblocks/react";
3
- var PKG_VERSION = "2.11.1";
3
+ var PKG_VERSION = "2.12.0-rc1";
4
4
  var PKG_FORMAT = "cjs";
5
5
 
6
6
  // src/ClientSideSuspense.tsx
@@ -19,4 +19,4 @@ function ClientSideSuspense(props) {
19
19
 
20
20
 
21
21
  exports.PKG_NAME = PKG_NAME; exports.PKG_VERSION = PKG_VERSION; exports.PKG_FORMAT = PKG_FORMAT; exports.ClientSideSuspense = ClientSideSuspense;
22
- //# sourceMappingURL=chunk-OVU4MAZA.js.map
22
+ //# sourceMappingURL=chunk-6ESOPOJR.js.map
@@ -32,6 +32,7 @@ import { useSyncExternalStoreWithSelector } from "use-sync-external-store/shim/w
32
32
  var SECONDS = 1e3;
33
33
  var MINUTES = 60 * SECONDS;
34
34
  var config = {
35
+ SMOOTH_DELAY: 1 * SECONDS,
35
36
  NOTIFICATIONS_POLL_INTERVAL: 1 * MINUTES,
36
37
  NOTIFICATIONS_MAX_STALE_TIME: 5 * SECONDS,
37
38
  ROOM_THREADS_POLL_INTERVAL: 5 * MINUTES,
@@ -503,6 +504,7 @@ var UmbrellaStore = class {
503
504
  // Room notification settings
504
505
  this._roomNotificationSettings = /* @__PURE__ */ new Map();
505
506
  this._client = client[kInternal].as();
507
+ this._syncSource = this._client[kInternal].createSyncSource();
506
508
  const inboxFetcher = async (cursor) => {
507
509
  const result = await this._client.getInboxNotifications({ cursor });
508
510
  this.updateThreadsAndNotifications(
@@ -651,12 +653,6 @@ var UmbrellaStore = class {
651
653
  versions: Object.values(this.get().versionsByRoomId[roomId] ?? {})
652
654
  };
653
655
  }
654
- /**
655
- * @private Only used by the E2E test suite.
656
- */
657
- _hasOptimisticUpdates() {
658
- return this._store.get().optimisticUpdates.length > 0;
659
- }
660
656
  subscribe(callback) {
661
657
  return this._store.subscribe(callback);
662
658
  }
@@ -703,10 +699,13 @@ var UmbrellaStore = class {
703
699
  });
704
700
  }
705
701
  updateOptimisticUpdatesCache(mapFn) {
706
- this._store.set((state) => ({
707
- ...state,
708
- optimisticUpdates: mapFn(state.optimisticUpdates)
709
- }));
702
+ this._store.set((state) => {
703
+ const optimisticUpdates = mapFn(state.optimisticUpdates);
704
+ this._syncSource.setSyncStatus(
705
+ optimisticUpdates.length > 0 ? "synchronizing" : "synchronized"
706
+ );
707
+ return { ...state, optimisticUpdates };
708
+ });
710
709
  }
711
710
  // ---------------------------------------------------------------------------------- }}}
712
711
  /** @internal - Only call this method from unit tests. */
@@ -1952,18 +1951,23 @@ function useRoomInfoSuspense_withClient(client, roomId) {
1952
1951
  }
1953
1952
  function createSharedContext(client) {
1954
1953
  const useClient2 = () => client;
1954
+ function useSyncStatus2(options) {
1955
+ return useSyncStatus_withClient(client, options);
1956
+ }
1955
1957
  return {
1956
1958
  classic: {
1957
1959
  useClient: useClient2,
1958
1960
  useUser: (userId) => useUser_withClient(client, userId),
1959
1961
  useRoomInfo: (roomId) => useRoomInfo_withClient(client, roomId),
1960
- useIsInsideRoom
1962
+ useIsInsideRoom,
1963
+ useSyncStatus: useSyncStatus2
1961
1964
  },
1962
1965
  suspense: {
1963
1966
  useClient: useClient2,
1964
1967
  useUser: (userId) => useUserSuspense_withClient(client, userId),
1965
1968
  useRoomInfo: (roomId) => useRoomInfoSuspense_withClient(client, roomId),
1966
- useIsInsideRoom
1969
+ useIsInsideRoom,
1970
+ useSyncStatus: useSyncStatus2
1967
1971
  }
1968
1972
  };
1969
1973
  }
@@ -1995,6 +1999,7 @@ function LiveblocksProvider(props) {
1995
1999
  polyfills: useInitial(o.polyfills),
1996
2000
  unstable_fallbackToHTTP: useInitial(o.unstable_fallbackToHTTP),
1997
2001
  unstable_streamData: useInitial(o.unstable_streamData),
2002
+ preventUnsavedChanges: useInitial(o.preventUnsavedChanges),
1998
2003
  authEndpoint: useInitialUnlessFunction(o.authEndpoint),
1999
2004
  resolveMentionSuggestions: useInitialUnlessFunction(
2000
2005
  o.resolveMentionSuggestions
@@ -2118,6 +2123,46 @@ var _useUser = useUser;
2118
2123
  var _useUserSuspense = useUserSuspense;
2119
2124
  var _useUserThreads_experimental = useUserThreads_experimental;
2120
2125
  var _useUserThreadsSuspense_experimental = useUserThreadsSuspense_experimental;
2126
+ function useSyncStatus_withClient(client, options) {
2127
+ const smooth = useInitial(options?.smooth ?? false);
2128
+ if (smooth) {
2129
+ return useSyncStatusSmooth_withClient(client);
2130
+ } else {
2131
+ return useSyncStatusImmediate_withClient(client);
2132
+ }
2133
+ }
2134
+ function useSyncStatusImmediate_withClient(client) {
2135
+ return useSyncExternalStore(
2136
+ client.events.syncStatus.subscribe,
2137
+ client.getSyncStatus,
2138
+ client.getSyncStatus
2139
+ );
2140
+ }
2141
+ function useSyncStatusSmooth_withClient(client) {
2142
+ const getter = client.getSyncStatus;
2143
+ const [status, setStatus] = React2.useState(getter);
2144
+ const oldStatus = useLatest(getter());
2145
+ React2.useEffect(() => {
2146
+ let timeoutId;
2147
+ const unsub = client.events.syncStatus.subscribe(() => {
2148
+ const newStatus = getter();
2149
+ if (oldStatus.current === "synchronizing" && newStatus === "synchronized") {
2150
+ timeoutId = setTimeout(() => setStatus(newStatus), config.SMOOTH_DELAY);
2151
+ } else {
2152
+ clearTimeout(timeoutId);
2153
+ setStatus(newStatus);
2154
+ }
2155
+ });
2156
+ return () => {
2157
+ clearTimeout(timeoutId);
2158
+ unsub();
2159
+ };
2160
+ }, [client, getter, oldStatus]);
2161
+ return status;
2162
+ }
2163
+ function useSyncStatus(options) {
2164
+ return useSyncStatus_withClient(useClient(), options);
2165
+ }
2121
2166
 
2122
2167
  // src/types/errors.ts
2123
2168
  var CreateThreadError = class extends Error {
@@ -2265,7 +2310,6 @@ function useScrollToCommentOnLoadEffect(shouldScrollOnLoad, state) {
2265
2310
  }
2266
2311
 
2267
2312
  // src/room.tsx
2268
- var SMOOTH_DELAY = 1e3;
2269
2313
  var noop3 = () => {
2270
2314
  };
2271
2315
  var identity2 = (x) => x;
@@ -2695,7 +2739,7 @@ function useStorageStatusSmooth() {
2695
2739
  let timeoutId;
2696
2740
  const unsub = room.events.storageStatus.subscribe((newStatus) => {
2697
2741
  if (oldStatus.current === "synchronizing" && newStatus === "synchronized") {
2698
- timeoutId = setTimeout(() => setStatus(newStatus), SMOOTH_DELAY);
2742
+ timeoutId = setTimeout(() => setStatus(newStatus), config.SMOOTH_DELAY);
2699
2743
  } else {
2700
2744
  clearTimeout(timeoutId);
2701
2745
  setStatus(newStatus);
@@ -3809,6 +3853,7 @@ export {
3809
3853
  _useUserSuspense,
3810
3854
  _useUserThreads_experimental,
3811
3855
  _useUserThreadsSuspense_experimental,
3856
+ useSyncStatus,
3812
3857
  CreateThreadError,
3813
3858
  useStatus,
3814
3859
  useStorageStatus,
@@ -3868,4 +3913,4 @@ export {
3868
3913
  _useStorageRoot,
3869
3914
  _useUpdateMyPresence
3870
3915
  };
3871
- //# sourceMappingURL=chunk-A7GJNN4L.mjs.map
3916
+ //# sourceMappingURL=chunk-CX62YECU.mjs.map