@liveblocks/react 2.9.3-experimental1 → 2.10.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.
@@ -0,0 +1,5 @@
1
+ What is this directory? It exists solely to support subpath imports for node10.
2
+
3
+ While we're not interested in supporting this long-past EOL version 10 of Node,
4
+ we add this to acknowledge the reality that many TypeScript projects out there
5
+ are still using `--moduleResolution node`.
@@ -0,0 +1,4 @@
1
+ {
2
+ "main": "../dist/_private.js",
3
+ "types": "../dist/_private.d.ts"
4
+ }
@@ -0,0 +1,14 @@
1
+ export { C as CreateThreadError, g as getUmbrellaStoreForClient, s as selectThreads } from './liveblocks-X3qYz1Vg.mjs';
2
+ import '@liveblocks/client';
3
+ import '@liveblocks/core';
4
+ import 'react';
5
+
6
+ /**
7
+ * @private For internal use only. Do not rely on this hook.
8
+ *
9
+ * Simplistic debounced search, we don't need to worry too much about deduping
10
+ * and race conditions as there can only be one search at a time.
11
+ */
12
+ declare function useMentionSuggestions(search?: string): string[] | undefined;
13
+
14
+ export { useMentionSuggestions };
@@ -0,0 +1,14 @@
1
+ export { C as CreateThreadError, g as getUmbrellaStoreForClient, s as selectThreads } from './liveblocks-X3qYz1Vg.js';
2
+ import '@liveblocks/client';
3
+ import '@liveblocks/core';
4
+ import 'react';
5
+
6
+ /**
7
+ * @private For internal use only. Do not rely on this hook.
8
+ *
9
+ * Simplistic debounced search, we don't need to worry too much about deduping
10
+ * and race conditions as there can only be one search at a time.
11
+ */
12
+ declare function useMentionSuggestions(search?: string): string[] | undefined;
13
+
14
+ export { useMentionSuggestions };
@@ -0,0 +1,69 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+
4
+
5
+
6
+
7
+ var _chunkWJLAYICRjs = require('./chunk-WJLAYICR.js');
8
+
9
+ // src/use-mention-suggestions.ts
10
+ var _core = require('@liveblocks/core');
11
+ var _react = require('react'); var _react2 = _interopRequireDefault(_react);
12
+ var MENTION_SUGGESTIONS_DEBOUNCE = 500;
13
+ function useMentionSuggestions(search) {
14
+ const client = _chunkWJLAYICRjs.useClient.call(void 0, );
15
+ const room = _chunkWJLAYICRjs._useRoom.call(void 0, );
16
+ const [mentionSuggestions, setMentionSuggestions] = _react2.default.useState();
17
+ const lastInvokedAt = _react2.default.useRef();
18
+ _react2.default.useEffect(() => {
19
+ const mentionSuggestionsCache = client[_core.kInternal].mentionSuggestionsCache;
20
+ const resolveMentionSuggestions = client[_core.kInternal].resolveMentionSuggestions;
21
+ if (search === void 0 || !resolveMentionSuggestions) {
22
+ return;
23
+ }
24
+ const resolveMentionSuggestionsArgs = { text: search, roomId: room.id };
25
+ const mentionSuggestionsCacheKey = _core.stringify.call(void 0, resolveMentionSuggestionsArgs);
26
+ let debounceTimeout;
27
+ let isCanceled = false;
28
+ const getMentionSuggestions = async () => {
29
+ try {
30
+ lastInvokedAt.current = performance.now();
31
+ const mentionSuggestions2 = await resolveMentionSuggestions(
32
+ resolveMentionSuggestionsArgs
33
+ );
34
+ if (!isCanceled) {
35
+ setMentionSuggestions(mentionSuggestions2);
36
+ mentionSuggestionsCache.set(
37
+ mentionSuggestionsCacheKey,
38
+ mentionSuggestions2
39
+ );
40
+ }
41
+ } catch (error) {
42
+ console.error(_optionalChain([error, 'optionalAccess', _ => _.message]));
43
+ }
44
+ };
45
+ if (mentionSuggestionsCache.has(mentionSuggestionsCacheKey)) {
46
+ setMentionSuggestions(
47
+ mentionSuggestionsCache.get(mentionSuggestionsCacheKey)
48
+ );
49
+ } else if (!lastInvokedAt.current || Math.abs(performance.now() - lastInvokedAt.current) > MENTION_SUGGESTIONS_DEBOUNCE) {
50
+ void getMentionSuggestions();
51
+ } else {
52
+ debounceTimeout = window.setTimeout(() => {
53
+ void getMentionSuggestions();
54
+ }, MENTION_SUGGESTIONS_DEBOUNCE);
55
+ }
56
+ return () => {
57
+ isCanceled = true;
58
+ window.clearTimeout(debounceTimeout);
59
+ };
60
+ }, [client, room.id, search]);
61
+ return mentionSuggestions;
62
+ }
63
+
64
+
65
+
66
+
67
+
68
+ exports.CreateThreadError = _chunkWJLAYICRjs.CreateThreadError; exports.getUmbrellaStoreForClient = _chunkWJLAYICRjs.getUmbrellaStoreForClient; exports.selectThreads = _chunkWJLAYICRjs.selectThreads; exports.useMentionSuggestions = useMentionSuggestions;
69
+ //# sourceMappingURL=_private.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/use-mention-suggestions.ts"],"names":["mentionSuggestions"],"mappings":";;;;;;;;;AAAA,SAAS,WAAW,iBAAiB;AACrC,OAAO,WAAW;AAKlB,IAAM,+BAA+B;AAQ9B,SAAS,sBAAsB,QAAiB;AACrD,QAAM,SAAS,UAAU;AAEzB,QAAM,OAAO,SAAQ;AACrB,QAAM,CAAC,oBAAoB,qBAAqB,IAC9C,MAAM,SAAmB;AAC3B,QAAM,gBAAgB,MAAM,OAAe;AAE3C,QAAM,UAAU,MAAM;AACpB,UAAM,0BAA0B,OAAO,SAAS,EAAE;AAClD,UAAM,4BACJ,OAAO,SAAS,EAAE;AAEpB,QAAI,WAAW,UAAa,CAAC,2BAA2B;AACtD;AAAA,IACF;AAEA,UAAM,gCAAgC,EAAE,MAAM,QAAQ,QAAQ,KAAK,GAAG;AACtE,UAAM,6BAA6B,UAAU,6BAA6B;AAC1E,QAAI;AACJ,QAAI,aAAa;AAEjB,UAAM,wBAAwB,YAAY;AACxC,UAAI;AACF,sBAAc,UAAU,YAAY,IAAI;AACxC,cAAMA,sBAAqB,MAAM;AAAA,UAC/B;AAAA,QACF;AAEA,YAAI,CAAC,YAAY;AACf,gCAAsBA,mBAAkB;AACxC,kCAAwB;AAAA,YACtB;AAAA,YACAA;AAAA,UACF;AAAA,QACF;AAAA,MACF,SAAS,OAAO;AACd,gBAAQ,MAAO,OAAiB,OAAO;AAAA,MACzC;AAAA,IACF;AAEA,QAAI,wBAAwB,IAAI,0BAA0B,GAAG;AAE3D;AAAA,QACE,wBAAwB,IAAI,0BAA0B;AAAA,MACxD;AAAA,IACF,WACE,CAAC,cAAc,WACf,KAAK,IAAI,YAAY,IAAI,IAAI,cAAc,OAAO,IAChD,8BACF;AAGA,WAAK,sBAAsB;AAAA,IAC7B,OAAO;AAEL,wBAAkB,OAAO,WAAW,MAAM;AACxC,aAAK,sBAAsB;AAAA,MAC7B,GAAG,4BAA4B;AAAA,IACjC;AAEA,WAAO,MAAM;AACX,mBAAa;AACb,aAAO,aAAa,eAAe;AAAA,IACrC;AAAA,EACF,GAAG,CAAC,QAAQ,KAAK,IAAI,MAAM,CAAC;AAE5B,SAAO;AACT","sourcesContent":["import { kInternal, stringify } from \"@liveblocks/core\";\nimport React from \"react\";\n\nimport { useClient } from \"./liveblocks\";\nimport { useRoom } from \"./room\";\n\nconst MENTION_SUGGESTIONS_DEBOUNCE = 500;\n\n/**\n * @private For internal use only. Do not rely on this hook.\n *\n * Simplistic debounced search, we don't need to worry too much about deduping\n * and race conditions as there can only be one search at a time.\n */\nexport function useMentionSuggestions(search?: string) {\n const client = useClient();\n\n const room = useRoom();\n const [mentionSuggestions, setMentionSuggestions] =\n React.useState<string[]>();\n const lastInvokedAt = React.useRef<number>();\n\n React.useEffect(() => {\n const mentionSuggestionsCache = client[kInternal].mentionSuggestionsCache;\n const resolveMentionSuggestions =\n client[kInternal].resolveMentionSuggestions;\n\n if (search === undefined || !resolveMentionSuggestions) {\n return;\n }\n\n const resolveMentionSuggestionsArgs = { text: search, roomId: room.id };\n const mentionSuggestionsCacheKey = stringify(resolveMentionSuggestionsArgs);\n let debounceTimeout: number | undefined;\n let isCanceled = false;\n\n const getMentionSuggestions = async () => {\n try {\n lastInvokedAt.current = performance.now();\n const mentionSuggestions = await resolveMentionSuggestions(\n resolveMentionSuggestionsArgs\n );\n\n if (!isCanceled) {\n setMentionSuggestions(mentionSuggestions);\n mentionSuggestionsCache.set(\n mentionSuggestionsCacheKey,\n mentionSuggestions\n );\n }\n } catch (error) {\n console.error((error as Error)?.message);\n }\n };\n\n if (mentionSuggestionsCache.has(mentionSuggestionsCacheKey)) {\n // If there are already cached mention suggestions, use them immediately.\n setMentionSuggestions(\n mentionSuggestionsCache.get(mentionSuggestionsCacheKey)\n );\n } else if (\n !lastInvokedAt.current ||\n Math.abs(performance.now() - lastInvokedAt.current) >\n MENTION_SUGGESTIONS_DEBOUNCE\n ) {\n // If on the debounce's leading edge (either because it's the first invokation or enough\n // time has passed since the last debounce), get mention suggestions immediately.\n void getMentionSuggestions();\n } else {\n // Otherwise, wait for the debounce delay.\n debounceTimeout = window.setTimeout(() => {\n void getMentionSuggestions();\n }, MENTION_SUGGESTIONS_DEBOUNCE);\n }\n\n return () => {\n isCanceled = true;\n window.clearTimeout(debounceTimeout);\n };\n }, [client, room.id, search]);\n\n return mentionSuggestions;\n}\n"]}
@@ -0,0 +1,69 @@
1
+ import {
2
+ CreateThreadError,
3
+ _useRoom,
4
+ getUmbrellaStoreForClient,
5
+ selectThreads,
6
+ useClient
7
+ } from "./chunk-LMENFXCS.mjs";
8
+
9
+ // src/use-mention-suggestions.ts
10
+ import { kInternal, stringify } from "@liveblocks/core";
11
+ import React from "react";
12
+ var MENTION_SUGGESTIONS_DEBOUNCE = 500;
13
+ function useMentionSuggestions(search) {
14
+ const client = useClient();
15
+ const room = _useRoom();
16
+ const [mentionSuggestions, setMentionSuggestions] = React.useState();
17
+ const lastInvokedAt = React.useRef();
18
+ React.useEffect(() => {
19
+ const mentionSuggestionsCache = client[kInternal].mentionSuggestionsCache;
20
+ const resolveMentionSuggestions = client[kInternal].resolveMentionSuggestions;
21
+ if (search === void 0 || !resolveMentionSuggestions) {
22
+ return;
23
+ }
24
+ const resolveMentionSuggestionsArgs = { text: search, roomId: room.id };
25
+ const mentionSuggestionsCacheKey = stringify(resolveMentionSuggestionsArgs);
26
+ let debounceTimeout;
27
+ let isCanceled = false;
28
+ const getMentionSuggestions = async () => {
29
+ try {
30
+ lastInvokedAt.current = performance.now();
31
+ const mentionSuggestions2 = await resolveMentionSuggestions(
32
+ resolveMentionSuggestionsArgs
33
+ );
34
+ if (!isCanceled) {
35
+ setMentionSuggestions(mentionSuggestions2);
36
+ mentionSuggestionsCache.set(
37
+ mentionSuggestionsCacheKey,
38
+ mentionSuggestions2
39
+ );
40
+ }
41
+ } catch (error) {
42
+ console.error(error?.message);
43
+ }
44
+ };
45
+ if (mentionSuggestionsCache.has(mentionSuggestionsCacheKey)) {
46
+ setMentionSuggestions(
47
+ mentionSuggestionsCache.get(mentionSuggestionsCacheKey)
48
+ );
49
+ } else if (!lastInvokedAt.current || Math.abs(performance.now() - lastInvokedAt.current) > MENTION_SUGGESTIONS_DEBOUNCE) {
50
+ void getMentionSuggestions();
51
+ } else {
52
+ debounceTimeout = window.setTimeout(() => {
53
+ void getMentionSuggestions();
54
+ }, MENTION_SUGGESTIONS_DEBOUNCE);
55
+ }
56
+ return () => {
57
+ isCanceled = true;
58
+ window.clearTimeout(debounceTimeout);
59
+ };
60
+ }, [client, room.id, search]);
61
+ return mentionSuggestions;
62
+ }
63
+ export {
64
+ CreateThreadError,
65
+ getUmbrellaStoreForClient,
66
+ selectThreads,
67
+ useMentionSuggestions
68
+ };
69
+ //# sourceMappingURL=_private.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/use-mention-suggestions.ts"],"sourcesContent":["import { kInternal, stringify } from \"@liveblocks/core\";\nimport React from \"react\";\n\nimport { useClient } from \"./liveblocks\";\nimport { useRoom } from \"./room\";\n\nconst MENTION_SUGGESTIONS_DEBOUNCE = 500;\n\n/**\n * @private For internal use only. Do not rely on this hook.\n *\n * Simplistic debounced search, we don't need to worry too much about deduping\n * and race conditions as there can only be one search at a time.\n */\nexport function useMentionSuggestions(search?: string) {\n const client = useClient();\n\n const room = useRoom();\n const [mentionSuggestions, setMentionSuggestions] =\n React.useState<string[]>();\n const lastInvokedAt = React.useRef<number>();\n\n React.useEffect(() => {\n const mentionSuggestionsCache = client[kInternal].mentionSuggestionsCache;\n const resolveMentionSuggestions =\n client[kInternal].resolveMentionSuggestions;\n\n if (search === undefined || !resolveMentionSuggestions) {\n return;\n }\n\n const resolveMentionSuggestionsArgs = { text: search, roomId: room.id };\n const mentionSuggestionsCacheKey = stringify(resolveMentionSuggestionsArgs);\n let debounceTimeout: number | undefined;\n let isCanceled = false;\n\n const getMentionSuggestions = async () => {\n try {\n lastInvokedAt.current = performance.now();\n const mentionSuggestions = await resolveMentionSuggestions(\n resolveMentionSuggestionsArgs\n );\n\n if (!isCanceled) {\n setMentionSuggestions(mentionSuggestions);\n mentionSuggestionsCache.set(\n mentionSuggestionsCacheKey,\n mentionSuggestions\n );\n }\n } catch (error) {\n console.error((error as Error)?.message);\n }\n };\n\n if (mentionSuggestionsCache.has(mentionSuggestionsCacheKey)) {\n // If there are already cached mention suggestions, use them immediately.\n setMentionSuggestions(\n mentionSuggestionsCache.get(mentionSuggestionsCacheKey)\n );\n } else if (\n !lastInvokedAt.current ||\n Math.abs(performance.now() - lastInvokedAt.current) >\n MENTION_SUGGESTIONS_DEBOUNCE\n ) {\n // If on the debounce's leading edge (either because it's the first invokation or enough\n // time has passed since the last debounce), get mention suggestions immediately.\n void getMentionSuggestions();\n } else {\n // Otherwise, wait for the debounce delay.\n debounceTimeout = window.setTimeout(() => {\n void getMentionSuggestions();\n }, MENTION_SUGGESTIONS_DEBOUNCE);\n }\n\n return () => {\n isCanceled = true;\n window.clearTimeout(debounceTimeout);\n };\n }, [client, room.id, search]);\n\n return mentionSuggestions;\n}\n"],"mappings":";;;;;;;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