@liveblocks/react-ui 1.12.0-initial1 → 2.0.0-alpha1

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 (45) hide show
  1. package/dist/components/Comment.js +8 -17
  2. package/dist/components/Comment.js.map +1 -1
  3. package/dist/components/Comment.mjs +1 -10
  4. package/dist/components/Comment.mjs.map +1 -1
  5. package/dist/components/Composer.js +4 -6
  6. package/dist/components/Composer.js.map +1 -1
  7. package/dist/components/Composer.mjs +1 -3
  8. package/dist/components/Composer.mjs.map +1 -1
  9. package/dist/components/InboxNotification.js +3 -5
  10. package/dist/components/InboxNotification.js.map +1 -1
  11. package/dist/components/InboxNotification.mjs +1 -3
  12. package/dist/components/InboxNotification.mjs.map +1 -1
  13. package/dist/components/InboxNotificationList.js.map +1 -1
  14. package/dist/components/InboxNotificationList.mjs.map +1 -1
  15. package/dist/components/Thread.js +2 -3
  16. package/dist/components/Thread.js.map +1 -1
  17. package/dist/components/Thread.mjs +1 -2
  18. package/dist/components/Thread.mjs.map +1 -1
  19. package/dist/components/internal/Avatar.js +1 -1
  20. package/dist/components/internal/Avatar.js.map +1 -1
  21. package/dist/components/internal/Avatar.mjs +1 -1
  22. package/dist/components/internal/Avatar.mjs.map +1 -1
  23. package/dist/components/internal/Room.js +1 -2
  24. package/dist/components/internal/Room.js.map +1 -1
  25. package/dist/components/internal/Room.mjs +1 -2
  26. package/dist/components/internal/Room.mjs.map +1 -1
  27. package/dist/index.d.mts +21 -4
  28. package/dist/index.d.ts +21 -4
  29. package/dist/index.js +2 -0
  30. package/dist/index.js.map +1 -1
  31. package/dist/index.mjs +1 -0
  32. package/dist/index.mjs.map +1 -1
  33. package/dist/primitives/Composer/index.js +4 -9
  34. package/dist/primitives/Composer/index.js.map +1 -1
  35. package/dist/primitives/Composer/index.mjs +2 -7
  36. package/dist/primitives/Composer/index.mjs.map +1 -1
  37. package/dist/shared.js +79 -6
  38. package/dist/shared.js.map +1 -1
  39. package/dist/shared.mjs +81 -9
  40. package/dist/shared.mjs.map +1 -1
  41. package/dist/version.js +1 -1
  42. package/dist/version.js.map +1 -1
  43. package/dist/version.mjs +1 -1
  44. package/dist/version.mjs.map +1 -1
  45. package/package.json +4 -4
package/dist/shared.js CHANGED
@@ -2,14 +2,86 @@
2
2
 
3
3
  var core = require('@liveblocks/core');
4
4
  var react = require('@liveblocks/react');
5
+ var React = require('react');
5
6
 
