@liveblocks/react 2.17.0-channels1 → 2.17.0-usrnotsettings1
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.d.mts +1 -1
- package/dist/_private.d.ts +1 -1
- package/dist/_private.js +5 -7
- package/dist/_private.js.map +1 -1
- package/dist/_private.mjs +1 -3
- package/dist/_private.mjs.map +1 -1
- package/dist/{chunk-22QRR3GV.js → chunk-4F7C4HN7.js} +168 -286
- package/dist/chunk-4F7C4HN7.js.map +1 -0
- package/dist/{chunk-RABQO63H.js → chunk-DT3BO7N5.js} +2 -2
- package/dist/{chunk-RABQO63H.js.map → chunk-DT3BO7N5.js.map} +1 -1
- package/dist/{chunk-KFACA6OH.mjs → chunk-KAFU5ZQA.mjs} +2 -2
- package/dist/{chunk-VX6Y3GQO.mjs → chunk-LOPNJCSB.mjs} +169 -287
- package/dist/chunk-LOPNJCSB.mjs.map +1 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +8 -13
- package/dist/index.mjs.map +1 -1
- package/dist/{room-C0TyErPq.d.mts → room-DlI0Yrzf.d.mts} +72 -190
- package/dist/{room-C0TyErPq.d.ts → room-DlI0Yrzf.d.ts} +72 -190
- package/dist/suspense.d.mts +2 -2
- package/dist/suspense.d.ts +2 -2
- package/dist/suspense.js +4 -7
- package/dist/suspense.js.map +1 -1
- package/dist/suspense.mjs +8 -11
- package/dist/suspense.mjs.map +1 -1
- package/package.json +4 -4
- package/dist/chunk-22QRR3GV.js.map +0 -1
- package/dist/chunk-VX6Y3GQO.mjs.map +0 -1
- /package/dist/{chunk-KFACA6OH.mjs.map → chunk-KAFU5ZQA.mjs.map} +0 -0
package/dist/_private.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { g as getUmbrellaStoreForClient, b as useAddRoomCommentReaction, a as useClientOrNull, c as useCreateRoomComment, d as useCreateRoomThread, e as useCreateTextMention, f as useDeleteRoomComment, h as useDeleteRoomThread, i as useDeleteTextMention, j as useEditRoomComment, k as useEditRoomThreadMetadata, l as useMarkRoomThreadAsRead, m as useMarkRoomThreadAsResolved, n as useMarkRoomThreadAsUnresolved, o as useMentionSuggestionsCache, p as useRemoveRoomCommentReaction, q as useReportTextEditor, r as useResolveMentionSuggestions, s as useRoomAttachmentUrl, u as useRoomOrNull, t as useRoomPermissions, v as useYjsProvider } from './room-DlI0Yrzf.mjs';
|
|
2
2
|
import { useLayoutEffect as useLayoutEffect$1 } from 'react';
|
|
3
3
|
import { ISignal, SyncSource } from '@liveblocks/core';
|
|
4
4
|
import '@liveblocks/client';
|
package/dist/_private.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { g as getUmbrellaStoreForClient, b as useAddRoomCommentReaction, a as useClientOrNull, c as useCreateRoomComment, d as useCreateRoomThread, e as useCreateTextMention, f as useDeleteRoomComment, h as useDeleteRoomThread, i as useDeleteTextMention, j as useEditRoomComment, k as useEditRoomThreadMetadata, l as useMarkRoomThreadAsRead, m as useMarkRoomThreadAsResolved, n as useMarkRoomThreadAsUnresolved, o as useMentionSuggestionsCache, p as useRemoveRoomCommentReaction, q as useReportTextEditor, r as useResolveMentionSuggestions, s as useRoomAttachmentUrl, u as useRoomOrNull, t as useRoomPermissions, v as useYjsProvider } from './room-DlI0Yrzf.js';
|
|
2
2
|
import { useLayoutEffect as useLayoutEffect$1 } from 'react';
|
|
3
3
|
import { ISignal, SyncSource } from '@liveblocks/core';
|
|
4
4
|
import '@liveblocks/client';
|
package/dist/_private.js
CHANGED
|
@@ -24,8 +24,7 @@
|
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
var _chunk22QRR3GVjs = require('./chunk-22QRR3GV.js');
|
|
27
|
+
var _chunk4F7C4HN7js = require('./chunk-4F7C4HN7.js');
|
|
29
28
|
|
|
30
29
|
// src/lib/use-layout-effect.ts
|
|
31
30
|
var _react = require('react');
|
|
@@ -38,8 +37,8 @@ var MENTION_SUGGESTIONS_DEBOUNCE = 500;
|
|
|
38
37
|
function useMentionSuggestions(roomId, search) {
|
|
39
38
|
const [mentionSuggestions, setMentionSuggestions] = _react.useState.call(void 0, );
|
|
40
39
|
const lastInvokedAt = _react.useRef.call(void 0, );
|
|
41
|
-
const resolveMentionSuggestions =
|
|
42
|
-
const mentionSuggestionsCache =
|
|
40
|
+
const resolveMentionSuggestions = _chunk4F7C4HN7js.useResolveMentionSuggestions.call(void 0, );
|
|
41
|
+
const mentionSuggestionsCache = _chunk4F7C4HN7js.useMentionSuggestionsCache.call(void 0, );
|
|
43
42
|
_react.useEffect.call(void 0, () => {
|
|
44
43
|
if (search === void 0 || !resolveMentionSuggestions) {
|
|
45
44
|
return;
|
|
@@ -88,7 +87,7 @@ function useMentionSuggestions(roomId, search) {
|
|
|
88
87
|
|
|
89
88
|
|
|
90
89
|
function useSyncSource() {
|
|
91
|
-
const client =
|
|
90
|
+
const client = _chunk4F7C4HN7js.useClient.call(void 0, );
|
|
92
91
|
const createSyncSource = client[_core.kInternal].createSyncSource;
|
|
93
92
|
const [syncSource, setSyncSource] = _react.useState.call(void 0, );
|
|
94
93
|
_react.useEffect.call(void 0, () => {
|
|
@@ -126,6 +125,5 @@ function useSyncSource() {
|
|
|
126
125
|
|
|
127
126
|
|
|
128
127
|
|
|
129
|
-
|
|
130
|
-
exports.CreateThreadError = _chunk22QRR3GVjs.CreateThreadError; exports.getUmbrellaStoreForClient = _chunk22QRR3GVjs.getUmbrellaStoreForClient; exports.useAddRoomCommentReaction = _chunk22QRR3GVjs.useAddRoomCommentReaction; exports.useClientOrNull = _chunk22QRR3GVjs.useClientOrNull; exports.useCreateRoomComment = _chunk22QRR3GVjs.useCreateRoomComment; exports.useCreateRoomThread = _chunk22QRR3GVjs.useCreateRoomThread; exports.useCreateTextMention = _chunk22QRR3GVjs.useCreateTextMention; exports.useDeleteRoomComment = _chunk22QRR3GVjs.useDeleteRoomComment; exports.useDeleteRoomThread = _chunk22QRR3GVjs.useDeleteRoomThread; exports.useDeleteTextMention = _chunk22QRR3GVjs.useDeleteTextMention; exports.useEditRoomComment = _chunk22QRR3GVjs.useEditRoomComment; exports.useEditRoomThreadMetadata = _chunk22QRR3GVjs.useEditRoomThreadMetadata; exports.useLayoutEffect = useLayoutEffect; exports.useMarkRoomThreadAsRead = _chunk22QRR3GVjs.useMarkRoomThreadAsRead; exports.useMarkRoomThreadAsResolved = _chunk22QRR3GVjs.useMarkRoomThreadAsResolved; exports.useMarkRoomThreadAsUnresolved = _chunk22QRR3GVjs.useMarkRoomThreadAsUnresolved; exports.useMentionSuggestions = useMentionSuggestions; exports.useMentionSuggestionsCache = _chunk22QRR3GVjs.useMentionSuggestionsCache; exports.useRemoveRoomCommentReaction = _chunk22QRR3GVjs.useRemoveRoomCommentReaction; exports.useReportTextEditor = _chunk22QRR3GVjs.useReportTextEditor; exports.useResolveMentionSuggestions = _chunk22QRR3GVjs.useResolveMentionSuggestions; exports.useRoomAttachmentUrl = _chunk22QRR3GVjs.useRoomAttachmentUrl; exports.useRoomOrNull = _chunk22QRR3GVjs.useRoomOrNull; exports.useRoomPermissions = _chunk22QRR3GVjs.useRoomPermissions; exports.useSignal = _chunk22QRR3GVjs.useSignal; exports.useSyncExternalStoreWithSelector = _chunk22QRR3GVjs.useSyncExternalStoreWithSelector; exports.useSyncSource = useSyncSource; exports.useYjsProvider = _chunk22QRR3GVjs.useYjsProvider;
|
|
128
|
+
exports.getUmbrellaStoreForClient = _chunk4F7C4HN7js.getUmbrellaStoreForClient; exports.useAddRoomCommentReaction = _chunk4F7C4HN7js.useAddRoomCommentReaction; exports.useClientOrNull = _chunk4F7C4HN7js.useClientOrNull; exports.useCreateRoomComment = _chunk4F7C4HN7js.useCreateRoomComment; exports.useCreateRoomThread = _chunk4F7C4HN7js.useCreateRoomThread; exports.useCreateTextMention = _chunk4F7C4HN7js.useCreateTextMention; exports.useDeleteRoomComment = _chunk4F7C4HN7js.useDeleteRoomComment; exports.useDeleteRoomThread = _chunk4F7C4HN7js.useDeleteRoomThread; exports.useDeleteTextMention = _chunk4F7C4HN7js.useDeleteTextMention; exports.useEditRoomComment = _chunk4F7C4HN7js.useEditRoomComment; exports.useEditRoomThreadMetadata = _chunk4F7C4HN7js.useEditRoomThreadMetadata; exports.useLayoutEffect = useLayoutEffect; exports.useMarkRoomThreadAsRead = _chunk4F7C4HN7js.useMarkRoomThreadAsRead; exports.useMarkRoomThreadAsResolved = _chunk4F7C4HN7js.useMarkRoomThreadAsResolved; exports.useMarkRoomThreadAsUnresolved = _chunk4F7C4HN7js.useMarkRoomThreadAsUnresolved; exports.useMentionSuggestions = useMentionSuggestions; exports.useMentionSuggestionsCache = _chunk4F7C4HN7js.useMentionSuggestionsCache; exports.useRemoveRoomCommentReaction = _chunk4F7C4HN7js.useRemoveRoomCommentReaction; exports.useReportTextEditor = _chunk4F7C4HN7js.useReportTextEditor; exports.useResolveMentionSuggestions = _chunk4F7C4HN7js.useResolveMentionSuggestions; exports.useRoomAttachmentUrl = _chunk4F7C4HN7js.useRoomAttachmentUrl; exports.useRoomOrNull = _chunk4F7C4HN7js.useRoomOrNull; exports.useRoomPermissions = _chunk4F7C4HN7js.useRoomPermissions; exports.useSignal = _chunk4F7C4HN7js.useSignal; exports.useSyncExternalStoreWithSelector = _chunk4F7C4HN7js.useSyncExternalStoreWithSelector; exports.useSyncSource = useSyncSource; exports.useYjsProvider = _chunk4F7C4HN7js.useYjsProvider;
|
|
131
129
|
//# sourceMappingURL=_private.js.map
|
package/dist/_private.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/liveblocks/liveblocks/packages/liveblocks-react/dist/_private.js","../src/lib/use-layout-effect.ts","../src/use-mention-suggestions.ts","../src/use-sync-source.ts"],"names":["useEffect","mentionSuggestions","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;
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/liveblocks/liveblocks/packages/liveblocks-react/dist/_private.js","../src/lib/use-layout-effect.ts","../src/use-mention-suggestions.ts","../src/use-sync-source.ts"],"names":["useEffect","mentionSuggestions","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;AACF,sDAA4B;AAC5B;AACA;AC1BA,8BAAsE;AAI/D,IAAM,gBAAA,EACX,OAAO,OAAA,IAAW,YAAA,EAAc,uBAAA,EAA0B,gBAAA;ADwB5D;AACA;AEhCA,wCAA0B;AAC1B;AAOA,IAAM,6BAAA,EAA+B,GAAA;AAQ9B,SAAS,qBAAA,CAAsB,MAAA,EAAgB,MAAA,EAAiB;AACrE,EAAA,MAAM,CAAC,kBAAA,EAAoB,qBAAqB,EAAA,EAAI,6BAAA,CAAmB;AACvE,EAAA,MAAM,cAAA,EAAgB,2BAAA,CAAe;AAErC,EAAA,MAAM,0BAAA,EAA4B,2DAAA,CAA6B;AAC/D,EAAA,MAAM,wBAAA,EAA0B,yDAAA,CAA2B;AAE3D,EAAAA,8BAAAA,CAAU,EAAA,GAAM;AACd,IAAA,GAAA,CAAI,OAAA,IAAW,KAAA,EAAA,GAAa,CAAC,yBAAA,EAA2B;AACtD,MAAA,MAAA;AAAA,IACF;AAEA,IAAA,MAAM,8BAAA,EAAgC,EAAE,IAAA,EAAM,MAAA,EAAQ,OAAO,CAAA;AAC7D,IAAA,MAAM,2BAAA,EAA6B,6BAAA,6BAAuC,CAAA;AAC1E,IAAA,IAAI,eAAA;AACJ,IAAA,IAAI,WAAA,EAAa,KAAA;AAEjB,IAAA,MAAM,sBA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yBAAA,EAA2B,uBAAuB,CAAC,CAAA;AAEvE,EAAA,OAAO,kBAAA;AACT;AFKA;AACA;AGpFA;AACA;AAOO,SAAS,aAAA,CAAA,EAAwC;AACtD,EAAA,MAAM,OAAA,EAAS,wCAAA,CAAU;AACzB,EAAA,MAAM,iBAAA,EAAmB,MAAA,CAAO,eAAS,CAAA,CAAE,gBAAA;AAC3C,EAAA,MAAM,CAAC,UAAA,EAAY,aAAa,EAAA,EAAIC,6BAAAA,CAAiC;AAErE,EAAAF,8BAAAA,CAAU,EAAA,GAAM;AAEd,IAAA,MAAM,cAAA,EAAgB,gBAAA,CAAiB,CAAA;AACvC,IAAA,aAAA,CAAc,aAAa,CAAA;AAC3B,IAAA,OAAO,CAAA,EAAA,GAAM,aAAA,CAAc,OAAA,CAAQ,CAAA;AAAA,EACrC,CAAA,EAAG,CAAC,gBAAgB,CAAC,CAAA;AAErB,EAAA,OAAO,UAAA;AACT;AH6EA;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;AACF,w1DAAC","file":"/home/runner/work/liveblocks/liveblocks/packages/liveblocks-react/dist/_private.js","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 { stringify } 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 * @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<string[]>();\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 = 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 }, [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 \"./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] = 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.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
CreateThreadError,
|
|
3
2
|
getUmbrellaStoreForClient,
|
|
4
3
|
useAddRoomCommentReaction,
|
|
5
4
|
useClient,
|
|
@@ -25,7 +24,7 @@ import {
|
|
|
25
24
|
useSignal,
|
|
26
25
|
useSyncExternalStoreWithSelector,
|
|
27
26
|
useYjsProvider
|
|
28
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-LOPNJCSB.mjs";
|
|
29
28
|
|
|
30
29
|
// src/lib/use-layout-effect.ts
|
|
31
30
|
import { useEffect, useLayoutEffect as useOriginalLayoutEffect } from "react";
|
|
@@ -99,7 +98,6 @@ function useSyncSource() {
|
|
|
99
98
|
return syncSource;
|
|
100
99
|
}
|
|
101
100
|
export {
|
|
102
|
-
CreateThreadError,
|
|
103
101
|
getUmbrellaStoreForClient,
|
|
104
102
|
useAddRoomCommentReaction,
|
|
105
103
|
useClientOrNull,
|
package/dist/_private.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lib/use-layout-effect.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 { stringify } 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 * @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<string[]>();\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 = 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 }, [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 \"./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] = 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-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 { stringify } 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 * @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<string[]>();\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 = 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 }, [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 \"./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] = 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA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