@liveblocks/react-ui 2.0.4 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  </a>
8
8
  </p>
9
9
 
10
- # `@liveblocks/react-comments`
10
+ # `@liveblocks/react-ui`
11
11
 
12
12
  <p>
13
13
  <a href="https://npmjs.org/package/@liveblocks/react-ui">
package/dist/shared.js CHANGED
@@ -3,6 +3,7 @@
3
3
  var core = require('@liveblocks/core');
4
4
  var react = require('@liveblocks/react');
5
5
  var React = require('react');
6
+ var index_js = require('use-sync-external-store/shim/index.js');
6
7
 
7
8
  const MENTION_SUGGESTIONS_DEBOUNCE = 500;
8
9
  const _cachesByClient = /* @__PURE__ */ new WeakMap();
@@ -69,7 +70,7 @@ function useCurrentUserIdFromRoom() {
69
70
  }
70
71
  function useCurrentUserIdFromClient_withClient(client) {
71
72
  const currentUserIdStore = client[core.kInternal].currentUserIdStore;
72
- return React.useSyncExternalStore(
73
+ return index_js.useSyncExternalStore(
73
74
  currentUserIdStore.subscribe,
74
75
  currentUserIdStore.get,
75
76
  currentUserIdStore.get
@@ -1 +1 @@
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\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 mentionSuggestionsCache = getMentionSuggestionsCacheForClient(client);\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\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\n // NOTE: These hooks are called conditionally, but in a way that will not\n // take different code paths between re-renders, so we can ignore the\n // rules-of-hooks lint warning here.\n /* eslint-disable react-hooks/rules-of-hooks */\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 /* eslint-enable react-hooks/rules-of-hooks */\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;AAEzB,EAAA,MAAM,OAAOC,aAAQ,EAAA,CAAA;AACrB,EAAA,MAAM,CAAC,kBAAA,EAAoB,qBAAqB,CAAA,GAC9C,MAAM,QAAmB,EAAA,CAAA;AAC3B,EAAM,MAAA,aAAA,GAAgB,MAAM,MAAe,EAAA,CAAA;AAE3C,EAAA,KAAA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;AAAA,MACE,qEAAA;AAAA,KACF,CAAA;AAAA,GACF;AAEF;;;;;"}
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 } from \"react\";\nimport { useSyncExternalStore } from \"use-sync-external-store/shim/index.js\";\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\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 mentionSuggestionsCache = getMentionSuggestionsCacheForClient(client);\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\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\n // NOTE: These hooks are called conditionally, but in a way that will not\n // take different code paths between re-renders, so we can ignore the\n // rules-of-hooks lint warning here.\n /* eslint-disable react-hooks/rules-of-hooks */\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 /* eslint-enable react-hooks/rules-of-hooks */\n}\n"],"names":["useClient","useRoom","kInternal","stringify","mentionSuggestions","useSelf","useSyncExternalStore","useContext","ClientContext","RoomContext","raise"],"mappings":";;;;;;;AAYA,MAAM,4BAA+B,GAAA,GAAA,CAAA;AAErC,MAAM,eAAA,uBAAsB,OAA6C,EAAA,CAAA;AAEz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AAsB,EAAA;AACnE,EAAM,MAAA,kBAAA,GAAqB,OAAOH,cAAW,CAAA,CAAA,kBAAA,CAAA;AAC7C,EAAO,OAAAI,6BAAA;AAAA,IACL,kBAAmB,CAAA,SAAA;AAAA,IACnB,kBAAmB,CAAA,GAAA;AAAA,IACnB,kBAAmB,CAAA,GAAA;AAAA,GACrB,CAAA;AACF,CAAA;AAEO,SAAS,gBAAkC,GAAA;AAChD,EAAM,MAAA,MAAA,GAASC,iBAAWC,mBAAa,CAAA,CAAA;AACvC,EAAM,MAAA,IAAA,GAAOD,iBAAWE,iBAAW,CAAA,CAAA;AAMnC,EAAA,IAAI,SAAS,IAAM,EAAA;AACjB,IAAA,OAAO,wBAAyB,EAAA,CAAA;AAAA,GAClC,MAAA,IAAW,WAAW,IAAM,EAAA;AAC1B,IAAA,OAAO,sCAAsC,MAAM,CAAA,CAAA;AAAA,GAC9C,MAAA;AACL,IAAAC,UAAA;AAAA,MACE,qEAAA;AAAA,KACF,CAAA;AAAA,GACF;AAEF;;;;;"}
package/dist/shared.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import { kInternal, stringify, raise } from '@liveblocks/core';
2
2
  import { useClient, useRoom, ClientContext, RoomContext, useSelf } from '@liveblocks/react';
