@liveblocks/react 3.16.0 → 3.17.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/dist/_private.cjs +13 -7
- package/dist/_private.cjs.map +1 -1
- package/dist/_private.d.cts +11 -3
- package/dist/_private.d.ts +11 -3
- package/dist/_private.js +7 -1
- package/dist/_private.js.map +1 -1
- package/dist/{chunk-EEXHY3OA.js → chunk-D3G7BVLV.js} +31 -22
- package/dist/chunk-D3G7BVLV.js.map +1 -0
- package/dist/{chunk-VSO26OCO.cjs → chunk-IVZ4Z5VE.cjs} +2 -2
- package/dist/{chunk-VSO26OCO.cjs.map → chunk-IVZ4Z5VE.cjs.map} +1 -1
- package/dist/{chunk-A7EFQVZ3.js → chunk-LG2KVNGB.js} +2 -2
- package/dist/{chunk-HFTIBRCD.cjs → chunk-RQSGIWTN.cjs} +30 -21
- package/dist/chunk-RQSGIWTN.cjs.map +1 -0
- package/dist/index.cjs +4 -4
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/{room-kE9R5ats.d.cts → room-C6NTdu0X.d.cts} +9 -1
- package/dist/{room-kE9R5ats.d.ts → room-C6NTdu0X.d.ts} +9 -1
- package/dist/suspense.cjs +4 -4
- package/dist/suspense.d.cts +1 -1
- package/dist/suspense.d.ts +1 -1
- package/dist/suspense.js +2 -2
- package/package.json +3 -3
- package/dist/chunk-EEXHY3OA.js.map +0 -1
- package/dist/chunk-HFTIBRCD.cjs.map +0 -1
- /package/dist/{chunk-A7EFQVZ3.js.map → chunk-LG2KVNGB.js.map} +0 -0
package/dist/_private.cjs
CHANGED
|
@@ -25,7 +25,10 @@
|
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
var _chunkRQSGIWTNcjs = require('./chunk-RQSGIWTN.cjs');
|
|
29
32
|
|
|
30
33
|
// src/lib/use-layout-effect.ts
|
|
31
34
|
var _react = require('react');
|
|
@@ -50,7 +53,7 @@ function selectorFor_useGroup(state) {
|
|
|
50
53
|
};
|
|
51
54
|
}
|
|
52
55
|
function useGroup(groupId) {
|
|
53
|
-
const client =
|
|
56
|
+
const client = _chunkRQSGIWTNcjs.useClient.call(void 0, );
|
|
54
57
|
const store = client[_core.kInternal].httpClient.groupsStore;
|
|
55
58
|
const getGroupState = _react.useCallback.call(void 0,
|
|
56
59
|
() => store.getItemState(groupId),
|
|
@@ -59,7 +62,7 @@ function useGroup(groupId) {
|
|
|
59
62
|
_react.useEffect.call(void 0, () => {
|
|
60
63
|
void store.enqueue(groupId);
|
|
61
64
|
}, [store, groupId]);
|
|
62
|
-
return
|
|
65
|
+
return _chunkRQSGIWTNcjs.useSyncExternalStoreWithSelector.call(void 0,
|
|
63
66
|
store.subscribe,
|
|
64
67
|
getGroupState,
|
|
65
68
|
getGroupState,
|
|
@@ -80,8 +83,8 @@ function normalizeMentionSuggestions(suggestions) {
|
|
|
80
83
|
function useMentionSuggestions(roomId, search) {
|
|
81
84
|
const [mentionSuggestions, setMentionSuggestions] = _react.useState.call(void 0, );
|
|
82
85
|
const lastInvokedAt = _react.useRef.call(void 0, );
|
|
83
|
-
const resolveMentionSuggestions =
|
|
84
|
-
const mentionSuggestionsCache =
|
|
86
|
+
const resolveMentionSuggestions = _chunkRQSGIWTNcjs.useResolveMentionSuggestions.call(void 0, );
|
|
87
|
+
const mentionSuggestionsCache = _chunkRQSGIWTNcjs.useMentionSuggestionsCache.call(void 0, );
|
|
85
88
|
_react.useEffect.call(void 0, () => {
|
|
86
89
|
if (search === void 0 || !resolveMentionSuggestions) {
|
|
87
90
|
return;
|
|
@@ -136,7 +139,7 @@ function useMentionSuggestions(roomId, search) {
|
|
|
136
139
|
|
|
137
140
|
|
|
138
141
|
function useSyncSource() {
|
|
139
|
-
const client =
|
|
142
|
+
const client = _chunkRQSGIWTNcjs.useClient.call(void 0, );
|
|
140
143
|
const createSyncSource = client[_core.kInternal].createSyncSource;
|
|
141
144
|
const [syncSource, setSyncSource] = _react.useState.call(void 0, );
|
|
142
145
|
_react.useEffect.call(void 0, () => {
|
|
@@ -176,5 +179,8 @@ function useSyncSource() {
|
|
|
176
179
|
|
|
177
180
|
|
|
178
181
|
|
|
179
|
-
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
exports.getUmbrellaStoreForClient = _chunkRQSGIWTNcjs.getUmbrellaStoreForClient; exports.useAddRoomCommentReaction = _chunkRQSGIWTNcjs.useAddRoomCommentReaction; exports.useClientOrNull = _chunkRQSGIWTNcjs.useClientOrNull; exports.useCreateRoomComment = _chunkRQSGIWTNcjs.useCreateRoomComment; exports.useCreateRoomThread = _chunkRQSGIWTNcjs.useCreateRoomThread; exports.useCreateTextMention = _chunkRQSGIWTNcjs.useCreateTextMention; exports.useDeleteRoomComment = _chunkRQSGIWTNcjs.useDeleteRoomComment; exports.useDeleteRoomThread = _chunkRQSGIWTNcjs.useDeleteRoomThread; exports.useDeleteTextMention = _chunkRQSGIWTNcjs.useDeleteTextMention; exports.useEditRoomComment = _chunkRQSGIWTNcjs.useEditRoomComment; exports.useEditRoomThreadMetadata = _chunkRQSGIWTNcjs.useEditRoomThreadMetadata; exports.useGroup = useGroup; exports.useInitial = _chunkRQSGIWTNcjs.useInitial; exports.useLatest = _chunkRQSGIWTNcjs.useLatest; exports.useLayoutEffect = useLayoutEffect; exports.useMarkRoomThreadAsRead = _chunkRQSGIWTNcjs.useMarkRoomThreadAsRead; exports.useMarkRoomThreadAsResolved = _chunkRQSGIWTNcjs.useMarkRoomThreadAsResolved; exports.useMarkRoomThreadAsUnresolved = _chunkRQSGIWTNcjs.useMarkRoomThreadAsUnresolved; exports.useMentionSuggestions = useMentionSuggestions; exports.useMentionSuggestionsCache = _chunkRQSGIWTNcjs.useMentionSuggestionsCache; exports.useRemoveRoomCommentReaction = _chunkRQSGIWTNcjs.useRemoveRoomCommentReaction; exports.useReportTextEditor = _chunkRQSGIWTNcjs.useReportTextEditor; exports.useResolveMentionSuggestions = _chunkRQSGIWTNcjs.useResolveMentionSuggestions; exports.useRoomAttachmentUrl = _chunkRQSGIWTNcjs.useRoomAttachmentUrl; exports.useRoomPermissions = _chunkRQSGIWTNcjs.useRoomPermissions; exports.useRoomThreadSubscription = _chunkRQSGIWTNcjs.useRoomThreadSubscription; exports.useSignal = _chunkRQSGIWTNcjs.useSignal; exports.useSuspendUntilPresenceReady = _chunkRQSGIWTNcjs.useSuspendUntilPresenceReady; exports.useSuspendUntilStorageReady = _chunkRQSGIWTNcjs.useSuspendUntilStorageReady; exports.useSyncExternalStoreWithSelector = _chunkRQSGIWTNcjs.useSyncExternalStoreWithSelector; exports.useSyncSource = useSyncSource; exports.useYjsProvider = _chunkRQSGIWTNcjs.useYjsProvider;
|
|
180
186
|
//# sourceMappingURL=_private.cjs.map
|
package/dist/_private.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/liveblocks/liveblocks/packages/liveblocks-react/dist/_private.cjs","../src/lib/use-layout-effect.ts","../src/use-group.ts","../src/use-mention-suggestions.ts","../src/use-sync-source.ts"],"names":["useEffect","kInternal","useState"],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;AC3BA,8BAAsE;AAI/D,IAAM,gBAAA,EACX,OAAO,OAAA,IAAW,YAAA,EAAc,uBAAA,EAA0B,gBAAA;ADyB5D;AACA;AEjCA;AAGE;AACA;AAAA,wCACK;AACP;AAMA,SAAS,oBAAA,CACP,KAAA,EACkB;AAClB,EAAA,GAAA,CAAI,MAAA,IAAU,KAAA,EAAA,mBAAa,KAAA,2BAAO,WAAA,EAAW;AAC3C,IAAA,wBAAO,KAAA,UAAS,EAAE,SAAA,EAA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AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,s9DAAC","file":"/home/runner/work/liveblocks/liveblocks/packages/liveblocks-react/dist/_private.cjs","sourcesContent":[null,"/* eslint-disable no-restricted-syntax */\n\nimport { useEffect, useLayoutEffect as useOriginalLayoutEffect } from \"react\";\n\n// On React 18.2.0 and earlier, useLayoutEffect triggers a warning when\n// executed on the server, so this workaround should be used instead.\nexport const useLayoutEffect =\n typeof window !== \"undefined\" ? useOriginalLayoutEffect : useEffect;\n","import {\n type AsyncResult,\n type GroupData,\n kInternal,\n shallow,\n} from \"@liveblocks/core\";\nimport { useCallback, useEffect } from \"react\";\n\nimport { useClient } from \"./contexts\";\nimport type { GroupAsyncResult } from \"./types\";\nimport { useSyncExternalStoreWithSelector } from \"./use-sync-external-store-with-selector\";\n\nfunction selectorFor_useGroup(\n state: AsyncResult<GroupData | undefined> | undefined\n): GroupAsyncResult {\n if (state === undefined || state?.isLoading) {\n return state ?? { isLoading: true };\n }\n\n if (state.error) {\n return state;\n }\n\n return {\n isLoading: false,\n group: state.data,\n };\n}\n\n/** @private - Internal API, do not rely on it. */\nexport function useGroup(groupId: string): GroupAsyncResult {\n const client = useClient();\n const store = client[kInternal].httpClient.groupsStore;\n\n const getGroupState = useCallback(\n () => store.getItemState(groupId),\n [store, groupId]\n );\n\n useEffect(() => {\n void store.enqueue(groupId);\n }, [store, groupId]);\n\n return useSyncExternalStoreWithSelector(\n store.subscribe,\n getGroupState,\n getGroupState,\n selectorFor_useGroup,\n shallow\n );\n}\n","import { type MentionData, stableStringify } from \"@liveblocks/core\";\nimport { useEffect, useRef, useState } from \"react\";\n\nimport {\n useMentionSuggestionsCache,\n useResolveMentionSuggestions,\n} from \"./room\";\n\nconst MENTION_SUGGESTIONS_DEBOUNCE = 500;\n\n/**\n * Normalize mention suggestions as `MentionData[]`.\n *\n * Mention suggestions were previously typed as `string[]`, a list of user IDs,\n * but to support multiple mention kinds (user, group, etc), they're now\n * typed as `MentionData[]`.\n */\nfunction normalizeMentionSuggestions<T extends string[] | MentionData[]>(\n suggestions: T\n): MentionData[] {\n return suggestions.map(\n (suggestion): MentionData =>\n typeof suggestion === \"string\"\n ? { kind: \"user\" as const, id: suggestion }\n : suggestion\n );\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(roomId: string, search?: string) {\n const [mentionSuggestions, setMentionSuggestions] = useState<MentionData[]>();\n const lastInvokedAt = useRef<number>();\n\n const resolveMentionSuggestions = useResolveMentionSuggestions();\n const mentionSuggestionsCache = useMentionSuggestionsCache();\n\n useEffect(() => {\n if (search === undefined || !resolveMentionSuggestions) {\n return;\n }\n\n const resolveMentionSuggestionsArgs = { text: search, roomId };\n const mentionSuggestionsCacheKey = stableStringify(\n resolveMentionSuggestionsArgs\n );\n let debounceTimeout: number | undefined;\n let isCanceled = false;\n\n const getMentionSuggestions = async () => {\n try {\n lastInvokedAt.current = performance.now();\n const rawMentionSuggestions = await resolveMentionSuggestions(\n resolveMentionSuggestionsArgs\n );\n\n if (!isCanceled) {\n const normalizedSuggestions = normalizeMentionSuggestions(\n rawMentionSuggestions\n );\n setMentionSuggestions(normalizedSuggestions);\n mentionSuggestionsCache.set(\n mentionSuggestionsCacheKey,\n normalizedSuggestions\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 const cachedSuggestions = mentionSuggestionsCache.get(\n mentionSuggestionsCacheKey\n );\n setMentionSuggestions(cachedSuggestions);\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 }, [search, roomId, resolveMentionSuggestions, mentionSuggestionsCache]);\n\n return mentionSuggestions;\n}\n","import type { SyncSource } from \"@liveblocks/core\";\nimport { kInternal } from \"@liveblocks/core\";\nimport { useEffect, useState } from \"react\";\n\nimport { useClient } from \"./contexts\";\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] = useState<SyncSource | undefined>();\n\n 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"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/liveblocks/liveblocks/packages/liveblocks-react/dist/_private.cjs","../src/lib/use-layout-effect.ts","../src/use-group.ts","../src/use-mention-suggestions.ts","../src/use-sync-source.ts"],"names":["useEffect","kInternal","useState"],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;AC9BA,8BAAsE;AAI/D,IAAM,gBAAA,EACX,OAAO,OAAA,IAAW,YAAA,EAAc,uBAAA,EAA0B,gBAAA;AD4B5D;AACA;AEpCA;AAGE;AACA;AAAA,wCACK;AACP;AAMA,SAAS,oBAAA,CACP,KAAA,EACkB;AAClB,EAAA,GAAA,CAAI,MAAA,IAAU,KAAA,EAAA,mBAAa,KAAA,2BAAO,WAAA,EAA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O,UAAA;AACT;AJiIA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,qrEAAC","file":"/home/runner/work/liveblocks/liveblocks/packages/liveblocks-react/dist/_private.cjs","sourcesContent":[null,"/* eslint-disable no-restricted-syntax */\n\nimport { useEffect, useLayoutEffect as useOriginalLayoutEffect } from \"react\";\n\n// On React 18.2.0 and earlier, useLayoutEffect triggers a warning when\n// executed on the server, so this workaround should be used instead.\nexport const useLayoutEffect =\n typeof window !== \"undefined\" ? useOriginalLayoutEffect : useEffect;\n","import {\n type AsyncResult,\n type GroupData,\n kInternal,\n shallow,\n} from \"@liveblocks/core\";\nimport { useCallback, useEffect } from \"react\";\n\nimport { useClient } from \"./contexts\";\nimport type { GroupAsyncResult } from \"./types\";\nimport { useSyncExternalStoreWithSelector } from \"./use-sync-external-store-with-selector\";\n\nfunction selectorFor_useGroup(\n state: AsyncResult<GroupData | undefined> | undefined\n): GroupAsyncResult {\n if (state === undefined || state?.isLoading) {\n return state ?? { isLoading: true };\n }\n\n if (state.error) {\n return state;\n }\n\n return {\n isLoading: false,\n group: state.data,\n };\n}\n\n/** @private - Internal API, do not rely on it. */\nexport function useGroup(groupId: string): GroupAsyncResult {\n const client = useClient();\n const store = client[kInternal].httpClient.groupsStore;\n\n const getGroupState = useCallback(\n () => store.getItemState(groupId),\n [store, groupId]\n );\n\n useEffect(() => {\n void store.enqueue(groupId);\n }, [store, groupId]);\n\n return useSyncExternalStoreWithSelector(\n store.subscribe,\n getGroupState,\n getGroupState,\n selectorFor_useGroup,\n shallow\n );\n}\n","import { type MentionData, stableStringify } from \"@liveblocks/core\";\nimport { useEffect, useRef, useState } from \"react\";\n\nimport {\n useMentionSuggestionsCache,\n useResolveMentionSuggestions,\n} from \"./room\";\n\nconst MENTION_SUGGESTIONS_DEBOUNCE = 500;\n\n/**\n * Normalize mention suggestions as `MentionData[]`.\n *\n * Mention suggestions were previously typed as `string[]`, a list of user IDs,\n * but to support multiple mention kinds (user, group, etc), they're now\n * typed as `MentionData[]`.\n */\nfunction normalizeMentionSuggestions<T extends string[] | MentionData[]>(\n suggestions: T\n): MentionData[] {\n return suggestions.map(\n (suggestion): MentionData =>\n typeof suggestion === \"string\"\n ? { kind: \"user\" as const, id: suggestion }\n : suggestion\n );\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(roomId: string, search?: string) {\n const [mentionSuggestions, setMentionSuggestions] = useState<MentionData[]>();\n const lastInvokedAt = useRef<number>();\n\n const resolveMentionSuggestions = useResolveMentionSuggestions();\n const mentionSuggestionsCache = useMentionSuggestionsCache();\n\n useEffect(() => {\n if (search === undefined || !resolveMentionSuggestions) {\n return;\n }\n\n const resolveMentionSuggestionsArgs = { text: search, roomId };\n const mentionSuggestionsCacheKey = stableStringify(\n resolveMentionSuggestionsArgs\n );\n let debounceTimeout: number | undefined;\n let isCanceled = false;\n\n const getMentionSuggestions = async () => {\n try {\n lastInvokedAt.current = performance.now();\n const rawMentionSuggestions = await resolveMentionSuggestions(\n resolveMentionSuggestionsArgs\n );\n\n if (!isCanceled) {\n const normalizedSuggestions = normalizeMentionSuggestions(\n rawMentionSuggestions\n );\n setMentionSuggestions(normalizedSuggestions);\n mentionSuggestionsCache.set(\n mentionSuggestionsCacheKey,\n normalizedSuggestions\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 const cachedSuggestions = mentionSuggestionsCache.get(\n mentionSuggestionsCacheKey\n );\n setMentionSuggestions(cachedSuggestions);\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 }, [search, roomId, resolveMentionSuggestions, mentionSuggestionsCache]);\n\n return mentionSuggestions;\n}\n","import type { SyncSource } from \"@liveblocks/core\";\nimport { kInternal } from \"@liveblocks/core\";\nimport { useEffect, useState } from \"react\";\n\nimport { useClient } from \"./contexts\";\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] = useState<SyncSource | undefined>();\n\n 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.d.cts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
import { G as GroupAsyncResult } from './room-
|
|
2
|
-
export { g as getUmbrellaStoreForClient, a as useAddRoomCommentReaction, u as useClientOrNull, b as useCreateRoomComment, c as useCreateRoomThread, d as useCreateTextMention, e as useDeleteRoomComment, f as useDeleteRoomThread, h as useDeleteTextMention, i as useEditRoomComment, j as useEditRoomThreadMetadata, k as useMarkRoomThreadAsRead, l as useMarkRoomThreadAsResolved, m as useMarkRoomThreadAsUnresolved, n as useMentionSuggestionsCache, o as useRemoveRoomCommentReaction, p as useReportTextEditor, q as useResolveMentionSuggestions, r as useRoomAttachmentUrl, s as useRoomPermissions, t as useRoomThreadSubscription, v as useYjsProvider } from './room-
|
|
1
|
+
import { G as GroupAsyncResult } from './room-C6NTdu0X.cjs';
|
|
2
|
+
export { g as getUmbrellaStoreForClient, a as useAddRoomCommentReaction, u as useClientOrNull, b as useCreateRoomComment, c as useCreateRoomThread, d as useCreateTextMention, e as useDeleteRoomComment, f as useDeleteRoomThread, h as useDeleteTextMention, i as useEditRoomComment, j as useEditRoomThreadMetadata, k as useMarkRoomThreadAsRead, l as useMarkRoomThreadAsResolved, m as useMarkRoomThreadAsUnresolved, n as useMentionSuggestionsCache, o as useRemoveRoomCommentReaction, p as useReportTextEditor, q as useResolveMentionSuggestions, r as useRoomAttachmentUrl, s as useRoomPermissions, t as useRoomThreadSubscription, v as useSuspendUntilPresenceReady, w as useSuspendUntilStorageReady, x as useYjsProvider } from './room-C6NTdu0X.cjs';
|
|
3
3
|
import { MutableRefObject, useEffect } from 'react';
|
|
4
4
|
import { MentionData, ISignal, SyncSource } from '@liveblocks/core';
|
|
5
5
|
import '@liveblocks/client';
|
|
6
6
|
import 'react/jsx-runtime';
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* "Freezes" a given value, so that it will return the same value/instance on
|
|
10
|
+
* each subsequent render. This can be used to freeze "initial" values for
|
|
11
|
+
* custom hooks, much like how `useState(initialState)` or
|
|
12
|
+
* `useRef(initialValue)` works.
|
|
13
|
+
*/
|
|
14
|
+
declare function useInitial<T>(value: T, roomId?: string): T;
|
|
15
|
+
|
|
8
16
|
/**
|
|
9
17
|
* Keeps a ref in sync with a given value that may or may not change on
|
|
10
18
|
* every render.
|
|
@@ -38,4 +46,4 @@ declare function useSyncExternalStoreWithSelector<Snapshot, Selection>(subscribe
|
|
|
38
46
|
*/
|
|
39
47
|
declare function useSyncSource(): SyncSource | undefined;
|
|
40
48
|
|
|
41
|
-
export { useGroup, useLatest, useLayoutEffect, useMentionSuggestions, useSignal, useSyncExternalStoreWithSelector, useSyncSource };
|
|
49
|
+
export { useGroup, useInitial, useLatest, useLayoutEffect, useMentionSuggestions, useSignal, useSyncExternalStoreWithSelector, useSyncSource };
|
package/dist/_private.d.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
import { G as GroupAsyncResult } from './room-
|
|
2
|
-
export { g as getUmbrellaStoreForClient, a as useAddRoomCommentReaction, u as useClientOrNull, b as useCreateRoomComment, c as useCreateRoomThread, d as useCreateTextMention, e as useDeleteRoomComment, f as useDeleteRoomThread, h as useDeleteTextMention, i as useEditRoomComment, j as useEditRoomThreadMetadata, k as useMarkRoomThreadAsRead, l as useMarkRoomThreadAsResolved, m as useMarkRoomThreadAsUnresolved, n as useMentionSuggestionsCache, o as useRemoveRoomCommentReaction, p as useReportTextEditor, q as useResolveMentionSuggestions, r as useRoomAttachmentUrl, s as useRoomPermissions, t as useRoomThreadSubscription, v as useYjsProvider } from './room-
|
|
1
|
+
import { G as GroupAsyncResult } from './room-C6NTdu0X.js';
|
|
2
|
+
export { g as getUmbrellaStoreForClient, a as useAddRoomCommentReaction, u as useClientOrNull, b as useCreateRoomComment, c as useCreateRoomThread, d as useCreateTextMention, e as useDeleteRoomComment, f as useDeleteRoomThread, h as useDeleteTextMention, i as useEditRoomComment, j as useEditRoomThreadMetadata, k as useMarkRoomThreadAsRead, l as useMarkRoomThreadAsResolved, m as useMarkRoomThreadAsUnresolved, n as useMentionSuggestionsCache, o as useRemoveRoomCommentReaction, p as useReportTextEditor, q as useResolveMentionSuggestions, r as useRoomAttachmentUrl, s as useRoomPermissions, t as useRoomThreadSubscription, v as useSuspendUntilPresenceReady, w as useSuspendUntilStorageReady, x as useYjsProvider } from './room-C6NTdu0X.js';
|
|
3
3
|
import { MutableRefObject, useEffect } from 'react';
|
|
4
4
|
import { MentionData, ISignal, SyncSource } from '@liveblocks/core';
|
|
5
5
|
import '@liveblocks/client';
|
|
6
6
|
import 'react/jsx-runtime';
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* "Freezes" a given value, so that it will return the same value/instance on
|
|
10
|
+
* each subsequent render. This can be used to freeze "initial" values for
|
|
11
|
+
* custom hooks, much like how `useState(initialState)` or
|
|
12
|
+
* `useRef(initialValue)` works.
|
|
13
|
+
*/
|
|
14
|
+
declare function useInitial<T>(value: T, roomId?: string): T;
|
|
15
|
+
|
|
8
16
|
/**
|
|
9
17
|
* Keeps a ref in sync with a given value that may or may not change on
|
|
10
18
|
* every render.
|
|
@@ -38,4 +46,4 @@ declare function useSyncExternalStoreWithSelector<Snapshot, Selection>(subscribe
|
|
|
38
46
|
*/
|
|
39
47
|
declare function useSyncSource(): SyncSource | undefined;
|
|
40
48
|
|
|
41
|
-
export { useGroup, useLatest, useLayoutEffect, useMentionSuggestions, useSignal, useSyncExternalStoreWithSelector, useSyncSource };
|
|
49
|
+
export { useGroup, useInitial, useLatest, useLayoutEffect, useMentionSuggestions, useSignal, useSyncExternalStoreWithSelector, useSyncSource };
|
package/dist/_private.js
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
useDeleteTextMention,
|
|
12
12
|
useEditRoomComment,
|
|
13
13
|
useEditRoomThreadMetadata,
|
|
14
|
+
useInitial,
|
|
14
15
|
useLatest,
|
|
15
16
|
useMarkRoomThreadAsRead,
|
|
16
17
|
useMarkRoomThreadAsResolved,
|
|
@@ -23,9 +24,11 @@ import {
|
|
|
23
24
|
useRoomPermissions,
|
|
24
25
|
useRoomThreadSubscription,
|
|
25
26
|
useSignal,
|
|
27
|
+
useSuspendUntilPresenceReady,
|
|
28
|
+
useSuspendUntilStorageReady,
|
|
26
29
|
useSyncExternalStoreWithSelector,
|
|
27
30
|
useYjsProvider
|
|
28
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-D3G7BVLV.js";
|
|
29
32
|
|
|
30
33
|
// src/lib/use-layout-effect.ts
|
|
31
34
|
import { useEffect, useLayoutEffect as useOriginalLayoutEffect } from "react";
|
|
@@ -159,6 +162,7 @@ export {
|
|
|
159
162
|
useEditRoomComment,
|
|
160
163
|
useEditRoomThreadMetadata,
|
|
161
164
|
useGroup,
|
|
165
|
+
useInitial,
|
|
162
166
|
useLatest,
|
|
163
167
|
useLayoutEffect,
|
|
164
168
|
useMarkRoomThreadAsRead,
|
|
@@ -173,6 +177,8 @@ export {
|
|
|
173
177
|
useRoomPermissions,
|
|
174
178
|
useRoomThreadSubscription,
|
|
175
179
|
useSignal,
|
|
180
|
+
useSuspendUntilPresenceReady,
|
|
181
|
+
useSuspendUntilStorageReady,
|
|
176
182
|
useSyncExternalStoreWithSelector,
|
|
177
183
|
useSyncSource,
|
|
178
184
|
useYjsProvider
|
package/dist/_private.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lib/use-layout-effect.ts","../src/use-group.ts","../src/use-mention-suggestions.ts","../src/use-sync-source.ts"],"sourcesContent":["/* eslint-disable no-restricted-syntax */\n\nimport { useEffect, useLayoutEffect as useOriginalLayoutEffect } from \"react\";\n\n// On React 18.2.0 and earlier, useLayoutEffect triggers a warning when\n// executed on the server, so this workaround should be used instead.\nexport const useLayoutEffect =\n typeof window !== \"undefined\" ? useOriginalLayoutEffect : useEffect;\n","import {\n type AsyncResult,\n type GroupData,\n kInternal,\n shallow,\n} from \"@liveblocks/core\";\nimport { useCallback, useEffect } from \"react\";\n\nimport { useClient } from \"./contexts\";\nimport type { GroupAsyncResult } from \"./types\";\nimport { useSyncExternalStoreWithSelector } from \"./use-sync-external-store-with-selector\";\n\nfunction selectorFor_useGroup(\n state: AsyncResult<GroupData | undefined> | undefined\n): GroupAsyncResult {\n if (state === undefined || state?.isLoading) {\n return state ?? { isLoading: true };\n }\n\n if (state.error) {\n return state;\n }\n\n return {\n isLoading: false,\n group: state.data,\n };\n}\n\n/** @private - Internal API, do not rely on it. */\nexport function useGroup(groupId: string): GroupAsyncResult {\n const client = useClient();\n const store = client[kInternal].httpClient.groupsStore;\n\n const getGroupState = useCallback(\n () => store.getItemState(groupId),\n [store, groupId]\n );\n\n useEffect(() => {\n void store.enqueue(groupId);\n }, [store, groupId]);\n\n return useSyncExternalStoreWithSelector(\n store.subscribe,\n getGroupState,\n getGroupState,\n selectorFor_useGroup,\n shallow\n );\n}\n","import { type MentionData, stableStringify } from \"@liveblocks/core\";\nimport { useEffect, useRef, useState } from \"react\";\n\nimport {\n useMentionSuggestionsCache,\n useResolveMentionSuggestions,\n} from \"./room\";\n\nconst MENTION_SUGGESTIONS_DEBOUNCE = 500;\n\n/**\n * Normalize mention suggestions as `MentionData[]`.\n *\n * Mention suggestions were previously typed as `string[]`, a list of user IDs,\n * but to support multiple mention kinds (user, group, etc), they're now\n * typed as `MentionData[]`.\n */\nfunction normalizeMentionSuggestions<T extends string[] | MentionData[]>(\n suggestions: T\n): MentionData[] {\n return suggestions.map(\n (suggestion): MentionData =>\n typeof suggestion === \"string\"\n ? { kind: \"user\" as const, id: suggestion }\n : suggestion\n );\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(roomId: string, search?: string) {\n const [mentionSuggestions, setMentionSuggestions] = useState<MentionData[]>();\n const lastInvokedAt = useRef<number>();\n\n const resolveMentionSuggestions = useResolveMentionSuggestions();\n const mentionSuggestionsCache = useMentionSuggestionsCache();\n\n useEffect(() => {\n if (search === undefined || !resolveMentionSuggestions) {\n return;\n }\n\n const resolveMentionSuggestionsArgs = { text: search, roomId };\n const mentionSuggestionsCacheKey = stableStringify(\n resolveMentionSuggestionsArgs\n );\n let debounceTimeout: number | undefined;\n let isCanceled = false;\n\n const getMentionSuggestions = async () => {\n try {\n lastInvokedAt.current = performance.now();\n const rawMentionSuggestions = await resolveMentionSuggestions(\n resolveMentionSuggestionsArgs\n );\n\n if (!isCanceled) {\n const normalizedSuggestions = normalizeMentionSuggestions(\n rawMentionSuggestions\n );\n setMentionSuggestions(normalizedSuggestions);\n mentionSuggestionsCache.set(\n mentionSuggestionsCacheKey,\n normalizedSuggestions\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 const cachedSuggestions = mentionSuggestionsCache.get(\n mentionSuggestionsCacheKey\n );\n setMentionSuggestions(cachedSuggestions);\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 }, [search, roomId, resolveMentionSuggestions, mentionSuggestionsCache]);\n\n return mentionSuggestions;\n}\n","import type { SyncSource } from \"@liveblocks/core\";\nimport { kInternal } from \"@liveblocks/core\";\nimport { useEffect, useState } from \"react\";\n\nimport { useClient } from \"./contexts\";\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] = useState<SyncSource | undefined>();\n\n 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":"
|
|
1
|
+
{"version":3,"sources":["../src/lib/use-layout-effect.ts","../src/use-group.ts","../src/use-mention-suggestions.ts","../src/use-sync-source.ts"],"sourcesContent":["/* eslint-disable no-restricted-syntax */\n\nimport { useEffect, useLayoutEffect as useOriginalLayoutEffect } from \"react\";\n\n// On React 18.2.0 and earlier, useLayoutEffect triggers a warning when\n// executed on the server, so this workaround should be used instead.\nexport const useLayoutEffect =\n typeof window !== \"undefined\" ? useOriginalLayoutEffect : useEffect;\n","import {\n type AsyncResult,\n type GroupData,\n kInternal,\n shallow,\n} from \"@liveblocks/core\";\nimport { useCallback, useEffect } from \"react\";\n\nimport { useClient } from \"./contexts\";\nimport type { GroupAsyncResult } from \"./types\";\nimport { useSyncExternalStoreWithSelector } from \"./use-sync-external-store-with-selector\";\n\nfunction selectorFor_useGroup(\n state: AsyncResult<GroupData | undefined> | undefined\n): GroupAsyncResult {\n if (state === undefined || state?.isLoading) {\n return state ?? { isLoading: true };\n }\n\n if (state.error) {\n return state;\n }\n\n return {\n isLoading: false,\n group: state.data,\n };\n}\n\n/** @private - Internal API, do not rely on it. */\nexport function useGroup(groupId: string): GroupAsyncResult {\n const client = useClient();\n const store = client[kInternal].httpClient.groupsStore;\n\n const getGroupState = useCallback(\n () => store.getItemState(groupId),\n [store, groupId]\n );\n\n useEffect(() => {\n void store.enqueue(groupId);\n }, [store, groupId]);\n\n return useSyncExternalStoreWithSelector(\n store.subscribe,\n getGroupState,\n getGroupState,\n selectorFor_useGroup,\n shallow\n );\n}\n","import { type MentionData, stableStringify } from \"@liveblocks/core\";\nimport { useEffect, useRef, useState } from \"react\";\n\nimport {\n useMentionSuggestionsCache,\n useResolveMentionSuggestions,\n} from \"./room\";\n\nconst MENTION_SUGGESTIONS_DEBOUNCE = 500;\n\n/**\n * Normalize mention suggestions as `MentionData[]`.\n *\n * Mention suggestions were previously typed as `string[]`, a list of user IDs,\n * but to support multiple mention kinds (user, group, etc), they're now\n * typed as `MentionData[]`.\n */\nfunction normalizeMentionSuggestions<T extends string[] | MentionData[]>(\n suggestions: T\n): MentionData[] {\n return suggestions.map(\n (suggestion): MentionData =>\n typeof suggestion === \"string\"\n ? { kind: \"user\" as const, id: suggestion }\n : suggestion\n );\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(roomId: string, search?: string) {\n const [mentionSuggestions, setMentionSuggestions] = useState<MentionData[]>();\n const lastInvokedAt = useRef<number>();\n\n const resolveMentionSuggestions = useResolveMentionSuggestions();\n const mentionSuggestionsCache = useMentionSuggestionsCache();\n\n useEffect(() => {\n if (search === undefined || !resolveMentionSuggestions) {\n return;\n }\n\n const resolveMentionSuggestionsArgs = { text: search, roomId };\n const mentionSuggestionsCacheKey = stableStringify(\n resolveMentionSuggestionsArgs\n );\n let debounceTimeout: number | undefined;\n let isCanceled = false;\n\n const getMentionSuggestions = async () => {\n try {\n lastInvokedAt.current = performance.now();\n const rawMentionSuggestions = await resolveMentionSuggestions(\n resolveMentionSuggestionsArgs\n );\n\n if (!isCanceled) {\n const normalizedSuggestions = normalizeMentionSuggestions(\n rawMentionSuggestions\n );\n setMentionSuggestions(normalizedSuggestions);\n mentionSuggestionsCache.set(\n mentionSuggestionsCacheKey,\n normalizedSuggestions\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 const cachedSuggestions = mentionSuggestionsCache.get(\n mentionSuggestionsCacheKey\n );\n setMentionSuggestions(cachedSuggestions);\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 }, [search, roomId, resolveMentionSuggestions, mentionSuggestionsCache]);\n\n return mentionSuggestions;\n}\n","import type { SyncSource } from \"@liveblocks/core\";\nimport { kInternal } from \"@liveblocks/core\";\nimport { useEffect, useState } from \"react\";\n\nimport { useClient } from \"./contexts\";\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] = useState<SyncSource | undefined>();\n\n 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,SAAS,WAAW,mBAAmB,+BAA+B;AAI/D,IAAM,kBACX,OAAO,WAAW,cAAc,0BAA0B;;;ACP5D;AAAA,EAGE;AAAA,EACA;AAAA,OACK;AACP,SAAS,aAAa,aAAAA,kBAAiB;AAMvC,SAAS,qBACP,OACkB;AAClB,MAAI,UAAU,UAAa,OAAO,WAAW;AAC3C,WAAO,SAAS,EAAE,WAAW,KAAK;AAAA,EACpC;AAEA,MAAI,MAAM,OAAO;AACf,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL,WAAW;AAAA,IACX,OAAO,MAAM;AAAA,EACf;AACF;AAGO,SAAS,SAAS,SAAmC;AAC1D,QAAM,SAAS,UAAU;AACzB,QAAM,QAAQ,OAAO,SAAS,EAAE,WAAW;AAE3C,QAAM,gBAAgB;AAAA,IACpB,MAAM,MAAM,aAAa,OAAO;AAAA,IAChC,CAAC,OAAO,OAAO;AAAA,EACjB;AAEA,EAAAC,WAAU,MAAM;AACd,SAAK,MAAM,QAAQ,OAAO;AAAA,EAC5B,GAAG,CAAC,OAAO,OAAO,CAAC;AAEnB,SAAO;AAAA,IACL,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;;;AClDA,SAA2B,uBAAuB;AAClD,SAAS,aAAAC,YAAW,QAAQ,gBAAgB;AAO5C,IAAM,+BAA+B;AASrC,SAAS,4BACP,aACe;AACf,SAAO,YAAY;AAAA,IACjB,CAAC,eACC,OAAO,eAAe,WAClB,EAAE,MAAM,QAAiB,IAAI,WAAW,IACxC;AAAA,EACR;AACF;AAQO,SAAS,sBAAsB,QAAg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AC,iBAAgB;AAO7B,SAAS,gBAAwC;AACtD,QAAM,SAAS,UAAU;AACzB,QAAM,mBAAmB,OAAOC,UAAS,EAAE;AAC3C,QAAM,CAAC,YAAY,aAAa,IAAIC,UAAiC;AAErE,EAAAC,WAAU,MAAM;AAEd,UAAM,gBAAgB,iBAAiB;AACvC,kBAAc,aAAa;AAC3B,WAAO,MAAM,cAAc,QAAQ;AAAA,EACrC,GAAG,CAAC,gBAAgB,CAAC;AAErB,SAAO;AACT;","names":["useEffect","useEffect","useEffect","useEffect","kInternal","useEffect","useState","kInternal","useState","useEffect"]}
|
|
@@ -27,6 +27,25 @@ function useLatest(value) {
|
|
|
27
27
|
return ref;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
// src/lib/use-initial.ts
|
|
31
|
+
import { useCallback, useMemo } from "react";
|
|
32
|
+
function useInitial(value, roomId) {
|
|
33
|
+
return useMemo(() => value, [roomId]);
|
|
34
|
+
}
|
|
35
|
+
function useInitialUnlessFunction(latestValue, roomId) {
|
|
36
|
+
const frozenValue = useInitial(latestValue, roomId);
|
|
37
|
+
const ref = useLatest(latestValue);
|
|
38
|
+
const wrapper = useCallback(
|
|
39
|
+
(...args) => ref.current(...args),
|
|
40
|
+
[ref]
|
|
41
|
+
);
|
|
42
|
+
if (typeof frozenValue === "function") {
|
|
43
|
+
return wrapper;
|
|
44
|
+
} else {
|
|
45
|
+
return frozenValue;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
30
49
|
// src/ai.tsx
|
|
31
50
|
import { kInternal, nanoid } from "@liveblocks/core";
|
|
32
51
|
import { memo, useEffect as useEffect2, useId, useState } from "react";
|
|
@@ -82,7 +101,7 @@ var RegisterAiTool = memo(function RegisterAiTool2({
|
|
|
82
101
|
import {
|
|
83
102
|
useDebugValue,
|
|
84
103
|
useEffect as useEffect3,
|
|
85
|
-
useMemo,
|
|
104
|
+
useMemo as useMemo2,
|
|
86
105
|
useRef as useRef2,
|
|
87
106
|
useSyncExternalStore
|
|
88
107
|
} from "react";
|
|
@@ -101,7 +120,7 @@ function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnaps
|
|
|
101
120
|
} else {
|
|
102
121
|
inst = instRef.current;
|
|
103
122
|
}
|
|
104
|
-
const [getSelection, getServerSelection] =
|
|
123
|
+
const [getSelection, getServerSelection] = useMemo2(() => {
|
|
105
124
|
let hasMemo = false;
|
|
106
125
|
let memoizedSnapshot;
|
|
107
126
|
let memoizedSelection;
|
|
@@ -231,25 +250,6 @@ function ensureNotServerSide() {
|
|
|
231
250
|
}
|
|
232
251
|
}
|
|
233
252
|
|
|
234
|
-
// src/lib/use-initial.ts
|
|
235
|
-
import { useCallback, useMemo as useMemo2 } from "react";
|
|
236
|
-
function useInitial(value, roomId) {
|
|
237
|
-
return useMemo2(() => value, [roomId]);
|
|
238
|
-
}
|
|
239
|
-
function useInitialUnlessFunction(latestValue, roomId) {
|
|
240
|
-
const frozenValue = useInitial(latestValue, roomId);
|
|
241
|
-
const ref = useLatest(latestValue);
|
|
242
|
-
const wrapper = useCallback(
|
|
243
|
-
(...args) => ref.current(...args),
|
|
244
|
-
[ref]
|
|
245
|
-
);
|
|
246
|
-
if (typeof frozenValue === "function") {
|
|
247
|
-
return wrapper;
|
|
248
|
-
} else {
|
|
249
|
-
return frozenValue;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
253
|
// src/lib/use-polyfill.ts
|
|
254
254
|
import * as React from "react";
|
|
255
255
|
var reactUse = React[" use ".trim().toString()];
|
|
@@ -5386,6 +5386,9 @@ function useSuspendUntilPresenceReady_withRoomContext(RoomContext) {
|
|
|
5386
5386
|
const room = useRoom_withRoomContext(RoomContext);
|
|
5387
5387
|
use(room.waitUntilPresenceReady());
|
|
5388
5388
|
}
|
|
5389
|
+
function useSuspendUntilPresenceReady() {
|
|
5390
|
+
return useSuspendUntilPresenceReady_withRoomContext(GlobalRoomContext);
|
|
5391
|
+
}
|
|
5389
5392
|
function useSelfSuspense_withRoomContext(RoomContext, selector, isEqual) {
|
|
5390
5393
|
useSuspendUntilPresenceReady_withRoomContext(RoomContext);
|
|
5391
5394
|
return useSelf_withRoomContext(
|
|
@@ -5460,6 +5463,9 @@ function useSuspendUntilStorageReady_withRoomContext(RoomContext) {
|
|
|
5460
5463
|
const room = useRoom_withRoomContext(RoomContext);
|
|
5461
5464
|
use(room.waitUntilStorageReady());
|
|
5462
5465
|
}
|
|
5466
|
+
function useSuspendUntilStorageReady() {
|
|
5467
|
+
return useSuspendUntilStorageReady_withRoomContext(GlobalRoomContext);
|
|
5468
|
+
}
|
|
5463
5469
|
function useStorageSuspense_withRoomContext(RoomContext, selector, isEqual) {
|
|
5464
5470
|
useSuspendUntilStorageReady_withRoomContext(RoomContext);
|
|
5465
5471
|
return useStorage_withRoomContext(
|
|
@@ -6048,6 +6054,7 @@ export {
|
|
|
6048
6054
|
useClient,
|
|
6049
6055
|
GlobalRoomContext,
|
|
6050
6056
|
useLatest,
|
|
6057
|
+
useInitial,
|
|
6051
6058
|
RegisterAiKnowledge,
|
|
6052
6059
|
RegisterAiTool,
|
|
6053
6060
|
useSyncExternalStoreWithSelector,
|
|
@@ -6131,7 +6138,9 @@ export {
|
|
|
6131
6138
|
useRoomThreadSubscription,
|
|
6132
6139
|
useHistoryVersionData,
|
|
6133
6140
|
useUpdateRoomSubscriptionSettings,
|
|
6141
|
+
useSuspendUntilPresenceReady,
|
|
6134
6142
|
useOthersConnectionIdsSuspense,
|
|
6143
|
+
useSuspendUntilStorageReady,
|
|
6135
6144
|
useAttachmentUrl,
|
|
6136
6145
|
useRoomAttachmentUrl,
|
|
6137
6146
|
useAttachmentUrlSuspense,
|
|
@@ -6176,4 +6185,4 @@ export {
|
|
|
6176
6185
|
_useStorageRoot,
|
|
6177
6186
|
_useUpdateMyPresence
|
|
6178
6187
|
};
|
|
6179
|
-
//# sourceMappingURL=chunk-
|
|
6188
|
+
//# sourceMappingURL=chunk-D3G7BVLV.js.map
|