@liveblocks/react-lexical 2.18.2 → 2.18.4-uns1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/dist/{classnames.mjs → classnames.cjs} +4 -2
  2. package/dist/{classnames.mjs.map → classnames.cjs.map} +1 -1
  3. package/dist/classnames.js +1 -3
  4. package/dist/classnames.js.map +1 -1
  5. package/dist/comments/{anchored-threads.mjs → anchored-threads.cjs} +44 -41
  6. package/dist/comments/{anchored-threads.mjs.map → anchored-threads.cjs.map} +1 -1
  7. package/dist/comments/anchored-threads.js +40 -43
  8. package/dist/comments/anchored-threads.js.map +1 -1
  9. package/dist/comments/{comment-plugin-provider.mjs → comment-plugin-provider.cjs} +62 -55
  10. package/dist/comments/{comment-plugin-provider.mjs.map → comment-plugin-provider.cjs.map} +1 -1
  11. package/dist/comments/comment-plugin-provider.js +54 -61
  12. package/dist/comments/comment-plugin-provider.js.map +1 -1
  13. package/dist/comments/{floating-composer.mjs → floating-composer.cjs} +68 -64
  14. package/dist/comments/{floating-composer.mjs.map → floating-composer.cjs.map} +1 -1
  15. package/dist/comments/floating-composer.js +63 -67
  16. package/dist/comments/floating-composer.js.map +1 -1
  17. package/dist/comments/{floating-threads.mjs → floating-threads.cjs} +51 -48
  18. package/dist/comments/{floating-threads.mjs.map → floating-threads.cjs.map} +1 -1
  19. package/dist/comments/floating-threads.js +47 -50
  20. package/dist/comments/floating-threads.js.map +1 -1
  21. package/dist/comments/get-thread-mark-ids.cjs +23 -0
  22. package/dist/comments/{get-thread-mark-ids.mjs.map → get-thread-mark-ids.cjs.map} +1 -1
  23. package/dist/comments/get-thread-mark-ids.js +6 -8
  24. package/dist/comments/get-thread-mark-ids.js.map +1 -1
  25. package/dist/comments/{thread-mark-node.mjs → thread-mark-node.cjs} +10 -6
  26. package/dist/comments/{thread-mark-node.mjs.map → thread-mark-node.cjs.map} +1 -1
  27. package/dist/comments/thread-mark-node.js +5 -9
  28. package/dist/comments/thread-mark-node.js.map +1 -1
  29. package/dist/comments/{unwrap-thread-mark-node.mjs → unwrap-thread-mark-node.cjs} +4 -2
  30. package/dist/comments/unwrap-thread-mark-node.cjs.map +1 -0
  31. package/dist/comments/unwrap-thread-mark-node.js +1 -3
  32. package/dist/comments/unwrap-thread-mark-node.js.map +1 -1
  33. package/dist/comments/{wrap-selection-in-thread-mark-node.mjs → wrap-selection-in-thread-mark-node.cjs} +12 -10
  34. package/dist/comments/{wrap-selection-in-thread-mark-node.mjs.map → wrap-selection-in-thread-mark-node.cjs.map} +1 -1
  35. package/dist/comments/wrap-selection-in-thread-mark-node.js +9 -11
  36. package/dist/comments/wrap-selection-in-thread-mark-node.js.map +1 -1
  37. package/dist/{create-dom-range.mjs → create-dom-range.cjs} +7 -5
  38. package/dist/{create-dom-range.mjs.map → create-dom-range.cjs.map} +1 -1
  39. package/dist/create-dom-range.js +4 -6
  40. package/dist/create-dom-range.js.map +1 -1
  41. package/dist/{create-rects-from-dom-range.mjs → create-rects-from-dom-range.cjs} +4 -2
  42. package/dist/{create-rects-from-dom-range.mjs.map → create-rects-from-dom-range.cjs.map} +1 -1
  43. package/dist/create-rects-from-dom-range.js +1 -3
  44. package/dist/create-rects-from-dom-range.js.map +1 -1
  45. package/dist/index.cjs +33 -0
  46. package/dist/{index.mjs.map → index.cjs.map} +1 -1
  47. package/dist/{index.d.mts → index.d.cts} +0 -1
  48. package/dist/index.d.ts +0 -1
  49. package/dist/index.js +14 -31
  50. package/dist/index.js.map +1 -1
  51. package/dist/{is-block-node-active.mjs → is-block-node-active.cjs} +12 -10
  52. package/dist/{is-block-node-active.mjs.map → is-block-node-active.cjs.map} +1 -1
  53. package/dist/is-block-node-active.js +9 -11
  54. package/dist/is-block-node-active.js.map +1 -1
  55. package/dist/is-command-registered.cjs +11 -0
  56. package/dist/{is-command-registered.mjs.map → is-command-registered.cjs.map} +1 -1
  57. package/dist/is-command-registered.js +3 -5
  58. package/dist/is-command-registered.js.map +1 -1
  59. package/dist/is-text-format-active.cjs +16 -0
  60. package/dist/{is-text-format-active.mjs.map → is-text-format-active.cjs.map} +1 -1
  61. package/dist/is-text-format-active.js +4 -6
  62. package/dist/is-text-format-active.js.map +1 -1
  63. package/dist/liveblocks-config.cjs +17 -0
  64. package/dist/{liveblocks-config.mjs.map → liveblocks-config.cjs.map} +1 -1
  65. package/dist/liveblocks-config.js +4 -6
  66. package/dist/liveblocks-config.js.map +1 -1
  67. package/dist/liveblocks-plugin-provider.cjs +151 -0
  68. package/dist/liveblocks-plugin-provider.cjs.map +1 -0
  69. package/dist/liveblocks-plugin-provider.js +45 -66
  70. package/dist/liveblocks-plugin-provider.js.map +1 -1
  71. package/dist/mentions/{avatar.mjs → avatar.cjs} +16 -14
  72. package/dist/mentions/avatar.cjs.map +1 -0
  73. package/dist/mentions/avatar.js +13 -15
  74. package/dist/mentions/avatar.js.map +1 -1
  75. package/dist/mentions/mention-component.cjs +51 -0
  76. package/dist/mentions/{mention-component.mjs.map → mention-component.cjs.map} +1 -1
  77. package/dist/mentions/mention-component.js +14 -16
  78. package/dist/mentions/mention-component.js.map +1 -1
  79. package/dist/mentions/{mention-node.mjs → mention-node.cjs} +17 -13
  80. package/dist/mentions/mention-node.cjs.map +1 -0
  81. package/dist/mentions/mention-node.js +12 -16
  82. package/dist/mentions/mention-node.js.map +1 -1
  83. package/dist/mentions/{mention-plugin.mjs → mention-plugin.cjs} +81 -78
  84. package/dist/mentions/{mention-plugin.mjs.map → mention-plugin.cjs.map} +1 -1
  85. package/dist/mentions/mention-plugin.js +77 -80
  86. package/dist/mentions/mention-plugin.js.map +1 -1
  87. package/dist/mentions/{suggestions.mjs → suggestions.cjs} +43 -37
  88. package/dist/mentions/{suggestions.mjs.map → suggestions.cjs.map} +1 -1
  89. package/dist/mentions/suggestions.js +36 -42
  90. package/dist/mentions/suggestions.js.map +1 -1
  91. package/dist/mentions/user.cjs +26 -0
  92. package/dist/mentions/{user.mjs.map → user.cjs.map} +1 -1
  93. package/dist/mentions/user.js +11 -13
  94. package/dist/mentions/user.js.map +1 -1
  95. package/dist/toolbar/{floating-toolbar.mjs → floating-toolbar.cjs} +73 -70
  96. package/dist/toolbar/{floating-toolbar.mjs.map → floating-toolbar.cjs.map} +1 -1
  97. package/dist/toolbar/floating-toolbar.js +69 -72
  98. package/dist/toolbar/floating-toolbar.js.map +1 -1
  99. package/dist/toolbar/shared.cjs +36 -0
  100. package/dist/toolbar/{shared.mjs.map → shared.cjs.map} +1 -1
  101. package/dist/toolbar/shared.js +12 -15
  102. package/dist/toolbar/shared.js.map +1 -1
  103. package/dist/toolbar/toolbar.cjs +433 -0
  104. package/dist/toolbar/{toolbar.mjs.map → toolbar.cjs.map} +1 -1
  105. package/dist/toolbar/toolbar.js +131 -156
  106. package/dist/toolbar/toolbar.js.map +1 -1
  107. package/dist/use-root-element.cjs +21 -0
  108. package/dist/use-root-element.cjs.map +1 -0
  109. package/dist/use-root-element.js +7 -9
  110. package/dist/use-root-element.js.map +1 -1
  111. package/dist/version-history/{history-version-preview.mjs → history-version-preview.cjs} +53 -50
  112. package/dist/version-history/history-version-preview.cjs.map +1 -0
  113. package/dist/version-history/history-version-preview.js +50 -51
  114. package/dist/version-history/history-version-preview.js.map +1 -1
  115. package/dist/version.cjs +10 -0
  116. package/dist/{version.mjs.map → version.cjs.map} +1 -1
  117. package/dist/version.js +3 -7
  118. package/dist/version.js.map +1 -1
  119. package/package.json +24 -23
  120. package/styles.css.d.cts +1 -0
  121. package/dist/comments/get-thread-mark-ids.mjs +0 -21
  122. package/dist/comments/unwrap-thread-mark-node.mjs.map +0 -1
  123. package/dist/index.mjs +0 -16
  124. package/dist/is-command-registered.mjs +0 -9
  125. package/dist/is-text-format-active.mjs +0 -14
  126. package/dist/liveblocks-config.mjs +0 -15
  127. package/dist/liveblocks-plugin-provider.mjs +0 -164
  128. package/dist/liveblocks-plugin-provider.mjs.map +0 -1
  129. package/dist/mentions/avatar.mjs.map +0 -1
  130. package/dist/mentions/mention-component.mjs +0 -49
  131. package/dist/mentions/mention-node.mjs.map +0 -1
  132. package/dist/mentions/user.mjs +0 -24
  133. package/dist/toolbar/shared.mjs +0 -33
  134. package/dist/toolbar/toolbar.mjs +0 -408
  135. package/dist/use-root-element.mjs +0 -19
  136. package/dist/use-root-element.mjs.map +0 -1
  137. package/dist/version-history/history-version-preview.mjs.map +0 -1
  138. package/dist/version.mjs +0 -6