3
- import React__default, { useContext, useSyncExternalStore } from 'react';
3
+ import React__default, { useContext } from 'react';
4
+ import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';
4
5
 
5
6
  const MENTION_SUGGESTIONS_DEBOUNCE = 500;
6
7
  const _cachesByClient = /* @__PURE__ */ new WeakMap();
@@ -1 +1 @@
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\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 mentionSuggestionsCache = getMentionSuggestionsCacheForClient(client);\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\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\n // NOTE: These hooks are called conditionally, but in a way that will not\n // take different code paths between re-renders, so we can ignore the\n // rules-of-hooks lint warning here.\n /* eslint-disable react-hooks/rules-of-hooks */\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 /* eslint-enable react-hooks/rules-of-hooks */\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;AAEzB,EAAA,MAAM,OAAO,OAAQ,EAAA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IAAA,OAAO,wBAAyB,EAAA,CAAA;AAAA,GAClC,MAAA,IAAW,WAAW,IAAM,EAAA;AAC1B,IAAA,OAAO,sCAAsC,MAAM,CAAA,CAAA;AAAA,GAC9C,MAAA;AACL,IAAA,KAAA;AAAA,MACE,qEAAA;AAAA,KACF,CAAA;AAAA,GACF;AAEF;;;;"}
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 } from \"react\";\nimport { useSyncExternalStore } from \"use-sync-external-store/shim/index.js\";\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\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 mentionSuggestionsCache = getMentionSuggestionsCacheForClient(client);\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\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\n // NOTE: These hooks are called conditionally, but in a way that will not\n // take different code paths between re-renders, so we can ignore the\n // rules-of-hooks lint warning here.\n /* eslint-disable react-hooks/rules-of-hooks */\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 /* eslint-enable react-hooks/rules-of-hooks */\n}\n"],"names":["React","mentionSuggestions"],"mappings":";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AAA,QAAA,GAAW,IAAK,CAAA,EAAA,GAAK,IAAK,CAAA,CAAA;AACzE,CAAA;AAEA,SAAS,sCAAsC,MAAsB,EAAA;AACnE,EAAM,MAAA,kBAAA,GAAqB,OAAO,SAAW,CAAA,CAAA,kBAAA,CAAA;AAC7C,EAAO,OAAA,oBAAA;AAAA,IACL,kBAAmB,CAAA,SAAA;AAAA,IACnB,kBAAmB,CAAA,GAAA;AAAA,IACnB,kBAAmB,CAAA,GAAA;AAAA,GACrB,CAAA;AACF,CAAA;AAEO,SAAS,gBAAkC,GAAA;AAChD,EAAM,MAAA,MAAA,GAAS,WAAW,aAAa,CAAA,CAAA;AACvC,EAAM,MAAA,IAAA,GAAO,WAAW,WAAW,CAAA,CAAA;AAMnC,EAAA,IAAI,SAAS,IAAM,EAAA;AACjB,IAAA,OAAO,wBAAyB,EAAA,CAAA;AAAA,GAClC,MAAA,IAAW,WAAW,IAAM,EAAA;AAC1B,IAAA,OAAO,sCAAsC,MAAM,CAAA,CAAA;AAAA,GAC9C,MAAA;AACL,IAAA,KAAA;AAAA,MACE,qEAAA;AAAA,KACF,CAAA;AAAA,GACF;AAEF;;;;"}
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 = "2.0.4";
4
+ const PKG_VERSION = "2.1.0";
5
5
  const PKG_FORMAT = "cjs";
6
6
 
7
7
  exports.PKG_FORMAT = PKG_FORMAT;
package/dist/version.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  const PKG_NAME = "@liveblocks/react-ui";
2
- const PKG_VERSION = "2.0.4";
2
+ const PKG_VERSION = "2.1.0";
3
3
  const PKG_FORMAT = "esm";
4
4
 
5
5
  export { PKG_FORMAT, PKG_NAME, PKG_VERSION };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liveblocks/react-ui",
3
- "version": "2.0.4",
3
+ "version": "2.1.0",
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",
@@ -63,9 +63,9 @@
63
63
  },
64
64
  "dependencies": {
65
65
  "@floating-ui/react-dom": "^2.0.8",
66
- "@liveblocks/client": "2.0.4",
67
- "@liveblocks/core": "2.0.4",
68
- "@liveblocks/react": "2.0.4",
66
+ "@liveblocks/client": "2.1.0",
67
+ "@liveblocks/core": "2.1.0",
68
+ "@liveblocks/react": "2.1.0",
69
69
  "@radix-ui/react-dropdown-menu": "^2.0.6",
70
70
  "@radix-ui/react-popover": "^1.0.7",
71
71
  "@radix-ui/react-slot": "^1.0.2",