@liveblocks/react-lexical 2.18.3 → 2.18.4-uns2
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/{classnames.mjs → classnames.cjs} +4 -2
- package/dist/{classnames.mjs.map → classnames.cjs.map} +1 -1
- package/dist/classnames.js +1 -3
- package/dist/classnames.js.map +1 -1
- package/dist/comments/{anchored-threads.mjs → anchored-threads.cjs} +44 -41
- package/dist/comments/{anchored-threads.mjs.map → anchored-threads.cjs.map} +1 -1
- package/dist/comments/anchored-threads.js +40 -43
- package/dist/comments/anchored-threads.js.map +1 -1
- package/dist/comments/{comment-plugin-provider.mjs → comment-plugin-provider.cjs} +62 -55
- package/dist/comments/{comment-plugin-provider.mjs.map → comment-plugin-provider.cjs.map} +1 -1
- package/dist/comments/comment-plugin-provider.js +54 -61
- package/dist/comments/comment-plugin-provider.js.map +1 -1
- package/dist/comments/{floating-composer.mjs → floating-composer.cjs} +68 -64
- package/dist/comments/{floating-composer.mjs.map → floating-composer.cjs.map} +1 -1
- package/dist/comments/floating-composer.js +63 -67
- package/dist/comments/floating-composer.js.map +1 -1
- package/dist/comments/{floating-threads.mjs → floating-threads.cjs} +51 -48
- package/dist/comments/{floating-threads.mjs.map → floating-threads.cjs.map} +1 -1
- package/dist/comments/floating-threads.js +47 -50
- package/dist/comments/floating-threads.js.map +1 -1
- package/dist/comments/get-thread-mark-ids.cjs +23 -0
- package/dist/comments/{get-thread-mark-ids.mjs.map → get-thread-mark-ids.cjs.map} +1 -1
- package/dist/comments/get-thread-mark-ids.js +6 -8
- package/dist/comments/get-thread-mark-ids.js.map +1 -1
- package/dist/comments/{thread-mark-node.mjs → thread-mark-node.cjs} +10 -6
- package/dist/comments/{thread-mark-node.mjs.map → thread-mark-node.cjs.map} +1 -1
- package/dist/comments/thread-mark-node.js +5 -9
- package/dist/comments/thread-mark-node.js.map +1 -1
- package/dist/comments/{unwrap-thread-mark-node.mjs → unwrap-thread-mark-node.cjs} +4 -2
- package/dist/comments/unwrap-thread-mark-node.cjs.map +1 -0
- package/dist/comments/unwrap-thread-mark-node.js +1 -3
- package/dist/comments/unwrap-thread-mark-node.js.map +1 -1
- package/dist/comments/{wrap-selection-in-thread-mark-node.mjs → wrap-selection-in-thread-mark-node.cjs} +12 -10
- package/dist/comments/{wrap-selection-in-thread-mark-node.mjs.map → wrap-selection-in-thread-mark-node.cjs.map} +1 -1
- package/dist/comments/wrap-selection-in-thread-mark-node.js +9 -11
- package/dist/comments/wrap-selection-in-thread-mark-node.js.map +1 -1
- package/dist/{create-dom-range.mjs → create-dom-range.cjs} +7 -5
- package/dist/{create-dom-range.mjs.map → create-dom-range.cjs.map} +1 -1
- package/dist/create-dom-range.js +4 -6
- package/dist/create-dom-range.js.map +1 -1
- package/dist/{create-rects-from-dom-range.mjs → create-rects-from-dom-range.cjs} +4 -2
- package/dist/{create-rects-from-dom-range.mjs.map → create-rects-from-dom-range.cjs.map} +1 -1
- package/dist/create-rects-from-dom-range.js +1 -3
- package/dist/create-rects-from-dom-range.js.map +1 -1
- package/dist/index.cjs +33 -0
- package/dist/{index.mjs.map → index.cjs.map} +1 -1
- package/dist/index.js +14 -31
- package/dist/index.js.map +1 -1
- package/dist/{is-block-node-active.mjs → is-block-node-active.cjs} +12 -10
- package/dist/{is-block-node-active.mjs.map → is-block-node-active.cjs.map} +1 -1
- package/dist/is-block-node-active.js +9 -11
- package/dist/is-block-node-active.js.map +1 -1
- package/dist/is-command-registered.cjs +11 -0
- package/dist/{is-command-registered.mjs.map → is-command-registered.cjs.map} +1 -1
- package/dist/is-command-registered.js +3 -5
- package/dist/is-command-registered.js.map +1 -1
- package/dist/is-text-format-active.cjs +16 -0
- package/dist/{is-text-format-active.mjs.map → is-text-format-active.cjs.map} +1 -1
- package/dist/is-text-format-active.js +4 -6
- package/dist/is-text-format-active.js.map +1 -1
- package/dist/liveblocks-config.cjs +17 -0
- package/dist/{liveblocks-config.mjs.map → liveblocks-config.cjs.map} +1 -1
- package/dist/liveblocks-config.js +4 -6
- package/dist/liveblocks-config.js.map +1 -1
- package/dist/liveblocks-plugin-provider.cjs +151 -0
- package/dist/liveblocks-plugin-provider.cjs.map +1 -0
- package/dist/liveblocks-plugin-provider.js +43 -47
- package/dist/liveblocks-plugin-provider.js.map +1 -1
- package/dist/mentions/{avatar.mjs → avatar.cjs} +16 -14
- package/dist/mentions/avatar.cjs.map +1 -0
- package/dist/mentions/avatar.js +13 -15
- package/dist/mentions/avatar.js.map +1 -1
- package/dist/mentions/mention-component.cjs +51 -0
- package/dist/mentions/{mention-component.mjs.map → mention-component.cjs.map} +1 -1
- package/dist/mentions/mention-component.js +14 -16
- package/dist/mentions/mention-component.js.map +1 -1
- package/dist/mentions/{mention-node.mjs → mention-node.cjs} +16 -12
- package/dist/mentions/{mention-node.mjs.map → mention-node.cjs.map} +1 -1
- package/dist/mentions/mention-node.js +11 -15
- package/dist/mentions/mention-node.js.map +1 -1
- package/dist/mentions/{mention-plugin.mjs → mention-plugin.cjs} +81 -78
- package/dist/mentions/{mention-plugin.mjs.map → mention-plugin.cjs.map} +1 -1
- package/dist/mentions/mention-plugin.js +77 -80
- package/dist/mentions/mention-plugin.js.map +1 -1
- package/dist/mentions/{suggestions.mjs → suggestions.cjs} +43 -37
- package/dist/mentions/{suggestions.mjs.map → suggestions.cjs.map} +1 -1
- package/dist/mentions/suggestions.js +36 -42
- package/dist/mentions/suggestions.js.map +1 -1
- package/dist/mentions/user.cjs +26 -0
- package/dist/mentions/{user.mjs.map → user.cjs.map} +1 -1
- package/dist/mentions/user.js +11 -13
- package/dist/mentions/user.js.map +1 -1
- package/dist/toolbar/{floating-toolbar.mjs → floating-toolbar.cjs} +73 -70
- package/dist/toolbar/{floating-toolbar.mjs.map → floating-toolbar.cjs.map} +1 -1
- package/dist/toolbar/floating-toolbar.js +69 -72
- package/dist/toolbar/floating-toolbar.js.map +1 -1
- package/dist/toolbar/shared.cjs +36 -0
- package/dist/toolbar/{shared.mjs.map → shared.cjs.map} +1 -1
- package/dist/toolbar/shared.js +12 -15
- package/dist/toolbar/shared.js.map +1 -1
- package/dist/toolbar/toolbar.cjs +433 -0
- package/dist/toolbar/{toolbar.mjs.map → toolbar.cjs.map} +1 -1
- package/dist/toolbar/toolbar.js +131 -156
- package/dist/toolbar/toolbar.js.map +1 -1
- package/dist/use-root-element.cjs +21 -0
- package/dist/use-root-element.cjs.map +1 -0
- package/dist/use-root-element.js +7 -9
- package/dist/use-root-element.js.map +1 -1
- package/dist/version-history/{history-version-preview.mjs → history-version-preview.cjs} +52 -50
- package/dist/version-history/{history-version-preview.mjs.map → history-version-preview.cjs.map} +1 -1
- package/dist/version-history/history-version-preview.js +49 -51
- package/dist/version-history/history-version-preview.js.map +1 -1
- package/dist/version.cjs +10 -0
- package/dist/{version.mjs.map → version.cjs.map} +1 -1
- package/dist/version.js +3 -7
- package/dist/version.js.map +1 -1
- package/package.json +18 -17
- package/styles.css.d.cts +1 -0
- package/dist/comments/get-thread-mark-ids.mjs +0 -21
- package/dist/comments/unwrap-thread-mark-node.mjs.map +0 -1
- package/dist/index.mjs +0 -16
- package/dist/is-command-registered.mjs +0 -9
- package/dist/is-text-format-active.mjs +0 -14
- package/dist/liveblocks-config.mjs +0 -15
- package/dist/liveblocks-plugin-provider.mjs +0 -147
- package/dist/liveblocks-plugin-provider.mjs.map +0 -1
- package/dist/mentions/avatar.mjs.map +0 -1
- package/dist/mentions/mention-component.mjs +0 -49
- package/dist/mentions/user.mjs +0 -24
- package/dist/toolbar/shared.mjs +0 -33
- package/dist/toolbar/toolbar.mjs +0 -408
- package/dist/use-root-element.mjs +0 -19
- package/dist/use-root-element.mjs.map +0 -1
- package/dist/version.mjs +0 -6
- /package/dist/{index.d.mts → index.d.cts} +0 -0
|
@@ -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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AAAA,UACV,GAAK,EAAA,CAAA;AAAA,UACL,IAAM,EAAA,CAAA;AAAA,UACN,SAAA,EAAW,eAAe,IAAK,CAAA,KAAA,CAAM,CAAC,CAAQ,CAAA,IAAA,EAAA,IAAA,CAAK,MAAM,CAAC,CAAA,CAAA,MAAA,CAAA;AAAA,UAC1D,QAAU,EAAA,aAAA;AAAA,SACZ;AAAA,OACF,CAAA;AAAA,MAEC,wBACEA,cAAA,CAAAC,8CAAA,EAAA;AAAA,QAIC,IAAI,IAAK,CAAA,EAAA;AAAA,QACT,eAAA;AAAA,QACA,QAAA,EAAU,IAAK,CAAA,IAAA,EAAM,IAAQ,IAAA,EAAA;AAAA,QAC7B,WAAA,EAAa,KAAK,IAAM,EAAA,KAAA;AAAA,QACxB,mBAAqB,EAAA,YAAA;AAAA,QACrB,eAAiB,EAAA,IAAA;AAAA,OAAA,EANZ,KAAK,EAOZ,CAAA;AAAA,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,23 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var mentionPlugin = require('./mentions/mention-plugin.js');
|
|
16
|
-
var useRootElement = require('./use-root-element.js');
|
|
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';
|
|
17
15
|
|
|
18
16
|
function useEditorStatus() {
|
|
19
|
-
const provider =
|
|
20
|
-
const subscribe =
|
|
17
|
+
const provider = useYjsProvider();
|
|
18
|
+
const subscribe = useCallback(
|
|
21
19
|
(onStoreChange) => {
|
|
22
20
|
if (provider === void 0)
|
|
23
21
|
return () => {
|
|
@@ -29,21 +27,21 @@ function useEditorStatus() {
|
|
|
29
27
|
},
|
|
30
28
|
[provider]
|
|
31
29
|
);
|
|
32
|
-
const getSnapshot =
|
|
30
|
+
const getSnapshot = useCallback(() => {
|
|
33
31
|
if (provider === void 0) {
|
|
34
32
|
return "not-loaded";
|
|
35
33
|
}
|
|
36
34
|
return provider.getStatus();
|
|
37
35
|
}, [provider]);
|
|
38
|
-
return
|
|
36
|
+
return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
39
37
|
}
|
|
40
38
|
function useIsEditorReady() {
|
|
41
|
-
const yjsProvider =
|
|
42
|
-
const getSnapshot =
|
|
39
|
+
const yjsProvider = useYjsProvider();
|
|
40
|
+
const getSnapshot = useCallback(() => {
|
|
43
41
|
const status = yjsProvider?.getStatus();
|
|
44
42
|
return status === "synchronizing" || status === "synchronized";
|
|
45
43
|
}, [yjsProvider]);
|
|
46
|
-
const subscribe =
|
|
44
|
+
const subscribe = useCallback(
|
|
47
45
|
(callback) => {
|
|
48
46
|
if (yjsProvider === void 0)
|
|
49
47
|
return () => {
|
|
@@ -55,35 +53,35 @@ function useIsEditorReady() {
|
|
|
55
53
|
},
|
|
56
54
|
[yjsProvider]
|
|
57
55
|
);
|
|
58
|
-
return
|
|
56
|
+
return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
59
57
|
}
|
|
60
58
|
const LiveblocksPlugin = ({
|
|
61
59
|
children
|
|
62
60
|
}) => {
|
|
63
|
-
const isResolveMentionSuggestionsDefined =
|
|
64
|
-
const [editor] =
|
|
65
|
-
const room =
|
|
66
|
-
if (!editor.hasNodes([
|
|
61
|
+
const isResolveMentionSuggestionsDefined = useResolveMentionSuggestions() !== void 0;
|
|
62
|
+
const [editor] = useLexicalComposerContext();
|
|
63
|
+
const room = useRoom();
|
|
64
|
+
if (!editor.hasNodes([ThreadMarkNode, MentionNode])) {
|
|
67
65
|
throw new Error(
|
|
68
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"
|
|
69
67
|
);
|
|
70
68
|
}
|
|
71
|
-
const [containerRef, setContainerRef] =
|
|
69
|
+
const [containerRef, setContainerRef] = useState(void 0);
|
|
72
70
|
const {
|
|
73
71
|
refs: { setReference, setFloating },
|
|
74
72
|
strategy,
|
|
75
73
|
x,
|
|
76
74
|
y
|
|
77
|
-
} =
|
|
75
|
+
} = useFloating({
|
|
78
76
|
strategy: "fixed",
|
|
79
77
|
placement: "bottom",
|
|
80
78
|
whileElementsMounted: (...args) => {
|
|
81
|
-
return
|
|
79
|
+
return autoUpdate(...args, {
|
|
82
80
|
animationFrame: true
|
|
83
81
|
});
|
|
84
82
|
}
|
|
85
83
|
});
|
|
86
|
-
|
|
84
|
+
useEffect(() => {
|
|
87
85
|
if (process.env.NODE_ENV !== "production") {
|
|
88
86
|
if (!editor.getEditorState().isEmpty()) {
|
|
89
87
|
console.warn(
|
|
@@ -92,34 +90,34 @@ const LiveblocksPlugin = ({
|
|
|
92
90
|
}
|
|
93
91
|
}
|
|
94
92
|
}, []);
|
|
95
|
-
|
|
96
|
-
const self =
|
|
97
|
-
const providerFactory =
|
|
93
|
+
useReportTextEditor(TextEditorType.Lexical, "root");
|
|
94
|
+
const self = useSelf();
|
|
95
|
+
const providerFactory = useCallback(
|
|
98
96
|
(id, yjsDocMap) => {
|
|
99
|
-
const provider =
|
|
97
|
+
const provider = getYjsProviderForRoom(room);
|
|
100
98
|
yjsDocMap.set(id, provider.getYDoc());
|
|
101
99
|
return provider;
|
|
102
100
|
},
|
|
103
101
|
[room]
|
|
104
102
|
);
|
|
105
|
-
const root = useRootElement
|
|
106
|
-
|
|
103
|
+
const root = useRootElement();
|
|
104
|
+
useLayoutEffect(() => {
|
|
107
105
|
if (root === null)
|
|
108
106
|
return;
|
|
109
107
|
setReference({
|
|
110
108
|
getBoundingClientRect: () => root.getBoundingClientRect()
|
|
111
109
|
});
|
|
112
110
|
}, [setReference, root]);
|
|
113
|
-
const handleFloatingRef =
|
|
111
|
+
const handleFloatingRef = useCallback(
|
|
114
112
|
(node) => {
|
|
115
113
|
setFloating(node);
|
|
116
114
|
setContainerRef({ current: node });
|
|
117
115
|
},
|
|
118
116
|
[setFloating, setContainerRef]
|
|
119
117
|
);
|
|
120
|
-
return /* @__PURE__ */
|
|
118
|
+
return /* @__PURE__ */ jsxs(Fragment, {
|
|
121
119
|
children: [
|
|
122
|
-
/* @__PURE__ */
|
|
120
|
+
/* @__PURE__ */ jsx("div", {
|
|
123
121
|
ref: handleFloatingRef,
|
|
124
122
|
style: {
|
|
125
123
|
position: strategy,
|
|
@@ -129,7 +127,7 @@ const LiveblocksPlugin = ({
|
|
|
129
127
|
minWidth: "max-content"
|
|
130
128
|
}
|
|
131
129
|
}),
|
|
132
|
-
self && /* @__PURE__ */
|
|
130
|
+
self && /* @__PURE__ */ jsx(CollaborationPlugin, {
|
|
133
131
|
id: room.id,
|
|
134
132
|
providerFactory,
|
|
135
133
|
username: self.info?.name ?? "",
|
|
@@ -137,15 +135,13 @@ const LiveblocksPlugin = ({
|
|
|
137
135
|
cursorsContainerRef: containerRef,
|
|
138
136
|
shouldBootstrap: true
|
|
139
137
|
}, room.id),
|
|
140
|
-
isResolveMentionSuggestionsDefined && /* @__PURE__ */
|
|
141
|
-
/* @__PURE__ */
|
|
138
|
+
isResolveMentionSuggestionsDefined && /* @__PURE__ */ jsx(MentionPlugin, {}),
|
|
139
|
+
/* @__PURE__ */ jsx(CommentPluginProvider, {
|
|
142
140
|
children
|
|
143
141
|
})
|
|
144
142
|
]
|
|
145
143
|
});
|
|
146
144
|
};
|
|
147
145
|
|
|
148
|
-
|
|
149
|
-
exports.useEditorStatus = useEditorStatus;
|
|
150
|
-
exports.useIsEditorReady = useIsEditorReady;
|
|
146
|
+
export { LiveblocksPlugin, useEditorStatus, useIsEditorReady };
|
|
151
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 { 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 {\n useCallback,\n useEffect,\n useState,\n useSyncExternalStore,\n} 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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,eAAe,CAAA;AAAA,GAC/B,CAAA;AAEA,EACE,uBAAAiB,eAAA,CAAAC,mBAAA,EAAA;AAAA,IACE,QAAA,EAAA;AAAA,sBAACC,cAAA,CAAA,KAAA,EAAA;AAAA,QACC,GAAK,EAAA,iBAAA;AAAA,QACL,KAAO,EAAA;AAAA,UACL,QAAU,EAAA,QAAA;AAAA,UACV,GAAK,EAAA,CAAA;AAAA,UACL,IAAM,EAAA,CAAA;AAAA,UACN,SAAA,EAAW,eAAe,IAAK,CAAA,KAAA,CAAM,CAAC,CAAQ,CAAA,IAAA,EAAA,IAAA,CAAK,MAAM,CAAC,CAAA,CAAA,MAAA,CAAA;AAAA,UAC1D,QAAU,EAAA,aAAA;AAAA,SACZ;AAAA,OACF,CAAA;AAAA,MAEC,wBACEA,cAAA,CAAAC,8CAAA,EAAA;AAAA,QAIC,IAAI,IAAK,CAAA,EAAA;AAAA,QACT,eAAA;AAAA,QACA,QAAA,EAAU,IAAK,CAAA,IAAA,EAAM,IAAQ,IAAA,EAAA;AAAA,QAC7B,WAAA,EAAa,KAAK,IAAM,EAAA,KAAA;AAAA,QACxB,mBAAqB,EAAA,YAAA;AAAA,QACrB,eAAiB,EAAA,IAAA;AAAA,OAAA,EANZ,KAAK,EAOZ,CAAA;AAAA,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,CAAA;AAEb,EAAO,OAAA,oBAAA,CAAqB,SAAW,EAAA,WAAA,EAAa,WAAW,CAAA,CAAA;AACjE,CAAA;AAMO,SAAS,gBAA4B,GAAA;AAC1C,EAAA,MAAM,cAAc,cAAe,EAAA,CAAA;AAEnC,EAAM,MAAA,WAAA,GAAc,YAAY,MAAM;AACpC,IAAM,MAAA,MAAA,GAAS,aAAa,SAAU,EAAA,CAAA;AACtC,IAAO,OAAA,MAAA,KAAW,mBAAmB,MAAW,KAAA,cAAA,CAAA;AAAA,GAClD,EAAG,CAAC,WAAW,CAAC,CAAA,CAAA;AAEhB,EAAA,MAAM,SAAY,GAAA,WAAA;AAAA,IAChB,CAAC,QAAyB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A,IACA,CAAC,aAAa,eAAe,CAAA;AAAA,GAC/B,CAAA;AAEA,EACE,uBAAA,IAAA,CAAA,QAAA,EAAA;AAAA,IACE,QAAA,EAAA;AAAA,sBAAC,GAAA,CAAA,KAAA,EAAA;AAAA,QACC,GAAK,EAAA,iBAAA;AAAA,QACL,KAAO,EAAA;AAAA,UACL,QAAU,EAAA,QAAA;AAAA,UACV,GAAK,EAAA,CAAA;AAAA,UACL,IAAM,EAAA,CAAA;AAAA,UACN,SAAA,EAAW,eAAe,IAAK,CAAA,KAAA,CAAM,CAAC,CAAQ,CAAA,IAAA,EAAA,IAAA,CAAK,MAAM,CAAC,CAAA,CAAA,MAAA,CAAA;AAAA,UAC1D,QAAU,EAAA,aAAA;AAAA,SACZ;AAAA,OACF,CAAA;AAAA,MAEC,wBACE,GAAA,CAAA,mBAAA,EAAA;AAAA,QAIC,IAAI,IAAK,CAAA,EAAA;AAAA,QACT,eAAA;AAAA,QACA,QAAA,EAAU,IAAK,CAAA,IAAA,EAAM,IAAQ,IAAA,EAAA;AAAA,QAC7B,WAAA,EAAa,KAAK,IAAM,EAAA,KAAA;AAAA,QACxB,mBAAqB,EAAA,YAAA;AAAA,QACrB,eAAiB,EAAA,IAAA;AAAA,OAAA,EANZ,KAAK,EAOZ,CAAA;AAAA,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
|
-
|
|
2
|
-
import { useUser } from '@liveblocks/react';
|
|
3
|
-
import { forwardRef } from 'react';
|
|
4
|
-
import { classNames } from '../classnames.mjs';
|
|
1
|
+
'use strict';
|
|
5
2
|
|
|
6
|
-
|
|
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
|
-
|
|
58
|
-
//# sourceMappingURL=avatar.
|
|
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) {\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AAA,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;;;;"}
|
package/dist/mentions/avatar.js
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
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 } =
|
|
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__ */
|
|
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__ */
|
|
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__ */
|
|
32
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
35
33
|
"data-loading": isLoading ? "" : void 0,
|
|
36
34
|
...spanProps,
|
|
37
|
-
className:
|
|
35
|
+
className: classNames("lb-avatar", className),
|
|
38
36
|
ref: forwardedRef,
|
|
39
37
|
children: [
|
|
40
|
-
avatar && /* @__PURE__ */
|
|
38
|
+
avatar && /* @__PURE__ */ jsx("img", {
|
|
41
39
|
src: avatar,
|
|
42
40
|
alt: name,
|
|
43
41
|
className: "lb-avatar-image"
|
|
44
42
|
}),
|
|
45
|
-
/* @__PURE__ */
|
|
43
|
+
/* @__PURE__ */ jsx(Initials, {})
|
|
46
44
|
]
|
|
47
45
|
});
|
|
48
46
|
}
|
|
@@ -56,5 +54,5 @@ function getInitials(name) {
|
|
|
56
54
|
}, "");
|
|
57
55
|
}
|
|
58
56
|
|
|
59
|
-
|
|
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":["
|
|
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":["Avatar","name"],"mappings":";;;;;AAWO,MAAM,MAAS,GAAA,UAAA;AAAA,EACpB,SAASA,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,GAAI,QAAQ,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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A,MAAA,CAAO,CAAC,QAAA,EAAUC,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;;;;"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
5
|
+
var lexical = require('lexical');
|
|
6
|
+
var react = require('react');
|
|
7
|
+
|
|
8
|
+
function Mention({
|
|
9
|
+
nodeKey,
|
|
10
|
+
children
|
|
11
|
+
}) {
|
|
12
|
+
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
13
|
+
const isSelected = useIsNodeSelected(nodeKey);
|
|
14
|
+
function handleClick(event) {
|
|
15
|
+
editor.update(() => {
|
|
16
|
+
event.stopPropagation();
|
|
17
|
+
event.preventDefault();
|
|
18
|
+
const selection = lexical.$createNodeSelection();
|
|
19
|
+
selection.add(nodeKey);
|
|
20
|
+
lexical.$setSelection(selection);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return /* @__PURE__ */ jsxRuntime.jsx("span", {
|
|
24
|
+
onClick: handleClick,
|
|
25
|
+
"data-selected": isSelected ? "" : void 0,
|
|
26
|
+
className: "lb-root lb-lexical-mention",
|
|
27
|
+
children
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function $isNodeSelected(key) {
|
|
31
|
+
const node = lexical.$getNodeByKey(key);
|
|
32
|
+
if (node === null)
|
|
33
|
+
return false;
|
|
34
|
+
return node.isSelected();
|
|
35
|
+
}
|
|
36
|
+
function useIsNodeSelected(key) {
|
|
37
|
+
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
38
|
+
const subscribe = react.useCallback(
|
|
39
|
+
(onStoreChange) => {
|
|
40
|
+
return editor.registerUpdateListener(onStoreChange);
|
|
41
|
+
},
|
|
42
|
+
[editor]
|
|
43
|
+
);
|
|
44
|
+
const getSnapshot = react.useCallback(() => {
|
|
45
|
+
return editor.getEditorState().read(() => $isNodeSelected(key));
|
|
46
|
+
}, [editor, key]);
|
|
47
|
+
return react.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
exports.Mention = Mention;
|
|
51
|
+
//# sourceMappingURL=mention-component.cjs.map
|