@@ -0,0 +1,151 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var reactDom = require('@floating-ui/react-dom');
5
+ var LexicalCollaborationPlugin = require('@lexical/react/LexicalCollaborationPlugin');
6
+ var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
7
+ var core = require('@liveblocks/core');
8
+ var react$1 = require('@liveblocks/react');
9
+ var _private = require('@liveblocks/react/_private');
10
+ var yjs = require('@liveblocks/yjs');
11
+ var react = require('react');
12
+ var commentPluginProvider = require('./comments/comment-plugin-provider.cjs');
13
+ var threadMarkNode = require('./comments/thread-mark-node.cjs');
14
+ var mentionNode = require('./mentions/mention-node.cjs');
15
+ var mentionPlugin = require('./mentions/mention-plugin.cjs');
16
+ var useRootElement = require('./use-root-element.cjs');
17
+
18
+ function useEditorStatus() {
19
+ const provider = _private.useYjsProvider();
20
+ const subscribe = react.useCallback(
21
+ (onStoreChange) => {
22
+ if (provider === void 0)
23
+ return () => {
24
+ };
25
+ provider.on("status", onStoreChange);
26
+ return () => {
27
+ provider.off("status", onStoreChange);
28
+ };
29
+ },
30
+ [provider]
31
+ );
32
+ const getSnapshot = react.useCallback(() => {
33
+ if (provider === void 0) {
34
+ return "not-loaded";
35
+ }
36
+ return provider.getStatus();
37
+ }, [provider]);
38
+ return react.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
39
+ }
40
+ function useIsEditorReady() {
41
+ const yjsProvider = _private.useYjsProvider();
42
+ const getSnapshot = react.useCallback(() => {
43
+ const status = yjsProvider?.getStatus();
44
+ return status === "synchronizing" || status === "synchronized";
45
+ }, [yjsProvider]);
46
+ const subscribe = react.useCallback(
47
+ (callback) => {
48
+ if (yjsProvider === void 0)
49
+ return () => {
50
+ };
51
+ yjsProvider.on("status", callback);
52
+ return () => {
53
+ yjsProvider.off("status", callback);
54
+ };
55
+ },
56
+ [yjsProvider]
57
+ );
58
+ return react.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
59
+ }
60
+ const LiveblocksPlugin = ({
61
+ children
62
+ }) => {
63
+ const isResolveMentionSuggestionsDefined = _private.useResolveMentionSuggestions() !== void 0;
64
+ const [editor] = LexicalComposerContext.useLexicalComposerContext();
65
+ const room = react$1.useRoom();
66
+ if (!editor.hasNodes([threadMarkNode.ThreadMarkNode, mentionNode.MentionNode])) {
67
+ throw new Error(
68
+ "LiveblocksPlugin requires Lexical configuration to be wrapped in the `liveblocksConfig(options)` function. For more information: https://liveblocks.io/docs/api-reference/liveblocks-react-lexical#liveblocksConfig"
69
+ );
70
+ }
71
+ const [containerRef, setContainerRef] = react.useState(void 0);
72
+ const {
73
+ refs: { setReference, setFloating },
74
+ strategy,
75
+ x,
76
+ y
77
+ } = reactDom.useFloating({
78
+ strategy: "fixed",
79
+ placement: "bottom",
80
+ whileElementsMounted: (...args) => {
81
+ return reactDom.autoUpdate(...args, {
82
+ animationFrame: true
83
+ });
84
+ }
85
+ });
86
+ react.useEffect(() => {
87
+ if (process.env.NODE_ENV !== "production") {
88
+ if (!editor.getEditorState().isEmpty()) {
89
+ console.warn(
90
+ "Warning: LiveblocksPlugin: editorState in initialConfig detected, but must be null."
91
+ );
92
+ }
93
+ }
94
+ }, []);
95
+ _private.useReportTextEditor(core.TextEditorType.Lexical, "root");
96
+ const self = react$1.useSelf();
97
+ const providerFactory = react.useCallback(
98
+ (id, yjsDocMap) => {
99
+ const provider = yjs.getYjsProviderForRoom(room);
100
+ yjsDocMap.set(id, provider.getYDoc());
101
+ return provider;
102
+ },
103
+ [room]
104
+ );
105
+ const root = useRootElement.useRootElement();
106
+ _private.useLayoutEffect(() => {
107
+ if (root === null)
108
+ return;
109
+ setReference({
110
+ getBoundingClientRect: () => root.getBoundingClientRect()
111
+ });
112
+ }, [setReference, root]);
113
+ const handleFloatingRef = react.useCallback(
114
+ (node) => {
115
+ setFloating(node);
116
+ setContainerRef({ current: node });
117
+ },
118
+ [setFloating, setContainerRef]
119
+ );
120
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
121
+ children: [
122
+ /* @__PURE__ */ jsxRuntime.jsx("div", {
123
+ ref: handleFloatingRef,
124
+ style: {
125
+ position: strategy,
126
+ top: 0,
127
+ left: 0,
128
+ transform: `translate3d(${Math.round(x)}px, ${Math.round(y)}px, 0)`,
129
+ minWidth: "max-content"
130
+ }
131
+ }),
132
+ self && /* @__PURE__ */ jsxRuntime.jsx(LexicalCollaborationPlugin.CollaborationPlugin, {
133
+ id: room.id,
134
+ providerFactory,
135
+ username: self.info?.name ?? "",
136
+ cursorColor: self.info?.color,
137
+ cursorsContainerRef: containerRef,
138
+ shouldBootstrap: true
139
+ }, room.id),
140
+ isResolveMentionSuggestionsDefined && /* @__PURE__ */ jsxRuntime.jsx(mentionPlugin.MentionPlugin, {}),
141
+ /* @__PURE__ */ jsxRuntime.jsx(commentPluginProvider.CommentPluginProvider, {
142
+ children
143
+ })
144
+ ]
145
+ });
146
+ };
147
+
148
+ exports.LiveblocksPlugin = LiveblocksPlugin;
149
+ exports.useEditorStatus = useEditorStatus;
150
+ exports.useIsEditorReady = useIsEditorReady;
151
+ //# sourceMappingURL=liveblocks-plugin-provider.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"liveblocks-plugin-provider.cjs","sources":["../src/liveblocks-plugin-provider.tsx"],"sourcesContent":["import { autoUpdate, useFloating } from \"@floating-ui/react-dom\";\nimport { CollaborationPlugin } from \"@lexical/react/LexicalCollaborationPlugin\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport type { Provider } from \"@lexical/yjs\";\nimport { TextEditorType } from \"@liveblocks/core\";\nimport { useRoom, useSelf } from \"@liveblocks/react\";\nimport {\n useLayoutEffect,\n useReportTextEditor,\n useResolveMentionSuggestions,\n useYjsProvider,\n} from \"@liveblocks/react/_private\";\nimport { getYjsProviderForRoom } from \"@liveblocks/yjs\";\nimport type { MutableRefObject, ReactNode } from \"react\";\nimport { useCallback, useEffect, useState, useSyncExternalStore } from \"react\";\nimport type { Doc } from \"yjs\";\n\nimport { CommentPluginProvider } from \"./comments/comment-plugin-provider\";\nimport { ThreadMarkNode } from \"./comments/thread-mark-node\";\nimport { MentionNode } from \"./mentions/mention-node\";\nimport { MentionPlugin } from \"./mentions/mention-plugin\";\nimport { useRootElement } from \"./use-root-element\";\n\nexport type EditorStatus =\n /* The editor state is not loaded and has not been requested. */\n | \"not-loaded\"\n /* The editor state is loading from Liveblocks servers */\n | \"loading\"\n /**\n * Not working yet! Will be available in a future release.\n * Some editor state modifications has not been acknowledged yet by the server\n */\n | \"synchronizing\"\n /* The editor state is sync with Liveblocks servers */\n | \"synchronized\";\n\n/**\n * Get the storage status.\n *\n * - `not-loaded`: Initial state when entering the room.\n * - `loading`: Once the editor state has been requested by LiveblocksPlugin.\n * - `synchronizing`: Not working yet! Will be available in a future release.\n * - `synchronized`: The editor state is sync with Liveblocks servers.\n *\n * @deprecated Prefer `useIsEditorReady` or `useSyncStatus` (from @liveblocks/react)\n */\nexport function useEditorStatus(): EditorStatus {\n const provider = useYjsProvider();\n\n const subscribe = useCallback(\n (onStoreChange: () => void) => {\n if (provider === undefined) return () => {};\n provider.on(\"status\", onStoreChange);\n return () => {\n provider.off(\"status\", onStoreChange);\n };\n },\n [provider]\n );\n\n const getSnapshot = useCallback(() => {\n if (provider === undefined) {\n return \"not-loaded\";\n }\n return provider.getStatus();\n }, [provider]);\n\n return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n\n/**\n * Returns whether the editor has loaded the initial text contents from the\n * server and is ready to be used.\n */\nexport function useIsEditorReady(): boolean {\n const yjsProvider = useYjsProvider();\n\n const getSnapshot = useCallback(() => {\n const status = yjsProvider?.getStatus();\n return status === \"synchronizing\" || status === \"synchronized\";\n }, [yjsProvider]);\n\n const subscribe = useCallback(\n (callback: () => void) => {\n if (yjsProvider === undefined) return () => {};\n yjsProvider.on(\"status\", callback);\n return () => {\n yjsProvider.off(\"status\", callback);\n };\n },\n [yjsProvider]\n );\n\n return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n\nexport type LiveblocksPluginProps = {\n children?: ReactNode;\n};\n\n/**\n * Liveblocks plugin for Lexical that adds collaboration to your editor.\n *\n * `LiveblocksPlugin` should always be nested inside `LexicalComposer`.\n *\n * @example\n *\n * import { LexicalComposer } from \"@lexical/react/LexicalComposer\";\n * import { RichTextPlugin } from \"@lexical/react/LexicalRichTextPlugin\";\n * import { ContentEditable } from \"@lexical/react/LexicalContentEditable\";\n * import { LexicalErrorBoundary } from \"@lexical/react/LexicalErrorBoundary\";\n * import { liveblocksConfig, LiveblocksPlugin } from \"@liveblocks/react-lexical\";\n *\n * const initialConfig = liveblocksConfig({\n * namespace: \"MyEditor\",\n * theme: {},\n * nodes: [],\n * onError: (err) => console.error(err),\n * });\n *\n * function Editor() {\n * return (\n * <LexicalComposer initialConfig={initialConfig}>\n * <LiveblocksPlugin />\n * <RichTextPlugin\n * contentEditable={<ContentEditable />}\n * placeholder={<div>Enter some text...</div>}\n * ErrorBoundary={LexicalErrorBoundary}\n * />\n * </LexicalComposer>\n * );\n * }\n */\nexport const LiveblocksPlugin = ({\n children,\n}: LiveblocksPluginProps): JSX.Element => {\n const isResolveMentionSuggestionsDefined =\n useResolveMentionSuggestions() !== undefined;\n const [editor] = useLexicalComposerContext();\n const room = useRoom();\n\n if (!editor.hasNodes([ThreadMarkNode, MentionNode])) {\n throw new Error(\n \"LiveblocksPlugin requires Lexical configuration to be wrapped in the `liveblocksConfig(options)` function. For more information: https://liveblocks.io/docs/api-reference/liveblocks-react-lexical#liveblocksConfig\"\n );\n }\n\n const [containerRef, setContainerRef] = useState<\n MutableRefObject<HTMLDivElement | null> | undefined\n >(undefined);\n\n const {\n refs: { setReference, setFloating },\n strategy,\n x,\n y,\n } = useFloating({\n strategy: \"fixed\",\n placement: \"bottom\",\n whileElementsMounted: (...args) => {\n return autoUpdate(...args, {\n animationFrame: true,\n });\n },\n });\n\n // Warn users if initialConfig.editorState, set on the composer, is not null\n useEffect(() => {\n // only in dev mode\n if (process.env.NODE_ENV !== \"production\") {\n // A user should not even be set an emptyState, but when passing null, getEditorState still has initial empty state\n if (!editor.getEditorState().isEmpty()) {\n console.warn(\n \"Warning: LiveblocksPlugin: editorState in initialConfig detected, but must be null.\"\n );\n }\n }\n\n // we know editor is already defined as we're inside LexicalComposer, and we only want this running the first time\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useReportTextEditor(TextEditorType.Lexical, \"root\");\n\n // Get user info or allow override from props\n const self = useSelf();\n\n const providerFactory = useCallback(\n (id: string, yjsDocMap: Map<string, Doc>): Provider => {\n const provider = getYjsProviderForRoom(room);\n yjsDocMap.set(id, provider.getYDoc());\n\n return provider as Provider;\n },\n [room]\n );\n\n const root = useRootElement();\n\n useLayoutEffect(() => {\n if (root === null) return;\n setReference({\n getBoundingClientRect: () => root.getBoundingClientRect(),\n });\n }, [setReference, root]);\n\n const handleFloatingRef = useCallback(\n (node: HTMLDivElement) => {\n setFloating(node);\n setContainerRef({ current: node });\n },\n [setFloating, setContainerRef]\n );\n\n return (\n <>\n <div\n ref={handleFloatingRef}\n style={{\n position: strategy,\n top: 0,\n left: 0,\n transform: `translate3d(${Math.round(x)}px, ${Math.round(y)}px, 0)`,\n minWidth: \"max-content\",\n }}\n />\n\n {self && (\n <CollaborationPlugin\n // Setting the key allows us to reset the internal Y.doc used by useYjsCollaboration\n // without implementing `reload` event\n key={room.id}\n id={room.id}\n providerFactory={providerFactory}\n username={self.info?.name ?? \"\"} // use empty string to prevent random name\n cursorColor={self.info?.color as string | undefined}\n cursorsContainerRef={containerRef}\n shouldBootstrap={true}\n />\n )}\n\n {isResolveMentionSuggestionsDefined && <MentionPlugin />}\n <CommentPluginProvider>{children}</CommentPluginProvider>\n </>\n );\n};\n"],"names":["useYjsProvider","useCallback","useSyncExternalStore","useResolveMentionSuggestions","useLexicalComposerContext","useRoom","ThreadMarkNode","MentionNode","useState","useFloating","autoUpdate","useEffect","useReportTextEditor","TextEditorType","useSelf","getYjsProviderForRoom","useRootElement","useLayoutEffect","jsxs","Fragment","jsx","CollaborationPlugin","MentionPlugin","CommentPluginProvider"],"mappings":";;;;;;;;;;;;;;;;;AA8CO,SAAS,eAAgC,GAAA;AAC9C,EAAA,MAAM,WAAWA,uBAAe,EAAA,CAAA;AAEhC,EAAA,MAAM,SAAY,GAAAC,iBAAA;AAAA,IAChB,CAAC,aAA8B,KAAA;AAC7B,MAAA,IAAI,QAAa,KAAA,KAAA,CAAA;AAAW,QAAA,OAAO,MAAM;AAAA,SAAC,CAAA;AAC1C,MAAS,QAAA,CAAA,EAAA,CAAG,UAAU,aAAa,CAAA,CAAA;AACnC,MAAA,OAAO,MAAM;AACX,QAAS,QAAA,CAAA,GAAA,CAAI,UAAU,aAAa,CAAA,CAAA;AAAA,OACtC,CAAA;AAAA,KACF;AAAA,IACA,CAAC,QAAQ,CAAA;AAAA,GACX,CAAA;AAEA,EAAM,MAAA,WAAA,GAAcA,kBAAY,MAAM;AACpC,IAAA,IAAI,aAAa,KAAW,CAAA,EAAA;AAC1B,MAAO,OAAA,YAAA,CAAA;AAAA,KACT;AACA,IAAA,OAAO,SAAS,SAAU,EAAA,CAAA;AAAA,GAC5B,EAAG,CAAC,QAAQ,CAAC,CAAA,CAAA;AAEb,EAAO,OAAAC,0BAAA,CAAqB,SAAW,EAAA,WAAA,EAAa,WAAW,CAAA,CAAA;AACjE,CAAA;AAMO,SAAS,gBAA4B,GAAA;AAC1C,EAAA,MAAM,cAAcF,uBAAe,EAAA,CAAA;AAEnC,EAAM,MAAA,WAA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AAAA,GACnC,CAAA,CAAA;AAEJ;;;;;;"}
@@ -1,25 +1,21 @@
1
- 'use strict';
1
+ import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
2
+ import { useFloating, autoUpdate } from '@floating-ui/react-dom';
3
+ import { CollaborationPlugin } from '@lexical/react/LexicalCollaborationPlugin';
4
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
5
+ import { TextEditorType } from '@liveblocks/core';
6
+ import { useRoom, useSelf } from '@liveblocks/react';
7
+ import { useYjsProvider, useResolveMentionSuggestions, useReportTextEditor, useLayoutEffect } from '@liveblocks/react/_private';
8
+ import { getYjsProviderForRoom } from '@liveblocks/yjs';
9
+ import { useCallback, useSyncExternalStore, useState, useEffect } from 'react';
10
+ import { CommentPluginProvider } from './comments/comment-plugin-provider.js';
11
+ import { ThreadMarkNode } from './comments/thread-mark-node.js';
12
+ import { MentionNode } from './mentions/mention-node.js';
13
+ import { MentionPlugin } from './mentions/mention-plugin.js';
14
+ import { useRootElement } from './use-root-element.js';
2
15
 