7
+ const MENTION_SUGGESTIONS_DEBOUNCE = 500;
8
+ const _cachesByClient = /* @__PURE__ */ new WeakMap();
9
+ function getMentionSuggestionsCacheForClient(client) {
10
+ let cache = _cachesByClient.get(client);
11
+ if (!cache) {
12
+ cache = /* @__PURE__ */ new Map();
13
+ _cachesByClient.set(client, cache);
14
+ }
15
+ return cache;
16
+ }
17
+ function useMentionSuggestions(search) {
18
+ const client = react.useClient();
19
+ const mentionSuggestionsCache = getMentionSuggestionsCacheForClient(client);
20
+ const room = react.useRoom();
21
+ const [mentionSuggestions, setMentionSuggestions] = React.useState();
22
+ const lastInvokedAt = React.useRef();
23
+ React.useEffect(() => {
24
+ const resolveMentionSuggestions = client[core.kInternal].resolveMentionSuggestions;
25
+ if (search === void 0 || !resolveMentionSuggestions) {
26
+ return;
27
+ }
28
+ const resolveMentionSuggestionsArgs = { text: search, roomId: room.id };
29
+ const mentionSuggestionsCacheKey = core.stringify(resolveMentionSuggestionsArgs);
30
+ let debounceTimeout;
31
+ let isCanceled = false;
32
+ const getMentionSuggestions = async () => {
33
+ try {
34
+ lastInvokedAt.current = performance.now();
35
+ const mentionSuggestions2 = await resolveMentionSuggestions(
36
+ resolveMentionSuggestionsArgs
37
+ );
38
+ if (!isCanceled) {
39
+ setMentionSuggestions(mentionSuggestions2);
40
+ mentionSuggestionsCache.set(
41
+ mentionSuggestionsCacheKey,
42
+ mentionSuggestions2
43
+ );
44
+ }
45
+ } catch (error) {
46
+ console.error(error?.message);
47
+ }
48
+ };
49
+ if (mentionSuggestionsCache.has(mentionSuggestionsCacheKey)) {
50
+ setMentionSuggestions(
51
+ mentionSuggestionsCache.get(mentionSuggestionsCacheKey)
52
+ );
53
+ } else if (!lastInvokedAt.current || Math.abs(performance.now() - lastInvokedAt.current) > MENTION_SUGGESTIONS_DEBOUNCE) {
54
+ void getMentionSuggestions();
55
+ } else {
56
+ debounceTimeout = window.setTimeout(() => {
57
+ void getMentionSuggestions();
58
+ }, MENTION_SUGGESTIONS_DEBOUNCE);
59
+ }
60
+ return () => {
61
+ isCanceled = true;
62
+ window.clearTimeout(debounceTimeout);
63
+ };
64
+ }, [room.id, search]);
65
+ return mentionSuggestions;
66
+ }
67
+ function useCurrentUserIdFromRoom() {
68
+ return react.useSelf((user) => typeof user.id === "string" ? user.id : null);
69
+ }
70
+ function useCurrentUserIdFromClient_withClient(client) {
71
+ const currentUserIdStore = client[core.kInternal].currentUserIdStore;
72
+ return React.useSyncExternalStore(
73
+ currentUserIdStore.subscribe,
74
+ currentUserIdStore.get,
75
+ currentUserIdStore.get
76
+ );
77
+ }
6
78
  function useCurrentUserId() {
7
- const roomContextBundle = react.useRoomContextBundleOrNull__();
8
- const liveblocksContextBundle = react.useLiveblocksContextBundleOrNull__();
9
- if (roomContextBundle !== null) {
10
- return roomContextBundle[core.kInternal].useCurrentUserIdFromRoom();
11
- } else if (liveblocksContextBundle !== null) {
12
- return liveblocksContextBundle[core.kInternal].useCurrentUserIdFromClient();
79
+ const client = React.useContext(react.ClientContext);
80
+ const room = React.useContext(react.RoomContext);
81
+ if (room !== null) {
82
+ return useCurrentUserIdFromRoom();
83
+ } else if (client !== null) {
84
+ return useCurrentUserIdFromClient_withClient(client);
13
85
  } else {
14
86
  core.raise(
15
87
  "LiveblocksProvider or RoomProvider are missing from the React tree."
@@ -18,4 +90,5 @@ function useCurrentUserId() {
18
90
  }
19
91
 
20
92
  exports.useCurrentUserId = useCurrentUserId;
93
+ exports.useMentionSuggestions = useMentionSuggestions;
21
94
  //# sourceMappingURL=shared.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"shared.js","sources":["../src/shared.ts"],"sourcesContent":["import { kInternal, raise } from \"@liveblocks/core\";\nimport {\n useLiveblocksContextBundleOrNull__,\n useRoomContextBundleOrNull__,\n} from \"@liveblocks/react\";\n\nexport function useCurrentUserId(): string | null {\n const roomContextBundle = useRoomContextBundleOrNull__();\n const liveblocksContextBundle = useLiveblocksContextBundleOrNull__();\n\n if (roomContextBundle !== null) {\n return roomContextBundle[kInternal].useCurrentUserIdFromRoom();\n } else if (liveblocksContextBundle !== null) {\n return liveblocksContextBundle[kInternal].useCurrentUserIdFromClient();\n } else {\n raise(\n \"LiveblocksProvider or RoomProvider are missing from the React tree.\"\n );\n }\n}\n"],"names":["useRoomContextBundleOrNull__","useLiveblocksContextBundleOrNull__","kInternal","raise"],"mappings":";;;;;AAMO,SAAS,gBAAkC,GAAA;AAChD,EAAA,MAAM,oBAAoBA,kCAA6B,EAAA,CAAA;AACvD,EAAA,MAAM,0BAA0BC,wCAAmC,EAAA,CAAA;AAEnE,EAAA,IAAI,sBAAsB,IAAM,EAAA;AAC9B,IAAO,OAAA,iBAAA,CAAkBC,gBAAW,wBAAyB,EAAA,CAAA;AAAA,GAC/D,MAAA,IAAW,4BAA4B,IAAM,EAAA;AAC3C,IAAO,OAAA,uBAAA,CAAwBA,gBAAW,0BAA2B,EAAA,CAAA;AAAA,GAChE,MAAA;AACL,IAAAC,UAAA;AAAA,MACE,qEAAA;AAAA,KACF,CAAA;AAAA,GACF;AACF;;;;"}
1
+ {"version":3,"file":"shared.js","sources":["../src/shared.ts"],"sourcesContent":["import type { OpaqueClient } from \"@liveblocks/core\";\nimport { kInternal, raise, stringify } from \"@liveblocks/core\";\nimport {\n ClientContext,\n RoomContext,\n useClient,\n useRoom,\n useSelf,\n} from \"@liveblocks/react\";\nimport React, { useContext, useSyncExternalStore } from \"react\";\n\nconst MENTION_SUGGESTIONS_DEBOUNCE = 500;\n\nconst _cachesByClient = new WeakMap<OpaqueClient, Map<string, string[]>>();\n\nfunction getMentionSuggestionsCacheForClient(client: OpaqueClient) {\n let cache = _cachesByClient.get(client);\n if (!cache) {\n cache = new Map();\n _cachesByClient.set(client, cache);\n }\n return cache;\n}\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 const mentionSuggestionsCache = getMentionSuggestionsCacheForClient(client);\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 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 }, [room.id, search]);\n\n return mentionSuggestions;\n}\n\nfunction useCurrentUserIdFromRoom() {\n return useSelf((user) => (typeof user.id === \"string\" ? user.id : null));\n}\n\nfunction useCurrentUserIdFromClient_withClient(client: OpaqueClient) {\n const currentUserIdStore = client[kInternal].currentUserIdStore;\n return useSyncExternalStore(\n currentUserIdStore.subscribe,\n currentUserIdStore.get,\n currentUserIdStore.get\n );\n}\n\nexport function useCurrentUserId(): string | null {\n const client = useContext(ClientContext);\n const room = useContext(RoomContext);\n if (room !== null) {\n return useCurrentUserIdFromRoom();\n } else if (client !== null) {\n return useCurrentUserIdFromClient_withClient(client);\n } else {\n raise(\n \"LiveblocksProvider or RoomProvider are missing from the React tree.\"\n );\n }\n}\n"],"names":["useClient","useRoom","kInternal","stringify","mentionSuggestions","useSelf","useSyncExternalStore","useContext","ClientContext","RoomContext","raise"],"mappings":";;;;;;AAWA,MAAM,4BAA+B,GAAA,GAAA,CAAA;AAErC,MAAM,eAAA,uBAAsB,OAA6C,EAAA,CAAA;AAEzE,SAAS,oCAAoC,MAAsB,EAAA;AACjE,EAAI,IAAA,KAAA,GAAQ,eAAgB,CAAA,GAAA,CAAI,MAAM,CAAA,CAAA;AACtC,EAAA,IAAI,CAAC,KAAO,EAAA;AACV,IAAA,KAAA,uBAAY,GAAI,EAAA,CAAA;AAChB,IAAgB,eAAA,CAAA,GAAA,CAAI,QAAQ,KAAK,CAAA,CAAA;AAAA,GACnC;AACA,EAAO,OAAA,KAAA,CAAA;AACT,CAAA;AAQO,SAAS,sBAAsB,MAAiB,EAAA;AACrD,EAAA,MAAM,SAASA,eAAU,EAAA,CAAA;AACzB,EAAM,MAAA,uBAAA,GAA0B,oCAAoC,MAAM,CAAA,CAAA;AAE1E,EAAA,MAAM,OAAOC,aAAQ,EAAA,CAAA;AACrB,EAAA,MAAM,CAAC,kBAAA,EAAoB,qBAAqB,CAAA,GAC9C,M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GAC9C,MAAA;AACL,IAAAC,UAAA;AAAA,MACE,qEAAA;AAAA,KACF,CAAA;AAAA,GACF;AACF;;;;;"}
package/dist/shared.mjs CHANGED
@@ -1,13 +1,85 @@
1
- import { kInternal, raise } from '@liveblocks/core';
2
- import { useRoomContextBundleOrNull__, useLiveblocksContextBundleOrNull__ } from '@liveblocks/react';
1
+ import { kInternal, stringify, raise } from '@liveblocks/core';
2
+ import { useClient, useRoom, ClientContext, RoomContext, useSelf } from '@liveblocks/react';
3
+ import React__default, { useContext, useSyncExternalStore } from 'react';
3
4
 
5
+ const MENTION_SUGGESTIONS_DEBOUNCE = 500;
6
+ const _cachesByClient = /* @__PURE__ */ new WeakMap();
7
+ function getMentionSuggestionsCacheForClient(client) {
8
+ let cache = _cachesByClient.get(client);
9
+ if (!cache) {
10
+ cache = /* @__PURE__ */ new Map();
11
+ _cachesByClient.set(client, cache);
12
+ }
13
+ return cache;
14
+ }
15
+ function useMentionSuggestions(search) {
16
+ const client = useClient();
17
+ const mentionSuggestionsCache = getMentionSuggestionsCacheForClient(client);
18
+ const room = useRoom();
19
+ const [mentionSuggestions, setMentionSuggestions] = React__default.useState();
20
+ const lastInvokedAt = React__default.useRef();
21
+ React__default.useEffect(() => {
22
+ const resolveMentionSuggestions = client[kInternal].resolveMentionSuggestions;
23
+ if (search === void 0 || !resolveMentionSuggestions) {
24
+ return;
25
+ }
26
+ const resolveMentionSuggestionsArgs = { text: search, roomId: room.id };
27
+ const mentionSuggestionsCacheKey = stringify(resolveMentionSuggestionsArgs);
28
+ let debounceTimeout;
29
+ let isCanceled = false;
30
+ const getMentionSuggestions = async () => {
31
+ try {
32
+ lastInvokedAt.current = performance.now();
33
+ const mentionSuggestions2 = await resolveMentionSuggestions(
34
+ resolveMentionSuggestionsArgs
35
+ );
36
+ if (!isCanceled) {
37
+ setMentionSuggestions(mentionSuggestions2);
38
+ mentionSuggestionsCache.set(
39
+ mentionSuggestionsCacheKey,
40
+ mentionSuggestions2
41
+ );
42
+ }
43
+ } catch (error) {
44
+ console.error(error?.message);
45
+ }
46
+ };
47
+ if (mentionSuggestionsCache.has(mentionSuggestionsCacheKey)) {
48
+ setMentionSuggestions(
49
+ mentionSuggestionsCache.get(mentionSuggestionsCacheKey)
50
+ );
51
+ } else if (!lastInvokedAt.current || Math.abs(performance.now() - lastInvokedAt.current) > MENTION_SUGGESTIONS_DEBOUNCE) {
52
+ void getMentionSuggestions();
53
+ } else {
54
+ debounceTimeout = window.setTimeout(() => {
55
+ void getMentionSuggestions();
56
+ }, MENTION_SUGGESTIONS_DEBOUNCE);
57
+ }
58
+ return () => {
59
+ isCanceled = true;
60
+ window.clearTimeout(debounceTimeout);
61
+ };
62
+ }, [room.id, search]);
63
+ return mentionSuggestions;
64
+ }
65
+ function useCurrentUserIdFromRoom() {
66
+ return useSelf((user) => typeof user.id === "string" ? user.id : null);
67
+ }
68
+ function useCurrentUserIdFromClient_withClient(client) {
69
+ const currentUserIdStore = client[kInternal].currentUserIdStore;
70
+ return useSyncExternalStore(
71
+ currentUserIdStore.subscribe,
72
+ currentUserIdStore.get,
73
+ currentUserIdStore.get
74
+ );
75
+ }
4
76
  function useCurrentUserId() {
5
- const roomContextBundle = useRoomContextBundleOrNull__();
6
- const liveblocksContextBundle = useLiveblocksContextBundleOrNull__();
7
- if (roomContextBundle !== null) {
8
- return roomContextBundle[kInternal].useCurrentUserIdFromRoom();
9
- } else if (liveblocksContextBundle !== null) {
10
- return liveblocksContextBundle[kInternal].useCurrentUserIdFromClient();
77
+ const client = useContext(ClientContext);
78
+ const room = useContext(RoomContext);
79
+ if (room !== null) {
80
+ return useCurrentUserIdFromRoom();
81
+ } else if (client !== null) {
82
+ return useCurrentUserIdFromClient_withClient(client);
11
83
  } else {
12
84
  raise(
13
85
  "LiveblocksProvider or RoomProvider are missing from the React tree."
@@ -15,5 +87,5 @@ function useCurrentUserId() {
15
87
  }
16
88
  }
17
89
 
18
- export { useCurrentUserId };
90
+ export { useCurrentUserId, useMentionSuggestions };
19
91
  //# sourceMappingURL=shared.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"shared.mjs","sources":["../src/shared.ts"],"sourcesContent":["import { kInternal, raise } from \"@liveblocks/core\";\nimport {\n useLiveblocksContextBundleOrNull__,\n useRoomContextBundleOrNull__,\n} from \"@liveblocks/react\";\n\nexport function useCurrentUserId(): string | null {\n const roomContextBundle = useRoomContextBundleOrNull__();\n const liveblocksContextBundle = useLiveblocksContextBundleOrNull__();\n\n if (roomContextBundle !== null) {\n return roomContextBundle[kInternal].useCurrentUserIdFromRoom();\n } else if (liveblocksContextBundle !== null) {\n return liveblocksContextBundle[kInternal].useCurrentUserIdFromClient();\n } else {\n raise(\n \"LiveblocksProvider or RoomProvider are missing from the React tree.\"\n );\n }\n}\n"],"names":[],"mappings":";;;AAMO,SAAS,gBAAkC,GAAA;AAChD,EAAA,MAAM,oBAAoB,4BAA6B,EAAA,CAAA;AACvD,EAAA,MAAM,0BAA0B,kCAAmC,EAAA,CAAA;AAEnE,EAAA,IAAI,sBAAsB,IAAM,EAAA;AAC9B,IAAO,OAAA,iBAAA,CAAkB,WAAW,wBAAyB,EAAA,CAAA;AAAA,GAC/D,MAAA,IAAW,4BAA4B,IAAM,EAAA;AAC3C,IAAO,OAAA,uBAAA,CAAwB,WAAW,0BAA2B,EAAA,CAAA;AAAA,GAChE,MAAA;AACL,IAAA,KAAA;AAAA,MACE,qEAAA;AAAA,KACF,CAAA;AAAA,GACF;AACF;;;;"}
1
+ {"version":3,"file":"shared.mjs","sources":["../src/shared.ts"],"sourcesContent":["import type { OpaqueClient } from \"@liveblocks/core\";\nimport { kInternal, raise, stringify } from \"@liveblocks/core\";\nimport {\n ClientContext,\n RoomContext,\n useClient,\n useRoom,\n useSelf,\n} from \"@liveblocks/react\";\nimport React, { useContext, useSyncExternalStore } from \"react\";\n\nconst MENTION_SUGGESTIONS_DEBOUNCE = 500;\n\nconst _cachesByClient = new WeakMap<OpaqueClient, Map<string, string[]>>();\n\nfunction getMentionSuggestionsCacheForClient(client: OpaqueClient) {\n let cache = _cachesByClient.get(client);\n if (!cache) {\n cache = new Map();\n _cachesByClient.set(client, cache);\n }\n return cache;\n}\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 const mentionSuggestionsCache = getMentionSuggestionsCacheForClient(client);\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 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 }, [room.id, search]);\n\n return mentionSuggestions;\n}\n\nfunction useCurrentUserIdFromRoom() {\n return useSelf((user) => (typeof user.id === \"string\" ? user.id : null));\n}\n\nfunction useCurrentUserIdFromClient_withClient(client: OpaqueClient) {\n const currentUserIdStore = client[kInternal].currentUserIdStore;\n return useSyncExternalStore(\n currentUserIdStore.subscribe,\n currentUserIdStore.get,\n currentUserIdStore.get\n );\n}\n\nexport function useCurrentUserId(): string | null {\n const client = useContext(ClientContext);\n const room = useContext(RoomContext);\n if (room !== null) {\n return useCurrentUserIdFromRoom();\n } else if (client !== null) {\n return useCurrentUserIdFromClient_withClient(client);\n } else {\n raise(\n \"LiveblocksProvider or RoomProvider are missing from the React tree.\"\n );\n }\n}\n"],"names":["React","mentionSuggestions"],"mappings":";;;;AAWA,MAAM,4BAA+B,GAAA,GAAA,CAAA;AAErC,MAAM,eAAA,uBAAsB,OAA6C,EAAA,CAAA;AAEzE,SAAS,oCAAoC,MAAsB,EAAA;AACjE,EAAI,IAAA,KAAA,GAAQ,eAAgB,CAAA,GAAA,CAAI,MAAM,CAAA,CAAA;AACtC,EAAA,IAAI,CAAC,KAAO,EAAA;AACV,IAAA,KAAA,uBAAY,GAAI,EAAA,CAAA;AAChB,IAAgB,eAAA,CAAA,GAAA,CAAI,QAAQ,KAAK,CAAA,CAAA;AAAA,GACnC;AACA,EAAO,OAAA,KAAA,CAAA;AACT,CAAA;AAQO,SAAS,sBAAsB,MAAiB,EAAA;AACrD,EAAA,MAAM,SAAS,SAAU,EAAA,CAAA;AACzB,EAAM,MAAA,uBAAA,GAA0B,oCAAoC,MAAM,CAAA,CAAA;AAE1E,EAAA,MAAM,OAAO,OAAQ,EAAA,CAAA;AACrB,EAAA,MAAM,CAAC,kBAAA,EAAoB,qBAAqB,CAAA,GAC9CA,eAAM,QAAmB,EAAA,CAAA;AAC3B,EAAM,MAAA,aAAA,GAAgBA,eAAM,MAAe,EAA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}
package/dist/version.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const PKG_NAME = "@liveblocks/react-ui";
4
- const PKG_VERSION = "1.12.0";
4
+ const PKG_VERSION = "2.0.0-alpha1";
5
5
  const PKG_FORMAT = "cjs";
6
6
 
7
7
  exports.PKG_FORMAT = PKG_FORMAT;
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sources":["../src/version.ts"],"sourcesContent":["declare const __VERSION__: string;\ndeclare const TSUP_FORMAT: string;\n\nexport const PKG_NAME = \"@liveblocks/react-ui\";\nexport const PKG_VERSION = typeof __VERSION__ === \"string\" && __VERSION__;\nexport const PKG_FORMAT = typeof TSUP_FORMAT === \"string\" && TSUP_FORMAT;\n"],"names":[],"mappings":";;AAGO,MAAM,QAAW,GAAA,uBAAA;AACX,MAAA,WAAA,GAAiD,SAAA;AACjD,MAAA,UAAA,GAAgD;;;;;;"}
1
+ {"version":3,"file":"version.js","sources":["../src/version.ts"],"sourcesContent":["declare const __VERSION__: string;\ndeclare const TSUP_FORMAT: string;\n\nexport const PKG_NAME = \"@liveblocks/react-ui\";\nexport const PKG_VERSION = typeof __VERSION__ === \"string\" && __VERSION__;\nexport const PKG_FORMAT = typeof TSUP_FORMAT === \"string\" && TSUP_FORMAT;\n"],"names":[],"mappings":";;AAGO,MAAM,QAAW,GAAA,uBAAA;AACX,MAAA,WAAA,GAAiD,eAAA;AACjD,MAAA,UAAA,GAAgD;;;;;;"}
package/dist/version.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  const PKG_NAME = "@liveblocks/react-ui";
2
- const PKG_VERSION = "1.12.0";
2
+ const PKG_VERSION = "2.0.0-alpha1";
3
3
  const PKG_FORMAT = "esm";
4
4
 
5
5
  export { PKG_FORMAT, PKG_NAME, PKG_VERSION };
@@ -1 +1 @@
1
- {"version":3,"file":"version.mjs","sources":["../src/version.ts"],"sourcesContent":["declare const __VERSION__: string;\ndeclare const TSUP_FORMAT: string;\n\nexport const PKG_NAME = \"@liveblocks/react-ui\";\nexport const PKG_VERSION = typeof __VERSION__ === \"string\" && __VERSION__;\nexport const PKG_FORMAT = typeof TSUP_FORMAT === \"string\" && TSUP_FORMAT;\n"],"names":[],"mappings":"AAGO,MAAM,QAAW,GAAA,uBAAA;AACX,MAAA,WAAA,GAAiD,SAAA;AACjD,MAAA,UAAA,GAAgD;;;;"}
1
+ {"version":3,"file":"version.mjs","sources":["../src/version.ts"],"sourcesContent":["declare const __VERSION__: string;\ndeclare const TSUP_FORMAT: string;\n\nexport const PKG_NAME = \"@liveblocks/react-ui\";\nexport const PKG_VERSION = typeof __VERSION__ === \"string\" && __VERSION__;\nexport const PKG_FORMAT = typeof TSUP_FORMAT === \"string\" && TSUP_FORMAT;\n"],"names":[],"mappings":"AAGO,MAAM,QAAW,GAAA,uBAAA;AACX,MAAA,WAAA,GAAiD,eAAA;AACjD,MAAA,UAAA,GAAgD;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liveblocks/react-ui",
3
- "version": "1.12.0-initial1",
3
+ "version": "2.0.0-alpha1",
4
4
  "description": "A set of React pre-built components for the Liveblocks products. Liveblocks is the all-in-one toolkit to build collaborative products like Figma, Notion, and more.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "commonjs",
@@ -62,9 +62,9 @@
62
62
  },
63
63
  "dependencies": {
64
64
  "@floating-ui/react-dom": "^2.0.8",
65
- "@liveblocks/client": "1.12.0",
66
- "@liveblocks/core": "1.12.0",
67
- "@liveblocks/react": "1.12.0",
65
+ "@liveblocks/client": "2.0.0-alpha1",
66
+ "@liveblocks/core": "2.0.0-alpha1",
67
+ "@liveblocks/react": "2.0.0-alpha1",
68
68
  "@radix-ui/react-dropdown-menu": "^2.0.6",
69
69
  "@radix-ui/react-popover": "^1.0.7",
70
70
  "@radix-ui/react-slot": "^1.0.2",