3
- var jsxRuntime = require('react/jsx-runtime');
4
- var reactDom = require('@floating-ui/react-dom');
5
- var LexicalCollaborationPlugin = require('@lexical/react/LexicalCollaborationPlugin');
6
- var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
7
- var core = require('@liveblocks/core');
8
- var react$1 = require('@liveblocks/react');
9
- var _private = require('@liveblocks/react/_private');
10
- var yjs$1 = require('@liveblocks/yjs');
11
- var react = require('react');
12
- var yjs = require('yjs');
13
- var commentPluginProvider = require('./comments/comment-plugin-provider.js');
14
- var threadMarkNode = require('./comments/thread-mark-node.js');
15
- var mentionNode = require('./mentions/mention-node.js');
16
- var mentionPlugin = require('./mentions/mention-plugin.js');
17
- var useRootElement = require('./use-root-element.js');
18
-
19
- const providersMap = /* @__PURE__ */ new Map();
20
16
  function useEditorStatus() {
21
- const provider = _private.useYjsProvider();
22
- const subscribe = react.useCallback(
17
+ const provider = useYjsProvider();
18
+ const subscribe = useCallback(
23
19
  (onStoreChange) => {
24
20
  if (provider === void 0)
25
21
  return () => {
@@ -31,21 +27,21 @@ function useEditorStatus() {
31
27
  },
32
28
  [provider]
33
29
  );
34
- const getSnapshot = react.useCallback(() => {
30
+ const getSnapshot = useCallback(() => {
35
31
  if (provider === void 0) {
36
32
  return "not-loaded";
37
33
  }
38
34
  return provider.getStatus();
39
35
  }, [provider]);
40
- return react.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
36
+ return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
41
37
  }
42
38
  function useIsEditorReady() {
43
- const yjsProvider = _private.useYjsProvider();
44
- const getSnapshot = react.useCallback(() => {
39
+ const yjsProvider = useYjsProvider();
40
+ const getSnapshot = useCallback(() => {
45
41
  const status = yjsProvider?.getStatus();
46
42
  return status === "synchronizing" || status === "synchronized";
47
43
  }, [yjsProvider]);
48
- const subscribe = react.useCallback(
44
+ const subscribe = useCallback(
49
45
  (callback) => {
50
46
  if (yjsProvider === void 0)
51
47
  return () => {
@@ -57,36 +53,35 @@ function useIsEditorReady() {
57
53
  },
58
54
  [yjsProvider]
59
55
  );
60
- return react.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
56
+ return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
61
57
  }
62
58
  const LiveblocksPlugin = ({
63
59
  children
64
60
  }) => {
65
- const isResolveMentionSuggestionsDefined = _private.useResolveMentionSuggestions() !== void 0;
66
- const [editor] = LexicalComposerContext.useLexicalComposerContext();
67
- const room = react$1.useRoom();
68
- const previousRoomIdRef = react.useRef(null);
69
- if (!editor.hasNodes([threadMarkNode.ThreadMarkNode, mentionNode.MentionNode])) {
61
+ const isResolveMentionSuggestionsDefined = useResolveMentionSuggestions() !== void 0;
62
+ const [editor] = useLexicalComposerContext();
63
+ const room = useRoom();
64
+ if (!editor.hasNodes([ThreadMarkNode, MentionNode])) {
70
65
  throw new Error(
71
66
  "LiveblocksPlugin requires Lexical configuration to be wrapped in the `liveblocksConfig(options)` function. For more information: https://liveblocks.io/docs/api-reference/liveblocks-react-lexical#liveblocksConfig"
72
67
  );
73
68
  }
74
- const [containerRef, setContainerRef] = react.useState(void 0);
69
+ const [containerRef, setContainerRef] = useState(void 0);
75
70
  const {
76
71
  refs: { setReference, setFloating },
77
72
  strategy,
78
73
  x,
79
74
  y
80
- } = reactDom.useFloating({
75
+ } = useFloating({
81
76
  strategy: "fixed",
82
77
  placement: "bottom",
83
78
  whileElementsMounted: (...args) => {
84
- return reactDom.autoUpdate(...args, {
79
+ return autoUpdate(...args, {
85
80
  animationFrame: true
86
81
  });
87
82
  }
88
83
  });
89
- react.useEffect(() => {
84
+ useEffect(() => {
90
85
  if (process.env.NODE_ENV !== "production") {
91
86
  if (!editor.getEditorState().isEmpty()) {
92
87
  console.warn(
@@ -95,48 +90,34 @@ const LiveblocksPlugin = ({
95
90
  }
96
91
  }
97
92
  }, []);
98
- _private.useReportTextEditor(core.TextEditorType.Lexical, "root");
99
- const self = react$1.useSelf();
100
- const providerFactory = react.useCallback(
93
+ useReportTextEditor(TextEditorType.Lexical, "root");
94
+ const self = useSelf();
95
+ const providerFactory = useCallback(
101
96
  (id, yjsDocMap) => {
102
- if (previousRoomIdRef.current !== null && previousRoomIdRef.current !== id) {
103
- const previousProvider = providersMap.get(id);
104
- if (previousProvider !== void 0) {
105
- previousProvider.destroy();
106
- }
107
- }
108
- let doc = yjsDocMap.get(id);
109
- if (doc === void 0) {
110
- doc = new yjs.Doc();
111
- const provider = new yjs$1.LiveblocksYjsProvider(room, doc);
112
- yjsDocMap.set(id, doc);
113
- providersMap.set(id, provider);
114
- }
115
- return core.nn(
116
- providersMap.get(id),
117
- "Internal error. Should never happen"
118
- );
97
+ const provider = getYjsProviderForRoom(room);
98
+ yjsDocMap.set(id, provider.getYDoc());
99
+ return provider;
119
100
  },
120
101
  [room]
121
102
  );
122
- const root = useRootElement.useRootElement();
123
- _private.useLayoutEffect(() => {
103
+ const root = useRootElement();
104
+ useLayoutEffect(() => {
124
105
  if (root === null)
125
106
  return;
126
107
  setReference({
127
108
  getBoundingClientRect: () => root.getBoundingClientRect()
128
109
  });
129
110
  }, [setReference, root]);
130
- const handleFloatingRef = react.useCallback(
111
+ const handleFloatingRef = useCallback(
131
112
  (node) => {
132
113
  setFloating(node);
133
114
  setContainerRef({ current: node });
134
115
  },
135
116
  [setFloating, setContainerRef]
136
117
  );
137
- return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
118
+ return /* @__PURE__ */ jsxs(Fragment, {
138
119
  children: [
139
- /* @__PURE__ */ jsxRuntime.jsx("div", {
120
+ /* @__PURE__ */ jsx("div", {
140
121
  ref: handleFloatingRef,
141
122
  style: {
142
123
  position: strategy,
@@ -146,7 +127,7 @@ const LiveblocksPlugin = ({
146
127
  minWidth: "max-content"
147
128
  }
148
129
  }),
149
- self && /* @__PURE__ */ jsxRuntime.jsx(LexicalCollaborationPlugin.CollaborationPlugin, {
130
+ self && /* @__PURE__ */ jsx(CollaborationPlugin, {
150
131
  id: room.id,
151
132
  providerFactory,
152
133
  username: self.info?.name ?? "",
@@ -154,15 +135,13 @@ const LiveblocksPlugin = ({
154
135
  cursorsContainerRef: containerRef,
155
136
  shouldBootstrap: true
156
137
  }, room.id),
157
- isResolveMentionSuggestionsDefined && /* @__PURE__ */ jsxRuntime.jsx(mentionPlugin.MentionPlugin, {}),
158
- /* @__PURE__ */ jsxRuntime.jsx(commentPluginProvider.CommentPluginProvider, {
138
+ isResolveMentionSuggestionsDefined && /* @__PURE__ */ jsx(MentionPlugin, {}),
139
+ /* @__PURE__ */ jsx(CommentPluginProvider, {
159
140
  children
160
141
  })
161
142
  ]
162
143
  });
163
144
  };
164
145
 
165
- exports.LiveblocksPlugin = LiveblocksPlugin;
166
- exports.useEditorStatus = useEditorStatus;
167
- exports.useIsEditorReady = useIsEditorReady;
146
+ export { LiveblocksPlugin, useEditorStatus, useIsEditorReady };
168
147
  //# sourceMappingURL=liveblocks-plugin-provider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"liveblocks-plugin-provider.js","sources":["../src/liveblocks-plugin-provider.tsx"],"sourcesContent":["import { autoUpdate, useFloating } from \"@floating-ui/react-dom\";\nimport { CollaborationPlugin } from \"@lexical/react/LexicalCollaborationPlugin\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport type { Provider } from \"@lexical/yjs\";\nimport { nn, TextEditorType } from \"@liveblocks/core\";\nimport { useRoom, useSelf } from \"@liveblocks/react\";\nimport {\n useLayoutEffect,\n useReportTextEditor,\n useResolveMentionSuggestions,\n useYjsProvider,\n} from \"@liveblocks/react/_private\";\nimport { LiveblocksYjsProvider } from \"@liveblocks/yjs\";\nimport type { MutableRefObject, ReactNode } from \"react\";\nimport {\n useCallback,\n useEffect,\n useRef,\n useState,\n useSyncExternalStore,\n} from \"react\";\nimport { Doc } from \"yjs\";\n\nimport { CommentPluginProvider } from \"./comments/comment-plugin-provider\";\nimport { ThreadMarkNode } from \"./comments/thread-mark-node\";\nimport { MentionNode } from \"./mentions/mention-node\";\nimport { MentionPlugin } from \"./mentions/mention-plugin\";\nimport { useRootElement } from \"./use-root-element\";\n\n// TODO: Replace by ref once I understand why useRef is not stable (?!)\nconst providersMap = new Map<\n string,\n LiveblocksYjsProvider\n>();\n\nexport type EditorStatus =\n /* The editor state is not loaded and has not been requested. */\n | \"not-loaded\"\n /* The editor state is loading from Liveblocks servers */\n | \"loading\"\n /**\n * Not working yet! Will be available in a future release.\n * Some editor state modifications has not been acknowledged yet by the server\n */\n | \"synchronizing\"\n /* The editor state is sync with Liveblocks servers */\n | \"synchronized\";\n\n/**\n * Get the storage status.\n *\n * - `not-loaded`: Initial state when entering the room.\n * - `loading`: Once the editor state has been requested by LiveblocksPlugin.\n * - `synchronizing`: Not working yet! Will be available in a future release.\n * - `synchronized`: The editor state is sync with Liveblocks servers.\n *\n * @deprecated Prefer `useIsEditorReady` or `useSyncStatus` (from @liveblocks/react)\n */\nexport function useEditorStatus(): EditorStatus {\n const provider = useYjsProvider();\n\n const subscribe = useCallback(\n (onStoreChange: () => void) => {\n if (provider === undefined) return () => { };\n provider.on(\"status\", onStoreChange);\n return () => {\n provider.off(\"status\", onStoreChange);\n };\n },\n [provider]\n );\n\n const getSnapshot = useCallback(() => {\n if (provider === undefined) {\n return \"not-loaded\";\n }\n return provider.getStatus();\n }, [provider]);\n\n return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n\n/**\n * Returns whether the editor has loaded the initial text contents from the\n * server and is ready to be used.\n */\nexport function useIsEditorReady(): boolean {\n const yjsProvider = useYjsProvider();\n\n const getSnapshot = useCallback(() => {\n const status = yjsProvider?.getStatus();\n return status === \"synchronizing\" || status === \"synchronized\";\n }, [yjsProvider]);\n\n const subscribe = useCallback(\n (callback: () => void) => {\n if (yjsProvider === undefined) return () => { };\n yjsProvider.on(\"status\", callback);\n return () => {\n yjsProvider.off(\"status\", callback);\n };\n },\n [yjsProvider]\n );\n\n return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n\nexport type LiveblocksPluginProps = {\n children?: ReactNode;\n};\n\n/**\n * Liveblocks plugin for Lexical that adds collaboration to your editor.\n *\n * `LiveblocksPlugin` should always be nested inside `LexicalComposer`.\n *\n * @example\n *\n * import { LexicalComposer } from \"@lexical/react/LexicalComposer\";\n * import { RichTextPlugin } from \"@lexical/react/LexicalRichTextPlugin\";\n * import { ContentEditable } from \"@lexical/react/LexicalContentEditable\";\n * import { LexicalErrorBoundary } from \"@lexical/react/LexicalErrorBoundary\";\n * import { liveblocksConfig, LiveblocksPlugin } from \"@liveblocks/react-lexical\";\n *\n * const initialConfig = liveblocksConfig({\n * namespace: \"MyEditor\",\n * theme: {},\n * nodes: [],\n * onError: (err) => console.error(err),\n * });\n *\n * function Editor() {\n * return (\n * <LexicalComposer initialConfig={initialConfig}>\n * <LiveblocksPlugin />\n * <RichTextPlugin\n * contentEditable={<ContentEditable />}\n * placeholder={<div>Enter some text...</div>}\n * ErrorBoundary={LexicalErrorBoundary}\n * />\n * </LexicalComposer>\n * );\n * }\n */\nexport const LiveblocksPlugin = ({\n children,\n}: LiveblocksPluginProps): JSX.Element => {\n const isResolveMentionSuggestionsDefined =\n useResolveMentionSuggestions() !== undefined;\n const [editor] = useLexicalComposerContext();\n const room = useRoom();\n const previousRoomIdRef = useRef<string | null>(null);\n\n if (!editor.hasNodes([ThreadMarkNode, MentionNode])) {\n throw new Error(\n \"LiveblocksPlugin requires Lexical configuration to be wrapped in the `liveblocksConfig(options)` function. For more information: https://liveblocks.io/docs/api-reference/liveblocks-react-lexical#liveblocksConfig\"\n );\n }\n\n const [containerRef, setContainerRef] = useState<\n MutableRefObject<HTMLDivElement | null> | undefined\n >(undefined);\n\n const {\n refs: { setReference, setFloating },\n strategy,\n x,\n y,\n } = useFloating({\n strategy: \"fixed\",\n placement: \"bottom\",\n whileElementsMounted: (...args) => {\n return autoUpdate(...args, {\n animationFrame: true,\n });\n },\n });\n\n // Warn users if initialConfig.editorState, set on the composer, is not null\n useEffect(() => {\n // only in dev mode\n if (process.env.NODE_ENV !== \"production\") {\n // A user should not even be set an emptyState, but when passing null, getEditorState still has initial empty state\n if (!editor.getEditorState().isEmpty()) {\n console.warn(\n \"Warning: LiveblocksPlugin: editorState in initialConfig detected, but must be null.\"\n );\n }\n }\n\n // we know editor is already defined as we're inside LexicalComposer, and we only want this running the first time\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useReportTextEditor(TextEditorType.Lexical, \"root\");\n\n // Get user info or allow override from props\n const self = useSelf();\n\n const providerFactory = useCallback(\n (id: string, yjsDocMap: Map<string, Doc>): Provider => {\n // Destroy previously used provider to avoid memory leaks\n // TODO: Find a way to destroy the last used provider on unmount (while working with StrictMode)\n if (\n previousRoomIdRef.current !== null &&\n previousRoomIdRef.current !== id\n ) {\n const previousProvider = providersMap.get(id);\n if (previousProvider !== undefined) {\n previousProvider.destroy();\n }\n }\n\n let doc = yjsDocMap.get(id);\n\n if (doc === undefined) {\n doc = new Doc();\n const provider = new LiveblocksYjsProvider(room, doc);\n yjsDocMap.set(id, doc);\n providersMap.set(id, provider);\n }\n\n return nn(\n providersMap.get(id),\n \"Internal error. Should never happen\"\n ) as Provider;\n },\n [room]\n );\n\n const root = useRootElement();\n\n useLayoutEffect(() => {\n if (root === null) return;\n setReference({\n getBoundingClientRect: () => root.getBoundingClientRect(),\n });\n }, [setReference, root]);\n\n const handleFloatingRef = useCallback(\n (node: HTMLDivElement) => {\n setFloating(node);\n setContainerRef({ current: node });\n },\n [setFloating, setContainerRef]\n );\n\n return (\n <>\n <div\n ref={handleFloatingRef}\n style={{\n position: strategy,\n top: 0,\n left: 0,\n transform: `translate3d(${Math.round(x)}px, ${Math.round(y)}px, 0)`,\n minWidth: \"max-content\",\n }}\n />\n\n {self && (\n <CollaborationPlugin\n // Setting the key allows us to reset the internal Y.doc used by useYjsCollaboration\n // without implementing `reload` event\n key={room.id}\n id={room.id}\n providerFactory={providerFactory}\n username={self.info?.name ?? \"\"} // use empty string to prevent random name\n cursorColor={self.info?.color as string | undefined}\n cursorsContainerRef={containerRef}\n shouldBootstrap={true}\n />\n )}\n\n {isResolveMentionSuggestionsDefined && <MentionPlugin />}\n <CommentPluginProvider>{children}</CommentPluginProvider>\n </>\n );\n};\n"],"names":["useYjsProvider","useCallback","useSyncExternalStore","useResolveMentionSuggestions","useLexicalComposerContext","useRoom","useRef","ThreadMarkNode","MentionNode","useState","useFloating","autoUpdate","useEffect","useReportTextEditor","TextEditorType","useSelf","Doc","LiveblocksYjsProvider","nn","useRootElement","useLayoutEffect","jsxs","Fragment","jsx","CollaborationPlugin","MentionPlugin","CommentPluginProvider"],"mappings":";;;;;;;;;;;;;;;;;;AA8BA,MAAM,YAAA,uBAAmB,GAGvB,EAAA,CAAA;AAyBK,SAAS,eAAgC,GAAA;AAC9C,EAAA,MAAM,WAAWA,uBAAe,EAAA,CAAA;AAEhC,EAAA,MAAM,SAAY,GAAAC,iBAAA;AAAA,IAChB,CAAC,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,MAGD,kCAAA,mCAAuCC,2BAAc,EAAA,EAAA,CAAA;AAAA,sBACrDF,cAAA,CAAAG,2CAAA,EAAA;AAAA,QAAuB,QAAA;AAAA,OAAS,CAAA;AAAA,KAAA;AAAA,GACnC,CAAA,CAAA;AAEJ;;;;;;"}
1
+ {"version":3,"file":"liveblocks-plugin-provider.js","sources":["../src/liveblocks-plugin-provider.tsx"],"sourcesContent":["import { autoUpdate, useFloating } from \"@floating-ui/react-dom\";\nimport { CollaborationPlugin } from \"@lexical/react/LexicalCollaborationPlugin\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport type { Provider } from \"@lexical/yjs\";\nimport { TextEditorType } from \"@liveblocks/core\";\nimport { useRoom, useSelf } from \"@liveblocks/react\";\nimport {\n useLayoutEffect,\n useReportTextEditor,\n useResolveMentionSuggestions,\n useYjsProvider,\n} from \"@liveblocks/react/_private\";\nimport { getYjsProviderForRoom } from \"@liveblocks/yjs\";\nimport type { MutableRefObject, ReactNode } from \"react\";\nimport { useCallback, useEffect, useState, useSyncExternalStore } from \"react\";\nimport type { Doc } from \"yjs\";\n\nimport { CommentPluginProvider } from \"./comments/comment-plugin-provider\";\nimport { ThreadMarkNode } from \"./comments/thread-mark-node\";\nimport { MentionNode } from \"./mentions/mention-node\";\nimport { MentionPlugin } from \"./mentions/mention-plugin\";\nimport { useRootElement } from \"./use-root-element\";\n\nexport type EditorStatus =\n /* The editor state is not loaded and has not been requested. */\n | \"not-loaded\"\n /* The editor state is loading from Liveblocks servers */\n | \"loading\"\n /**\n * Not working yet! Will be available in a future release.\n * Some editor state modifications has not been acknowledged yet by the server\n */\n | \"synchronizing\"\n /* The editor state is sync with Liveblocks servers */\n | \"synchronized\";\n\n/**\n * Get the storage status.\n *\n * - `not-loaded`: Initial state when entering the room.\n * - `loading`: Once the editor state has been requested by LiveblocksPlugin.\n * - `synchronizing`: Not working yet! Will be available in a future release.\n * - `synchronized`: The editor state is sync with Liveblocks servers.\n *\n * @deprecated Prefer `useIsEditorReady` or `useSyncStatus` (from @liveblocks/react)\n */\nexport function useEditorStatus(): EditorStatus {\n const provider = useYjsProvider();\n\n const subscribe = useCallback(\n (onStoreChange: () => void) => {\n if (provider === undefined) return () => {};\n provider.on(\"status\", onStoreChange);\n return () => {\n provider.off(\"status\", onStoreChange);\n };\n },\n [provider]\n );\n\n const getSnapshot = useCallback(() => {\n if (provider === undefined) {\n return \"not-loaded\";\n }\n return provider.getStatus();\n }, [provider]);\n\n return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n\n/**\n * Returns whether the editor has loaded the initial text contents from the\n * server and is ready to be used.\n */\nexport function useIsEditorReady(): boolean {\n const yjsProvider = useYjsProvider();\n\n const getSnapshot = useCallback(() => {\n const status = yjsProvider?.getStatus();\n return status === \"synchronizing\" || status === \"synchronized\";\n }, [yjsProvider]);\n\n const subscribe = useCallback(\n (callback: () => void) => {\n if (yjsProvider === undefined) return () => {};\n yjsProvider.on(\"status\", callback);\n return () => {\n yjsProvider.off(\"status\", callback);\n };\n },\n [yjsProvider]\n );\n\n return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n\nexport type LiveblocksPluginProps = {\n children?: ReactNode;\n};\n\n/**\n * Liveblocks plugin for Lexical that adds collaboration to your editor.\n *\n * `LiveblocksPlugin` should always be nested inside `LexicalComposer`.\n *\n * @example\n *\n * import { LexicalComposer } from \"@lexical/react/LexicalComposer\";\n * import { RichTextPlugin } from \"@lexical/react/LexicalRichTextPlugin\";\n * import { ContentEditable } from \"@lexical/react/LexicalContentEditable\";\n * import { LexicalErrorBoundary } from \"@lexical/react/LexicalErrorBoundary\";\n * import { liveblocksConfig, LiveblocksPlugin } from \"@liveblocks/react-lexical\";\n *\n * const initialConfig = liveblocksConfig({\n * namespace: \"MyEditor\",\n * theme: {},\n * nodes: [],\n * onError: (err) => console.error(err),\n * });\n *\n * function Editor() {\n * return (\n * <LexicalComposer initialConfig={initialConfig}>\n * <LiveblocksPlugin />\n * <RichTextPlugin\n * contentEditable={<ContentEditable />}\n * placeholder={<div>Enter some text...</div>}\n * ErrorBoundary={LexicalErrorBoundary}\n * />\n * </LexicalComposer>\n * );\n * }\n */\nexport const LiveblocksPlugin = ({\n children,\n}: LiveblocksPluginProps): JSX.Element => {\n const isResolveMentionSuggestionsDefined =\n useResolveMentionSuggestions() !== undefined;\n const [editor] = useLexicalComposerContext();\n const room = useRoom();\n\n if (!editor.hasNodes([ThreadMarkNode, MentionNode])) {\n throw new Error(\n \"LiveblocksPlugin requires Lexical configuration to be wrapped in the `liveblocksConfig(options)` function. For more information: https://liveblocks.io/docs/api-reference/liveblocks-react-lexical#liveblocksConfig\"\n );\n }\n\n const [containerRef, setContainerRef] = useState<\n MutableRefObject<HTMLDivElement | null> | undefined\n >(undefined);\n\n const {\n refs: { setReference, setFloating },\n strategy,\n x,\n y,\n } = useFloating({\n strategy: \"fixed\",\n placement: \"bottom\",\n whileElementsMounted: (...args) => {\n return autoUpdate(...args, {\n animationFrame: true,\n });\n },\n });\n\n // Warn users if initialConfig.editorState, set on the composer, is not null\n useEffect(() => {\n // only in dev mode\n if (process.env.NODE_ENV !== \"production\") {\n // A user should not even be set an emptyState, but when passing null, getEditorState still has initial empty state\n if (!editor.getEditorState().isEmpty()) {\n console.warn(\n \"Warning: LiveblocksPlugin: editorState in initialConfig detected, but must be null.\"\n );\n }\n }\n\n // we know editor is already defined as we're inside LexicalComposer, and we only want this running the first time\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useReportTextEditor(TextEditorType.Lexical, \"root\");\n\n // Get user info or allow override from props\n const self = useSelf();\n\n const providerFactory = useCallback(\n (id: string, yjsDocMap: Map<string, Doc>): Provider => {\n const provider = getYjsProviderForRoom(room);\n yjsDocMap.set(id, provider.getYDoc());\n\n return provider as Provider;\n },\n [room]\n );\n\n const root = useRootElement();\n\n useLayoutEffect(() => {\n if (root === null) return;\n setReference({\n getBoundingClientRect: () => root.getBoundingClientRect(),\n });\n }, [setReference, root]);\n\n const handleFloatingRef = useCallback(\n (node: HTMLDivElement) => {\n setFloating(node);\n setContainerRef({ current: node });\n },\n [setFloating, setContainerRef]\n );\n\n return (\n <>\n <div\n ref={handleFloatingRef}\n style={{\n position: strategy,\n top: 0,\n left: 0,\n transform: `translate3d(${Math.round(x)}px, ${Math.round(y)}px, 0)`,\n minWidth: \"max-content\",\n }}\n />\n\n {self && (\n <CollaborationPlugin\n // Setting the key allows us to reset the internal Y.doc used by useYjsCollaboration\n // without implementing `reload` event\n key={room.id}\n id={room.id}\n providerFactory={providerFactory}\n username={self.info?.name ?? \"\"} // use empty string to prevent random name\n cursorColor={self.info?.color as string | undefined}\n cursorsContainerRef={containerRef}\n shouldBootstrap={true}\n />\n )}\n\n {isResolveMentionSuggestionsDefined && <MentionPlugin />}\n <CommentPluginProvider>{children}</CommentPluginProvider>\n </>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AA8CO,SAAS,eAAgC,GAAA;AAC9C,EAAA,MAAM,WAAW,cAAe,EAAA,CAAA;AAEhC,EAAA,MAAM,SAAY,GAAA,WAAA;AAAA,IAChB,CAAC,aAA8B,KAAA;AAC7B,MAAA,IAAI,QAAa,KAAA,KAAA,CAAA;AAAW,QAAA,OAAO,MAAM;AAAA,SAAC,CAAA;AAC1C,MAAS,QAAA,CAAA,EAAA,CAAG,UAAU,aAAa,CAAA,CAAA;AACnC,MAAA,OAAO,MAAM;AACX,QAAS,QAAA,CAAA,GAAA,CAAI,UAAU,aAAa,CAAA,CAAA;AAAA,OACtC,CAAA;AAAA,KACF;AAAA,IACA,CAAC,QAAQ,CAAA;AAAA,GACX,CAAA;AAEA,EAAM,MAAA,WAAA,GAAc,YAAY,MAAM;AACpC,IAAA,IAAI,aAAa,KAAW,CAAA,EAAA;AAC1B,MAAO,OAAA,YAAA,CAAA;AAAA,KACT;AACA,IAAA,OAAO,SAAS,SAAU,EAAA,CAAA;AAAA,GAC5B,EAAG,CAAC,QAAQ,CAAC,CAAA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AAA,MAGD,kCAAA,wBAAuC,aAAc,EAAA,EAAA,CAAA;AAAA,sBACrD,GAAA,CAAA,qBAAA,EAAA;AAAA,QAAuB,QAAA;AAAA,OAAS,CAAA;AAAA,KAAA;AAAA,GACnC,CAAA,CAAA;AAEJ;;;;"}
@@ -1,18 +1,20 @@
1
- import { jsx, jsxs } from 'react/jsx-runtime';
2
- import { useUser } from '@liveblocks/react';
3
- import { forwardRef } from 'react';
4
- import { classNames } from '../classnames.mjs';
1
+ 'use strict';
5
2
 
6
- const Avatar = forwardRef(
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var react$1 = require('@liveblocks/react');
5
+ var react = require('react');
6
+ var classnames = require('../classnames.cjs');
7
+
8
+ const Avatar = react.forwardRef(
7
9
  function Avatar2(props, forwardedRef) {
8
10
  const { userId, className, ...spanProps } = props;
9
- const { user, isLoading } = useUser(userId);
11
+ const { user, isLoading } = react$1.useUser(userId);
10
12
  const avatar = user ? user.avatar : void 0;
11
13
  const name = user ? user.name : void 0;
12
14
  function Initials() {
13
15
  const initials = name ? getInitials(name) : void 0;
14
16
  if (initials) {
15
- return /* @__PURE__ */ jsx("span", {
17
+ return /* @__PURE__ */ jsxRuntime.jsx("span", {
16
18
  "aria-hidden": true,
17
19
  className: "lb-avatar-fallback",
18
20
  children: initials
@@ -22,25 +24,25 @@ const Avatar = forwardRef(
22
24
  return null;
23
25
  if (user === void 0)
24
26
  return null;
25
- return /* @__PURE__ */ jsx("span", {
27
+ return /* @__PURE__ */ jsxRuntime.jsx("span", {
26
28
  "aria-label": userId,
27
29
  title: userId,
28
30
  className: "lb-avatar-fallback",
29
31
  children: getInitials(userId)
30
32
  });
31
33
  }
32
- return /* @__PURE__ */ jsxs("span", {
34
+ return /* @__PURE__ */ jsxRuntime.jsxs("span", {
33
35
  "data-loading": isLoading ? "" : void 0,
34
36
  ...spanProps,
35
- className: classNames("lb-avatar", className),
37
+ className: classnames.classNames("lb-avatar", className),
36
38
  ref: forwardedRef,
37
39
  children: [
38
- avatar && /* @__PURE__ */ jsx("img", {
40
+ avatar && /* @__PURE__ */ jsxRuntime.jsx("img", {
39
41
  src: avatar,
40
42
  alt: name,
41
43
  className: "lb-avatar-image"
42
44
  }),
43
- /* @__PURE__ */ jsx(Initials, {})
45
+ /* @__PURE__ */ jsxRuntime.jsx(Initials, {})
44
46
  ]
45
47
  });
46
48
  }
@@ -54,5 +56,5 @@ function getInitials(name) {
54
56
  }, "");
55
57
  }
56
58
 
57
- export { Avatar };
58
- //# sourceMappingURL=avatar.mjs.map
59
+ exports.Avatar = Avatar;
60
+ //# sourceMappingURL=avatar.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"avatar.cjs","sources":["../../src/mentions/avatar.tsx"],"sourcesContent":["import { useUser } from \"@liveblocks/react\";\nimport type { HTMLAttributes } from \"react\";\nimport { forwardRef } from \"react\";\n\nimport { classNames } from \"../classnames\";\n\nexport interface AvatarProps\n extends Omit<HTMLAttributes<HTMLDivElement>, \"children\"> {\n userId: string;\n}\n\nexport const Avatar = forwardRef<HTMLSpanElement, AvatarProps>(\n function Avatar(props, forwardedRef) {\n const { userId, className, ...spanProps } = props;\n\n const { user, isLoading } = useUser(userId);\n\n const avatar = user ? user.avatar : undefined;\n\n const name = user ? user.name : undefined;\n\n function Initials() {\n const initials = name ? getInitials(name) : undefined;\n if (initials) {\n return (\n <span aria-hidden className=\"lb-avatar-fallback\">\n {initials}\n </span>\n );\n }\n\n if (isLoading) return null;\n\n if (user === undefined) return null;\n\n return (\n <span aria-label={userId} title={userId} className=\"lb-avatar-fallback\">\n {getInitials(userId)}\n </span>\n );\n }\n\n return (\n <span\n data-loading={isLoading ? \"\" : undefined}\n {...spanProps}\n className={classNames(\"lb-avatar\", className)}\n ref={forwardedRef}\n >\n {avatar && <img src={avatar} alt={name} className=\"lb-avatar-image\" />}\n\n <Initials />\n </span>\n );\n }\n);\n\nfunction getInitials(name: string) {\n return name\n .trim()\n .split(\" \")\n .reduce((initials, name, index, array) => {\n if (index === 0 || index === array.length - 1) {\n initials += name.charAt(0).toLocaleUpperCase();\n }\n\n return initials;\n }, \"\");\n}\n"],"names":["forwardRef","Avatar","useUser","jsx","jsxs","classNames","name"],"mappings":";;;;;;;AAWO,MAAM,MAAS,GAAAA,gBAAA;AAAA,EACpB,SAASC,OAAO,CAAA,KAAA,EAAO,YAAc,EAAA;AACnC,IAAA,MAAM,EAAE,MAAA,EAAQ,SAAc,EAAA,GAAA,SAAA,EAAc,GAAA,KAAA,CAAA;AAE5C,IAAA,MAAM,EAAE,IAAA,EAAM,SAAU,EAAA,GAAIC,gBAAQ,MAAM,CAAA,CAAA;AAE1C,IAAM,MAAA,MAAA,GAAS,IAAO,GAAA,IAAA,CAAK,MAAS,GAAA,KAAA,CAAA,CAAA;AAEpC,IAAM,MAAA,IAAA,GAAO,IAAO,GAAA,IAAA,CAAK,IAAO,GAAA,KAAA,CAAA,CAAA;AAEhC,IAAA,SAAS,QAAW,GAAA;AAClB,MAAA,MAAM,QAAW,GAAA,IAAA,GAAO,WAAY,CAAA,IAAI,CAAI,GAAA,KAAA,CAAA,CAAA;AAC5C,MAAA,IAAI,QAAU,EAAA;AACZ,QAAA,uBACGC,cAAA,CAAA,MAAA,EAAA;AAAA,UAAK,aAAW,EAAA,IAAA;AAAA,UAAC,SAAU,EAAA,oBAAA;AAAA,UACzB,QAAA,EAAA,QAAA;AAAA,SACH,CAAA,CAAA;AAAA,OAEJ;AAEA,MAAI,IAAA,SAAA;AAAW,QAAO,OAAA,IAAA,CAAA;AAEtB,MAAA,IAAI,IAAS,KAAA,KAAA,CAAA;AAAW,QAAO,OAAA,IAAA,CAAA;AAE/B,MAAA,uBACGA,cAAA,CAAA,MAAA,EAAA;AAAA,QAAK,YAAY,EAAA,MAAA;AAAA,QAAQ,KAAO,EAAA,MAAA;AAAA,QAAQ,SAAU,EAAA,oBAAA;AAAA,QAChD,sBAAY,MAAM,CAAA;AAAA,OACrB,CAAA,CAAA;AAAA,KAEJ;AAEA,IAAA,uBACGC,eAAA,CAAA,MAAA,EAAA;AAAA,MACC,cAAA,EAAc,YAAY,EAAK,GAAA,KAAA,CAAA;AAAA,MAC9B,GAAG,SAAA;AAAA,MACJ,SAAA,EAAWC,qBAAW,CAAA,WAAA,EAAa,SAAS,CAAA;AAAA,MAC5C,GAAK,EAAA,YAAA;AAAA,MAEJ,QAAA,EAAA;AAAA,QAAA,MAAA,oBAAWF,cAAA,CAAA,KAAA,EAAA;AAAA,UAAI,GAAK,EAAA,MAAA;AAAA,UAAQ,GAAK,EAAA,IAAA;AAAA,UAAM,SAAU,EAAA,iBAAA;AAAA,SAAkB,CAAA;AAAA,uCAEnE,QAAS,EAAA,EAAA,CAAA;AAAA,OAAA;AAAA,KACZ,CAAA,CAAA;AAAA,GAEJ;AACF,EAAA;AAEA,SAAS,YAAY,IAAc,EAAA;AACjC,EAAO,OAAA,IAAA,CACJ,IAAK,EAAA,CACL,KAAM,CAAA,GAAG,CACT,CAAA,MAAA,CAAO,CAAC,QAAA,EAAUG,KAAM,EAAA,KAAA,EAAO,KAAU,KAAA;AACxC,IAAA,IAAI,KAAU,KAAA,CAAA,IAAK,KAAU,KAAA,KAAA,CAAM,SAAS,CAAG,EAAA;AAC7C,MAAA,QAAA,IAAYA,KAAK,CAAA,MAAA,CAAO,CAAC,CAAA,CAAE,iBAAkB,EAAA,CAAA;AAAA,KAC/C;AAEA,IAAO,OAAA,QAAA,CAAA;AAAA,KACN,EAAE,CAAA,CAAA;AACT;;;;"}
@@ -1,20 +1,18 @@
1
- 'use strict';
1
+ import { jsx, jsxs } from 'react/jsx-runtime';
2
+ import { useUser } from '@liveblocks/react';
3
+ import { forwardRef } from 'react';
4
+ import { classNames } from '../classnames.js';
2
5
 
3
- var jsxRuntime = require('react/jsx-runtime');
4
- var react$1 = require('@liveblocks/react');
5
- var react = require('react');
6
- var classnames = require('../classnames.js');
7
-
8
- const Avatar = react.forwardRef(
6
+ const Avatar = forwardRef(
9
7
  function Avatar2(props, forwardedRef) {
10
8
  const { userId, className, ...spanProps } = props;
11
- const { user, isLoading } = react$1.useUser(userId);
9
+ const { user, isLoading } = useUser(userId);
12
10
  const avatar = user ? user.avatar : void 0;
13
11
  const name = user ? user.name : void 0;
14
12
  function Initials() {
15
13
  const initials = name ? getInitials(name) : void 0;
16
14
  if (initials) {
17
- return /* @__PURE__ */ jsxRuntime.jsx("span", {
15
+ return /* @__PURE__ */ jsx("span", {
18
16
  "aria-hidden": true,
19
17
  className: "lb-avatar-fallback",
20
18
  children: initials
@@ -24,25 +22,25 @@ const Avatar = react.forwardRef(
24
22
  return null;
25
23
  if (user === void 0)
26
24
  return null;
27
- return /* @__PURE__ */ jsxRuntime.jsx("span", {
25
+ return /* @__PURE__ */ jsx("span", {
28
26
  "aria-label": userId,
29
27
  title: userId,
30
28
  className: "lb-avatar-fallback",
31
29
  children: getInitials(userId)
32
30
  });
33
31
  }
34
- return /* @__PURE__ */ jsxRuntime.jsxs("span", {
32
+ return /* @__PURE__ */ jsxs("span", {
35
33
  "data-loading": isLoading ? "" : void 0,
36
34
  ...spanProps,
37
- className: classnames.classNames("lb-avatar", className),
35
+ className: classNames("lb-avatar", className),
38
36
  ref: forwardedRef,
39
37
  children: [
40
- avatar && /* @__PURE__ */ jsxRuntime.jsx("img", {
38
+ avatar && /* @__PURE__ */ jsx("img", {
41
39
  src: avatar,
42
40
  alt: name,
43
41
  className: "lb-avatar-image"
44
42
  }),
45
- /* @__PURE__ */ jsxRuntime.jsx(Initials, {})
43
+ /* @__PURE__ */ jsx(Initials, {})
46
44
  ]
47
45
  });
48
46
  }
@@ -56,5 +54,5 @@ function getInitials(name) {
56
54
  }, "");
57
55
  }
58
56
 
59
- exports.Avatar = Avatar;
57
+ export { Avatar };
60
58
  //# sourceMappingURL=avatar.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"avatar.js","sources":["../../src/mentions/avatar.tsx"],"sourcesContent":["import { useUser } from \"@liveblocks/react\";\nimport type { HTMLAttributes } from \"react\";\nimport { forwardRef } from \"react\";\n\nimport { classNames } from \"../classnames\";\n\nexport interface AvatarProps\n extends Omit<HTMLAttributes<HTMLDivElement>, \"children\"> {\n userId: string;\n}\n\nexport const Avatar = forwardRef<HTMLSpanElement, AvatarProps>(\n function Avatar(props, forwardedRef) {\n const { userId, className, ...spanProps } = props;\n\n const { user, isLoading } = useUser(userId);\n\n const avatar = user ? user.avatar : undefined;\n\n const name = user ? user.name : undefined;\n\n function Initials() {\n const initials = name ? getInitials(name) : undefined;\n if (initials) {\n return (\n <span aria-hidden className=\"lb-avatar-fallback\">\n {initials}\n </span>\n );\n }\n\n if (isLoading) return null;\n\n if (user === undefined) return null;\n\n return (\n <span aria-label={userId} title={userId} className=\"lb-avatar-fallback\">\n {getInitials(userId)}\n </span>\n );\n }\n\n return (\n <span\n data-loading={isLoading ? \"\" : undefined}\n {...spanProps}\n className={classNames(\"lb-avatar\", className)}\n ref={forwardedRef}\n >\n {avatar && <img src={avatar} alt={name} className=\"lb-avatar-image\" />}\n\n <Initials />\n </span>\n );\n }\n);\n\nfunction getInitials(name: string) {\n return name\n .trim()\n .split(\" \")\n .reduce((initials, name, index, array) => {\n if (index === 0 || index === array.length - 1) {\n initials += name.charAt(0).toLocaleUpperCase();\n }\n\n return initials;\n }, \"\");\n}\n"],"names":["forwardRef","Avatar","useUser","jsx","jsxs","classNames","name"],"mappings":";;;;;;;AAWO,MAAM,MAAS,GAAAA,gBAAA;AAAA,EACpB,SAASC,OAAO,CAAA,KAAA,EAAO,YAAc,EAAA;AACnC,IAAA,MAAM,EAAE,MAAA,EAAQ,SAAc,EAAA,GAAA,SAAA,EAAc,GAAA,KAAA,CAAA;AAE5C,IAAA,MAAM,EAAE,IAAA,EAAM,SAAU,EAAA,GAAIC,gBAAQ,MAAM,CAAA,CAAA;AAE1C,IAAM,MAAA,MAAA,GAAS,IAAO,GAAA,IAAA,CAAK,MAAS,GAAA,KAAA,CAAA,CAAA;AAEpC,IAAM,MAAA,IAAA,GAAO,IAAO,GA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AA;AACjC,EAAO,OAAA,IAAA,CACJ,IAAK,EAAA,CACL,KAAM,CAAA,GAAG,CACT,CAAA,MAAA,CAAO,CAAC,QAAA,EAAUG,KAAM,EAAA,KAAA,EAAO,KAAU,KAAA;AACxC,IAAA,IAAI,KAAU,KAAA,CAAA,IAAK,KAAU,KAAA,KAAA,CAAM,SAAS,CAAG,EAAA;AAC7C,MAAA,QAAA,IAAYA,KAAK,CAAA,MAAA,CAAO,CAAC,CAAA,CAAE,iBAAkB,EAAA,CAAA;AAAA,KAC/C;AAEA,IAAO,OAAA,QAAA,CAAA;AAAA,KACN,EAAE,CAAA,CAAA;AACT;;;;"}
1
+ {"version":3,"file":"avatar.js","sources":["../../src/mentions/avatar.tsx"],"sourcesContent":["import { useUser } from \"@liveblocks/react\";\nimport type { HTMLAttributes } from \"react\";\nimport { forwardRef } from \"react\";\n\nimport { classNames } from \"../classnames\";\n\nexport interface AvatarProps\n extends Omit<HTMLAttributes<HTMLDivElement>, \"children\"> {\n userId: string;\n}\n\nexport const Avatar = forwardRef<HTMLSpanElement, AvatarProps>(\n function Avatar(props, forwardedRef) {\n const { userId, className, ...spanProps } = props;\n\n const { user, isLoading } = useUser(userId);\n\n const avatar = user ? user.avatar : undefined;\n\n const name = user ? user.name : undefined;\n\n function Initials() {\n const initials = name ? getInitials(name) : undefined;\n if (initials) {\n return (\n <span aria-hidden className=\"lb-avatar-fallback\">\n {initials}\n </span>\n );\n }\n\n if (isLoading) return null;\n\n if (user === undefined) return null;\n\n return (\n <span aria-label={userId} title={userId} className=\"lb-avatar-fallback\">\n {getInitials(userId)}\n </span>\n );\n }\n\n return (\n <span\n data-loading={isLoading ? \"\" : undefined}\n {...spanProps}\n className={classNames(\"lb-avatar\", className)}\n ref={forwardedRef}\n >\n {avatar && <img src={avatar} alt={name} className=\"lb-avatar-image\" />}\n\n <Initials />\n </span>\n );\n }\n);\n\nfunction getInitials(name: string) {\n return name\n .trim()\n .split(\" \")\n .reduce((initials, name, index, array) => {\n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