@liveblocks/react-lexical 1.12.0-lexical6 → 2.0.0-alpha3
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.js +8 -0
- package/dist/classnames.js.map +1 -0
- package/dist/classnames.mjs +6 -0
- package/dist/classnames.mjs.map +1 -0
- package/dist/comments/ThreadPanel.js +41 -16
- package/dist/comments/ThreadPanel.js.map +1 -1
- package/dist/comments/ThreadPanel.mjs +43 -18
- package/dist/comments/ThreadPanel.mjs.map +1 -1
- package/dist/comments/comment-plugin-provider.js +18 -106
- package/dist/comments/comment-plugin-provider.js.map +1 -1
- package/dist/comments/comment-plugin-provider.mjs +17 -104
- package/dist/comments/comment-plugin-provider.mjs.map +1 -1
- package/dist/comments/floating-composer.js +226 -15
- package/dist/comments/floating-composer.js.map +1 -1
- package/dist/comments/floating-composer.mjs +224 -15
- package/dist/comments/floating-composer.mjs.map +1 -1
- package/dist/create-dom-range.js +63 -0
- package/dist/create-dom-range.js.map +1 -0
- package/dist/create-dom-range.mjs +61 -0
- package/dist/create-dom-range.mjs.map +1 -0
- package/dist/create-rects-from-dom-range.js +36 -0
- package/dist/create-rects-from-dom-range.js.map +1 -0
- package/dist/create-rects-from-dom-range.mjs +34 -0
- package/dist/create-rects-from-dom-range.mjs.map +1 -0
- package/dist/index.d.mts +30 -40
- package/dist/index.d.ts +30 -40
- package/dist/index.js +5 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -4
- package/dist/index.mjs.map +1 -1
- package/dist/liveblocks-config.js +3 -75
- package/dist/liveblocks-config.js.map +1 -1
- package/dist/liveblocks-config.mjs +4 -56
- package/dist/liveblocks-config.mjs.map +1 -1
- package/dist/liveblocks-plugin-provider.js +39 -43
- package/dist/liveblocks-plugin-provider.js.map +1 -1
- package/dist/liveblocks-plugin-provider.mjs +41 -44
- package/dist/liveblocks-plugin-provider.mjs.map +1 -1
- package/dist/mentions/avatar.js +10 -6
- package/dist/mentions/avatar.js.map +1 -1
- package/dist/mentions/avatar.mjs +10 -6
- package/dist/mentions/avatar.mjs.map +1 -1
- package/dist/mentions/mention-component.js +5 -18
- package/dist/mentions/mention-component.js.map +1 -1
- package/dist/mentions/mention-component.mjs +7 -19
- package/dist/mentions/mention-component.mjs.map +1 -1
- package/dist/mentions/mention-node.js +76 -80
- package/dist/mentions/mention-node.js.map +1 -1
- package/dist/mentions/mention-node.mjs +75 -81
- package/dist/mentions/mention-node.mjs.map +1 -1
- package/dist/mentions/mention-plugin.js +102 -90
- package/dist/mentions/mention-plugin.js.map +1 -1
- package/dist/mentions/mention-plugin.mjs +87 -71
- package/dist/mentions/mention-plugin.mjs.map +1 -1
- package/dist/mentions/suggestions.js +34 -6
- package/dist/mentions/suggestions.js.map +1 -1
- package/dist/mentions/suggestions.mjs +28 -3
- package/dist/mentions/suggestions.mjs.map +1 -1
- package/dist/mentions/user.js +8 -5
- package/dist/mentions/user.js.map +1 -1
- package/dist/mentions/user.mjs +8 -5
- package/dist/mentions/user.mjs.map +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/dist/version.mjs +1 -1
- package/dist/version.mjs.map +1 -1
- package/package.json +13 -13
- package/src/styles/constants.css +1 -0
- package/src/styles/index.css +158 -5
- package/src/styles/utils.css +6 -0
- package/styles.css +1 -1
- package/styles.css.map +1 -1
- package/dist/active-selection.js +0 -143
- package/dist/active-selection.js.map +0 -1
- package/dist/active-selection.mjs +0 -123
- package/dist/active-selection.mjs.map +0 -1
- package/dist/floating-selection-container.js +0 -157
- package/dist/floating-selection-container.js.map +0 -1
- package/dist/floating-selection-container.mjs +0 -155
- package/dist/floating-selection-container.mjs.map +0 -1
|
@@ -1,76 +1,73 @@
|
|
|
1
|
+
import { CollaborationContext } from '@lexical/react/LexicalCollaborationContext';
|
|
1
2
|
import { CollaborationPlugin } from '@lexical/react/LexicalCollaborationPlugin';
|
|
2
3
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
3
|
-
import { kInternal } from '@liveblocks/core';
|
|
4
|
-
import { useClient,
|
|
5
|
-
import
|
|
6
|
-
import React__default, {
|
|
4
|
+
import { kInternal, nn } from '@liveblocks/core';
|
|
5
|
+
import { useClient, useRoom, useSelf } from '@liveblocks/react';
|
|
6
|
+
import { LiveblocksYjsProvider } from '@liveblocks/yjs';
|
|
7
|
+
import React__default, { useContext, useRef, useEffect, useCallback } from 'react';
|
|
7
8
|
import { Doc } from 'yjs';
|
|
8
9
|
import { CommentPluginProvider } from './comments/comment-plugin-provider.mjs';
|
|
9
|
-
import {
|
|
10
|
-
import MentionPlugin from './mentions/mention-plugin.mjs';
|
|
10
|
+
import { MentionPlugin } from './mentions/mention-plugin.mjs';
|
|
11
11
|
|
|
12
|
-
const
|
|
13
|
-
const
|
|
12
|
+
const providersMap = /* @__PURE__ */ new Map();
|
|
13
|
+
const LiveblocksPlugin = ({
|
|
14
14
|
children
|
|
15
15
|
}) => {
|
|
16
16
|
const client = useClient();
|
|
17
17
|
const hasResolveMentionSuggestions = client[kInternal].resolveMentionSuggestions !== void 0;
|
|
18
|
-
const { useSelf, useRoom } = useRoomContextBundle();
|
|
19
18
|
const [editor] = useLexicalComposerContext();
|
|
20
19
|
const room = useRoom();
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
useEffect(() => {
|
|
24
|
-
const _provider = new LiveblocksProvider(room, doc);
|
|
25
|
-
setProvider(_provider);
|
|
26
|
-
return () => {
|
|
27
|
-
_provider.destroy();
|
|
28
|
-
setProvider(void 0);
|
|
29
|
-
};
|
|
30
|
-
}, [room, doc]);
|
|
20
|
+
const collabContext = useContext(CollaborationContext);
|
|
21
|
+
const previousRoomIdRef = useRef(null);
|
|
31
22
|
useEffect(() => {
|
|
32
23
|
if (process.env.NODE_ENV !== "production") {
|
|
33
24
|
if (!editor.getEditorState().isEmpty()) {
|
|
34
25
|
console.warn(
|
|
35
|
-
"Warning:
|
|
26
|
+
"Warning: LiveblocksPlugin: editorState in initialConfig detected, but must be null."
|
|
36
27
|
);
|
|
37
28
|
}
|
|
38
29
|
}
|
|
39
|
-
room[kInternal].reportTextEditor("lexical", "root");
|
|
40
30
|
}, []);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
room[kInternal].reportTextEditor("lexical", "root");
|
|
33
|
+
}, [room]);
|
|
41
34
|
const info = useSelf((me) => me.info);
|
|
42
|
-
const username = info?.name;
|
|
35
|
+
const username = info?.name || "";
|
|
43
36
|
const cursorcolor = info?.color;
|
|
44
37
|
const providerFactory = useCallback(
|
|
45
38
|
(id, yjsDocMap) => {
|
|
46
|
-
|
|
47
|
-
|
|
39
|
+
if (previousRoomIdRef.current !== null && previousRoomIdRef.current !== id) {
|
|
40
|
+
const previousProvider = providersMap.get(id);
|
|
41
|
+
if (previousProvider !== void 0) {
|
|
42
|
+
previousProvider.destroy();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
let doc = yjsDocMap.get(id);
|
|
46
|
+
if (doc === void 0) {
|
|
47
|
+
doc = new Doc();
|
|
48
|
+
const provider = new LiveblocksYjsProvider(room, doc);
|
|
49
|
+
yjsDocMap.set(id, doc);
|
|
50
|
+
providersMap.set(id, provider);
|
|
51
|
+
}
|
|
52
|
+
return nn(
|
|
53
|
+
providersMap.get(id),
|
|
54
|
+
"Internal error. Should never happen"
|
|
55
|
+
);
|
|
48
56
|
},
|
|
49
|
-
[
|
|
57
|
+
[room]
|
|
50
58
|
);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}, provider && /* @__PURE__ */ React__default.createElement(CollaborationPlugin, {
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
collabContext.name = username || "";
|
|
61
|
+
}, [collabContext, username]);
|
|
62
|
+
return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(CollaborationPlugin, {
|
|
63
|
+
key: room.id,
|
|
64
|
+
id: room.id,
|
|
58
65
|
providerFactory,
|
|
59
|
-
id: "liveblocks-document",
|
|
60
66
|
username,
|
|
61
67
|
cursorColor: cursorcolor,
|
|
62
68
|
shouldBootstrap: true
|
|
63
|
-
}), hasResolveMentionSuggestions && /* @__PURE__ */ React__default.createElement(MentionPlugin, null),
|
|
69
|
+
}), hasResolveMentionSuggestions && /* @__PURE__ */ React__default.createElement(MentionPlugin, null), /* @__PURE__ */ React__default.createElement(CommentPluginProvider, null, children));
|
|
64
70
|
};
|
|
65
|
-
function useLiveblocksLexicalConfigContext() {
|
|
66
|
-
const config = useContext(LiveblocksLexicalConfigContext);
|
|
67
|
-
if (config === null) {
|
|
68
|
-
throw new Error(
|
|
69
|
-
"useLiveblocksLexicalConfigContext must be used within a LiveblocksPluginProviderProvider"
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
return config;
|
|
73
|
-
}
|
|
74
71
|
|
|
75
|
-
export {
|
|
72
|
+
export { LiveblocksPlugin };
|
|
76
73
|
//# sourceMappingURL=liveblocks-plugin-provider.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"liveblocks-plugin-provider.mjs","sources":["../src/liveblocks-plugin-provider.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"liveblocks-plugin-provider.mjs","sources":["../src/liveblocks-plugin-provider.tsx"],"sourcesContent":["import { CollaborationContext } from \"@lexical/react/LexicalCollaborationContext\";\nimport { CollaborationPlugin } from \"@lexical/react/LexicalCollaborationPlugin\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport type { Provider } from \"@lexical/yjs\";\nimport { kInternal, nn } from \"@liveblocks/core\";\nimport { useClient, useRoom, useSelf } from \"@liveblocks/react\";\nimport { LiveblocksYjsProvider } from \"@liveblocks/yjs\";\nimport React, { useCallback, useContext, useEffect, useRef } from \"react\";\nimport { Doc } from \"yjs\";\n\nimport { CommentPluginProvider } from \"./comments/comment-plugin-provider\";\nimport { MentionPlugin } from \"./mentions/mention-plugin\";\n\n// TODO: Replace by ref once I understand why useRef is not stable (?!)\nconst providersMap = new Map<\n string,\n LiveblocksYjsProvider<never, never, never, never, never>\n>();\n\nexport type LiveblocksPluginProps = {\n children?: React.ReactNode;\n};\n\nexport const LiveblocksPlugin = ({\n children,\n}: LiveblocksPluginProps): JSX.Element => {\n const client = useClient();\n const hasResolveMentionSuggestions =\n client[kInternal].resolveMentionSuggestions !== undefined;\n const [editor] = useLexicalComposerContext();\n const room = useRoom();\n const collabContext = useContext(CollaborationContext);\n const previousRoomIdRef = useRef<string | null>(null);\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 useEffect(() => {\n // Report that this is lexical and root is the rootKey\n room[kInternal].reportTextEditor(\"lexical\", \"root\");\n }, [room]);\n\n // Get user info or allow override from props\n const info = useSelf((me) => me.info);\n const username = info?.name || \"\"; // use empty string to prevent random name\n const cursorcolor = info?.color as string | undefined;\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 useEffect(() => {\n collabContext.name = username || \"\";\n }, [collabContext, username]);\n\n return (\n <>\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={username}\n cursorColor={cursorcolor}\n shouldBootstrap={true}\n />\n\n {hasResolveMentionSuggestions && <MentionPlugin />}\n\n <CommentPluginProvider>{children}</CommentPluginProvider>\n </>\n );\n};\n"],"names":["React"],"mappings":";;;;;;;;;;;AAcA,MAAM,YAAA,uBAAmB,GAGvB,EAAA,CAAA;AAMK,MAAM,mBAAmB,CAAC;AAAA,EAC/B,QAAA;AACF,CAA0C,KAAA;AACxC,EAAA,MAAM,SAAS,SAAU,EAAA,CAAA;AACzB,EAAM,MAAA,4BAAA,GACJ,MAAO,CAAA,SAAA,CAAA,CAAW,yBAA8B,KAAA,KAAA,CAAA,CAAA;AAClD,EAAM,MAAA,CAAC,MAAM,CAAA,GAAI,yBAA0B,EAAA,CAAA;AAC3C,EAAA,MAAM,OAAO,OAAQ,EAAA,CAAA;AACrB,EAAM,MAAA,aAAA,GAAgB,WAAW,oBAAoB,CAAA,CAAA;AACrD,EAAM,MAAA,iBAAA,GAAoB,OAAsB,IAAI,CAAA,CAAA;AAGpD,EAAA,SAAA,CAAU,MAAM;AAEd,IAAI,IAAA,OAAA,CAAQ,GAAI,CAAA,QAAA,KAAa,YAAc,EAAA;AAEzC,MAAA,IAAI,CAAC,MAAA,CAAO,cAAe,EAAA,CAAE,SAAW,EAAA;AACtC,QAAQ,OAAA,CAAA,IAAA;AAAA,UACN,qFAAA;AAAA,SACF,CAAA;AAAA,OACF;AAAA,KACF;AAAA,GAIF,EAAG,EAAE,CAAA,CAAA;AAEL,EAAA,SAAA,CAAU,MAAM;AAEd,IAAK,IAAA,CAAA,SAAA,CAAA,CAAW,gBAAiB,CAAA,SAAA,EAAW,MAAM,CAAA,CAAA;AA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AA,CAAC,aAAe,EAAA,QAAQ,CAAC,CAAA,CAAA;AAE5B,EAAA,mGAEKA,cAAA,CAAA,aAAA,CAAA,mBAAA,EAAA;AAAA,IAGC,KAAK,IAAK,CAAA,EAAA;AAAA,IACV,IAAI,IAAK,CAAA,EAAA;AAAA,IACT,eAAA;AAAA,IACA,QAAA;AAAA,IACA,WAAa,EAAA,WAAA;AAAA,IACb,eAAiB,EAAA,IAAA;AAAA,GACnB,CAAA,EAEC,gDAAiCA,cAAA,CAAA,aAAA,CAAA,aAAA,EAAA,IAAc,mBAE/CA,cAAA,CAAA,aAAA,CAAA,qBAAA,EAAA,IAAA,EAAuB,QAAS,CACnC,CAAA,CAAA;AAEJ;;;;"}
|
package/dist/mentions/avatar.js
CHANGED
|
@@ -2,19 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
var react = require('@liveblocks/react');
|
|
4
4
|
var React = require('react');
|
|
5
|
+
var classnames = require('../classnames.js');
|
|
5
6
|
|
|
6
7
|
const Avatar = React.forwardRef(
|
|
7
8
|
function Avatar2(props, forwardedRef) {
|
|
8
|
-
const { userId, ...spanProps } = props;
|
|
9
|
-
const {
|
|
10
|
-
const { user, isLoading } = useUser(userId);
|
|
9
|
+
const { userId, className, ...spanProps } = props;
|
|
10
|
+
const { user, isLoading } = react.useUser(userId);
|
|
11
11
|
const avatar = user ? user.avatar : void 0;
|
|
12
12
|
const name = user ? user.name : void 0;
|
|
13
13
|
function Initials() {
|
|
14
14
|
const initials = name ? getInitials(name) : void 0;
|
|
15
15
|
if (initials) {
|
|
16
16
|
return /* @__PURE__ */ React.createElement("span", {
|
|
17
|
-
"aria-hidden": true
|
|
17
|
+
"aria-hidden": true,
|
|
18
|
+
className: "lb-avatar-fallback"
|
|
18
19
|
}, initials);
|
|
19
20
|
}
|
|
20
21
|
if (isLoading)
|
|
@@ -23,16 +24,19 @@ const Avatar = React.forwardRef(
|
|
|
23
24
|
return null;
|
|
24
25
|
return /* @__PURE__ */ React.createElement("span", {
|
|
25
26
|
"aria-label": userId,
|
|
26
|
-
title: userId
|
|
27
|
+
title: userId,
|
|
28
|
+
className: "lb-avatar-fallback"
|
|
27
29
|
}, getInitials(userId));
|
|
28
30
|
}
|
|
29
31
|
return /* @__PURE__ */ React.createElement("span", {
|
|
30
32
|
"data-loading": isLoading ? "" : void 0,
|
|
31
33
|
...spanProps,
|
|
34
|
+
className: classnames.classNames("lb-avatar", className),
|
|
32
35
|
ref: forwardedRef
|
|
33
36
|
}, avatar && /* @__PURE__ */ React.createElement("img", {
|
|
34
37
|
src: avatar,
|
|
35
|
-
alt: name
|
|
38
|
+
alt: name,
|
|
39
|
+
className: "lb-avatar-image"
|
|
36
40
|
}), /* @__PURE__ */ React.createElement(Initials, null));
|
|
37
41
|
}
|
|
38
42
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"avatar.js","sources":["../../src/mentions/avatar.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"avatar.js","sources":["../../src/mentions/avatar.tsx"],"sourcesContent":["import { useUser } from \"@liveblocks/react\";\nimport type { HTMLAttributes } from \"react\";\nimport React, { 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","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,cAAQ,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,uBACG,KAAA,CAAA,aAAA,CAAA,MAAA,EAAA;AAAA,UAAK,aAAW,EAAA,IAAA;AAAA,UAAC,SAAU,EAAA,oBAAA;AAAA,SAAA,EACzB,QACH,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,uBACG,KAAA,CAAA,aAAA,CAAA,MAAA,EA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
|
+
import { classNames } from '../classnames.mjs';
|
|
3
4
|
|
|
4
5
|
const Avatar = forwardRef(
|
|
5
6
|
function Avatar2(props, forwardedRef) {
|
|
6
|
-
const { userId, ...spanProps } = props;
|
|
7
|
-
const { useUser } = useSharedContextBundle();
|
|
7
|
+
const { userId, className, ...spanProps } = props;
|
|
8
8
|
const { user, isLoading } = useUser(userId);
|
|
9
9
|
const avatar = user ? user.avatar : void 0;
|
|
10
10
|
const name = user ? user.name : void 0;
|
|
@@ -12,7 +12,8 @@ const Avatar = forwardRef(
|
|
|
12
12
|
const initials = name ? getInitials(name) : void 0;
|
|
13
13
|
if (initials) {
|
|
14
14
|
return /* @__PURE__ */ React__default.createElement("span", {
|
|
15
|
-
"aria-hidden": true
|
|
15
|
+
"aria-hidden": true,
|
|
16
|
+
className: "lb-avatar-fallback"
|
|
16
17
|
}, initials);
|
|
17
18
|
}
|
|
18
19
|
if (isLoading)
|
|
@@ -21,16 +22,19 @@ const Avatar = forwardRef(
|
|
|
21
22
|
return null;
|
|
22
23
|
return /* @__PURE__ */ React__default.createElement("span", {
|
|
23
24
|
"aria-label": userId,
|
|
24
|
-
title: userId
|
|
25
|
+
title: userId,
|
|
26
|
+
className: "lb-avatar-fallback"
|
|
25
27
|
}, getInitials(userId));
|
|
26
28
|
}
|
|
27
29
|
return /* @__PURE__ */ React__default.createElement("span", {
|
|
28
30
|
"data-loading": isLoading ? "" : void 0,
|
|
29
31
|
...spanProps,
|
|
32
|
+
className: classNames("lb-avatar", className),
|
|
30
33
|
ref: forwardedRef
|
|
31
34
|
}, avatar && /* @__PURE__ */ React__default.createElement("img", {
|
|
32
35
|
src: avatar,
|
|
33
|
-
alt: name
|
|
36
|
+
alt: name,
|
|
37
|
+
className: "lb-avatar-image"
|
|
34
38
|
}), /* @__PURE__ */ React__default.createElement(Initials, null));
|
|
35
39
|
}
|
|
36
40
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"avatar.mjs","sources":["../../src/mentions/avatar.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"avatar.mjs","sources":["../../src/mentions/avatar.tsx"],"sourcesContent":["import { useUser } from \"@liveblocks/react\";\nimport type { HTMLAttributes } from \"react\";\nimport React, { 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","React","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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EnEA,cAAA,CAAA,aAAA,CAAA,QAAA,EAAA,IAAS,CACZ,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,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;;;;"}
|
|
@@ -5,8 +5,7 @@ var lexical = require('lexical');
|
|
|
5
5
|
var React = require('react');
|
|
6
6
|
var index_js = require('use-sync-external-store/shim/index.js');
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
function MentionWrapper({
|
|
8
|
+
function Mention({
|
|
10
9
|
nodeKey,
|
|
11
10
|
children
|
|
12
11
|
}) {
|
|
@@ -21,23 +20,12 @@ function MentionWrapper({
|
|
|
21
20
|
lexical.$setSelection(selection);
|
|
22
21
|
});
|
|
23
22
|
}
|
|
24
|
-
return /* @__PURE__ */ React.createElement(IsSelectedContext.Provider, {
|
|
25
|
-
value: isSelected
|
|
26
|
-
}, /* @__PURE__ */ React.createElement("span", {
|
|
27
|
-
onClick: handleClick
|
|
28
|
-
}, children));
|
|
29
|
-
}
|
|
30
|
-
const Mention = React.forwardRef(function(props, forwardedRef) {
|
|
31
|
-
const isSelected = React.useContext(IsSelectedContext);
|
|
32
|
-
if (isSelected === null) {
|
|
33
|
-
throw new Error("Mention component must be wrapped in MentionWrapper");
|
|
34
|
-
}
|
|
35
23
|
return /* @__PURE__ */ React.createElement("span", {
|
|
24
|
+
onClick: handleClick,
|
|
36
25
|
"data-selected": isSelected ? "" : void 0,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
});
|
|
26
|
+
className: "lb-lexical-mention"
|
|
27
|
+
}, children);
|
|
28
|
+
}
|
|
41
29
|
function $isNodeSelected(key) {
|
|
42
30
|
const node = lexical.$getNodeByKey(key);
|
|
43
31
|
if (node === null)
|
|
@@ -59,5 +47,4 @@ function useIsNodeSelected(key) {
|
|
|
59
47
|
}
|
|
60
48
|
|
|
61
49
|
exports.Mention = Mention;
|
|
62
|
-
exports.MentionWrapper = MentionWrapper;
|
|
63
50
|
//# sourceMappingURL=mention-component.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mention-component.js","sources":["../../src/mentions/mention-component.tsx"],"sourcesContent":["import { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport type { NodeKey } from \"lexical\";\nimport { $createNodeSelection, $getNodeByKey, $setSelection } from \"lexical\";\nimport type {
|
|
1
|
+
{"version":3,"file":"mention-component.js","sources":["../../src/mentions/mention-component.tsx"],"sourcesContent":["import { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport type { NodeKey } from \"lexical\";\nimport { $createNodeSelection, $getNodeByKey, $setSelection } from \"lexical\";\nimport type { ReactNode } from \"react\";\nimport React, { useCallback } from \"react\";\nimport { useSyncExternalStore } from \"use-sync-external-store/shim/index.js\";\n\nexport function Mention({\n nodeKey,\n children,\n}: {\n nodeKey: NodeKey;\n children: ReactNode;\n}) {\n const [editor] = useLexicalComposerContext();\n const isSelected = useIsNodeSelected(nodeKey);\n\n function handleClick(event: React.MouseEvent) {\n editor.update(() => {\n event.stopPropagation();\n event.preventDefault();\n\n const selection = $createNodeSelection();\n selection.add(nodeKey);\n $setSelection(selection);\n });\n }\n\n return (\n <span\n onClick={handleClick}\n data-selected={isSelected ? \"\" : undefined}\n className=\"lb-lexical-mention\"\n >\n {children}\n </span>\n );\n}\n\nfunction $isNodeSelected(key: NodeKey): boolean {\n const node = $getNodeByKey(key);\n if (node === null) return false;\n return node.isSelected();\n}\n\nfunction useIsNodeSelected(key: NodeKey) {\n const [editor] = useLexicalComposerContext();\n\n const subscribe = useCallback(\n (onStoreChange: () => void) => {\n return editor.registerUpdateListener(onStoreChange);\n },\n [editor]\n );\n\n const getSnapshot = useCallback(() => {\n return editor.getEditorState().read(() => $isNodeSelected(key));\n }, [editor, key]);\n\n return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n"],"names":["useLexicalComposerContext","$createNodeSelection","$setSelection","$getNodeByKey","useCallback","useSyncExternalStore"],"mappings":";;;;;;;AAOO,SAAS,OAAQ,CAAA;AAAA,EACtB,OAAA;AAAA,EACA,QAAA;AACF,CAGG,EAAA;AACD,EAAM,MAAA,CAAC,MAAM,CAAA,GAAIA,gDAA0B,EAAA,CAAA;AAC3C,EAAM,MAAA,UAAA,GAAa,kBAAkB,OAAO,CAAA,CAAA;AAE5C,EAAA,SAAS,YAAY,KAAyB,EAAA;AAC5C,IAAA,MAAA,CAAO,OAAO,MAAM;AAClB,MAAA,KAAA,CAAM,eAAgB,EAAA,CAAA;AACtB,MAAA,KAAA,CAAM,cAAe,EAAA,CAAA;AAErB,MAAA,MAAM,YAAYC,4BAAqB,EAAA,CAAA;AACvC,MAAA,SAAA,CAAU,IAAI,OAAO,CAAA,CAAA;AACrB,MAAAC,qBAAA,CAAc,SAAS,CAAA,CAAA;AAAA,KACxB,CAAA,CAAA;AAAA,GACH;AAEA,EAAA,uBACG,KAAA,CAAA,aAAA,CAAA,MAAA,EAAA;AAAA,IACC,OAAS,EAAA,WAAA;AAAA,IACT,eAAA,EAAe,aAAa,EAAK,GAAA,KAAA,CAAA;AAAA,IACjC,SAAU,EAAA,oBAAA;AAAA,GAAA,EAET,QACH,CAAA,CAAA;AAEJ,CAAA;AAEA,SAAS,gBAAgB,GAAuB,EAAA;AAC9C,EAAM,MAAA,IAAA,GAAOC,sBAAc,GAAG,CAAA,CAAA;AAC9B,EAAA,IAAI,IAAS,KAAA,IAAA;AAAM,IAAO,OAAA,KAAA,CAAA;AAC1B,EAAA,OAAO,KAAK,UAAW,EAAA,CAAA;AACzB,CAAA;AAEA,SAAS,kBAAkB,GAAc,EAAA;AACvC,EAAM,MAAA,CAAC,MAAM,CAAA,GAAIH,gDAA0B,EAAA,CAAA;AAE3C,EAAA,MAAM,SAAY,GAAAI,iBAAA;AAAA,IAChB,CAAC,aAA8B,KAAA;AAC7B,MAAO,OAAA,MAAA,CAAO,uBAAuB,aAAa,CAAA,CAAA;AAAA,KACpD;AAAA,IACA,CAAC,MAAM,CAAA;AAAA,GACT,CAAA;AAEA,EAAM,MAAA,WAAA,GAAcA,kBAAY,MAAM;AACpC,IAAA,OAAO,OAAO,cAAe,EAAA,CAAE,KAAK,MAAM,eAAA,CAAgB,GAAG,CAAC,CAAA,CAAA;AAAA,GAC7D,EAAA,CAAC,MAAQ,EAAA,GAAG,CAAC,CAAA,CAAA;AAEhB,EAAO,OAAAC,6BAAA,CAAqB,SAAW,EAAA,WAAA,EAAa,WAAW,CAAA,CAAA;AACjE;;;;"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
2
2
|
import { $createNodeSelection, $setSelection, $getNodeByKey } from 'lexical';
|
|
3
|
-
import React__default, {
|
|
3
|
+
import React__default, { useCallback } from 'react';
|
|
4
4
|
import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
function MentionWrapper({
|
|
6
|
+
function Mention({
|
|
8
7
|
nodeKey,
|
|
9
8
|
children
|
|
10
9
|
}) {
|
|
@@ -19,23 +18,12 @@ function MentionWrapper({
|
|
|
19
18
|
$setSelection(selection);
|
|
20
19
|
});
|
|
21
20
|
}
|
|
22
|
-
return /* @__PURE__ */ React__default.createElement(IsSelectedContext.Provider, {
|
|
23
|
-
value: isSelected
|
|
24
|
-
}, /* @__PURE__ */ React__default.createElement("span", {
|
|
25
|
-
onClick: handleClick
|
|
26
|
-
}, children));
|
|
27
|
-
}
|
|
28
|
-
const Mention = forwardRef(function(props, forwardedRef) {
|
|
29
|
-
const isSelected = useContext(IsSelectedContext);
|
|
30
|
-
if (isSelected === null) {
|
|
31
|
-
throw new Error("Mention component must be wrapped in MentionWrapper");
|
|
32
|
-
}
|
|
33
21
|
return /* @__PURE__ */ React__default.createElement("span", {
|
|
22
|
+
onClick: handleClick,
|
|
34
23
|
"data-selected": isSelected ? "" : void 0,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
});
|
|
24
|
+
className: "lb-lexical-mention"
|
|
25
|
+
}, children);
|
|
26
|
+
}
|
|
39
27
|
function $isNodeSelected(key) {
|
|
40
28
|
const node = $getNodeByKey(key);
|
|
41
29
|
if (node === null)
|
|
@@ -56,5 +44,5 @@ function useIsNodeSelected(key) {
|
|
|
56
44
|
return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
57
45
|
}
|
|
58
46
|
|
|
59
|
-
export { Mention
|
|
47
|
+
export { Mention };
|
|
60
48
|
//# sourceMappingURL=mention-component.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mention-component.mjs","sources":["../../src/mentions/mention-component.tsx"],"sourcesContent":["import { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport type { NodeKey } from \"lexical\";\nimport { $createNodeSelection, $getNodeByKey, $setSelection } from \"lexical\";\nimport type {
|
|
1
|
+
{"version":3,"file":"mention-component.mjs","sources":["../../src/mentions/mention-component.tsx"],"sourcesContent":["import { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport type { NodeKey } from \"lexical\";\nimport { $createNodeSelection, $getNodeByKey, $setSelection } from \"lexical\";\nimport type { ReactNode } from \"react\";\nimport React, { useCallback } from \"react\";\nimport { useSyncExternalStore } from \"use-sync-external-store/shim/index.js\";\n\nexport function Mention({\n nodeKey,\n children,\n}: {\n nodeKey: NodeKey;\n children: ReactNode;\n}) {\n const [editor] = useLexicalComposerContext();\n const isSelected = useIsNodeSelected(nodeKey);\n\n function handleClick(event: React.MouseEvent) {\n editor.update(() => {\n event.stopPropagation();\n event.preventDefault();\n\n const selection = $createNodeSelection();\n selection.add(nodeKey);\n $setSelection(selection);\n });\n }\n\n return (\n <span\n onClick={handleClick}\n data-selected={isSelected ? \"\" : undefined}\n className=\"lb-lexical-mention\"\n >\n {children}\n </span>\n );\n}\n\nfunction $isNodeSelected(key: NodeKey): boolean {\n const node = $getNodeByKey(key);\n if (node === null) return false;\n return node.isSelected();\n}\n\nfunction useIsNodeSelected(key: NodeKey) {\n const [editor] = useLexicalComposerContext();\n\n const subscribe = useCallback(\n (onStoreChange: () => void) => {\n return editor.registerUpdateListener(onStoreChange);\n },\n [editor]\n );\n\n const getSnapshot = useCallback(() => {\n return editor.getEditorState().read(() => $isNodeSelected(key));\n }, [editor, key]);\n\n return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n"],"names":["React"],"mappings":";;;;;AAOO,SAAS,OAAQ,CAAA;AAAA,EACtB,OAAA;AAAA,EACA,QAAA;AACF,CAGG,EAAA;AACD,EAAM,MAAA,CAAC,MAAM,CAAA,GAAI,yBAA0B,EAAA,CAAA;AAC3C,EAAM,MAAA,UAAA,GAAa,kBAAkB,OAAO,CAAA,CAAA;AAE5C,EAAA,SAAS,YAAY,KAAyB,EAAA;AAC5C,IAAA,MAAA,CAAO,OAAO,MAAM;AAClB,MAAA,KAAA,CAAM,eAAgB,EAAA,CAAA;AACtB,MAAA,KAAA,CAAM,cAAe,EAAA,CAAA;AAErB,MAAA,MAAM,YAAY,oBAAqB,EAAA,CAAA;AACvC,MAAA,SAAA,CAAU,IAAI,OAAO,CAAA,CAAA;AACrB,MAAA,aAAA,CAAc,SAAS,CAAA,CAAA;AAAA,KACxB,CAAA,CAAA;AAAA,GACH;AAEA,EAAA,uBACGA,cAAA,CAAA,aAAA,CAAA,MAAA,EAAA;AAAA,IACC,OAAS,EAAA,WAAA;AAAA,IACT,eAAA,EAAe,aAAa,EAAK,GAAA,KAAA,CAAA;AAAA,IACjC,SAAU,EAAA,oBAAA;AAAA,GAAA,EAET,QACH,CAAA,CAAA;AAEJ,CAAA;AAEA,SAAS,gBAAgB,GAAuB,EAAA;AAC9C,EAAM,MAAA,IAAA,GAAO,cAAc,GAAG,CAAA,CAAA;AAC9B,EAAA,IAAI,IAAS,KAAA,IAAA;AAAM,IAAO,OAAA,KAAA,CAAA;AAC1B,EAAA,OAAO,KAAK,UAAW,EAAA,CAAA;AACzB,CAAA;AAEA,SAAS,kBAAkB,GAAc,EAAA;AACvC,EAAM,MAAA,CAAC,MAAM,CAAA,GAAI,yBAA0B,EAAA,CAAA;AAE3C,EAAA,MAAM,SAAY,GAAA,WAAA;AAAA,IAChB,CAAC,aAA8B,KAAA;AAC7B,MAAO,OAAA,MAAA,CAAO,uBAAuB,aAAa,CAAA,CAAA;AAAA,KACpD;AAAA,IACA,CAAC,MAAM,CAAA;AAAA,GACT,CAAA;AAEA,EAAM,MAAA,WAAA,GAAc,YAAY,MAAM;AACpC,IAAA,OAAO,OAAO,cAAe,EAAA,CAAE,KAAK,MAAM,eAAA,CAAgB,GAAG,CAAC,CAAA,CAAA;AAAA,GAC7D,EAAA,CAAC,MAAQ,EAAA,GAAG,CAAC,CAAA,CAAA;AAEhB,EAAO,OAAA,oBAAA,CAAqB,SAAW,EAAA,WAAA,EAAa,WAAW,CAAA,CAAA;AACjE;;;;"}
|
|
@@ -4,6 +4,7 @@ var lexical = require('lexical');
|
|
|
4
4
|
var nanoid = require('nanoid');
|
|
5
5
|
var React = require('react');
|
|
6
6
|
var mentionComponent = require('./mention-component.js');
|
|
7
|
+
var user = require('./user.js');
|
|
7
8
|
|
|
8
9
|
function _interopNamespaceDefault(e) {
|
|
9
10
|
var n = Object.create(null);
|
|
@@ -24,89 +25,84 @@ function _interopNamespaceDefault(e) {
|
|
|
24
25
|
|
|
25
26
|
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
static getType() {
|
|
35
|
-
return "lb-mention";
|
|
36
|
-
}
|
|
37
|
-
static clone(node) {
|
|
38
|
-
return new MentionNode(node.__id, node.__userId);
|
|
39
|
-
}
|
|
40
|
-
createDOM() {
|
|
41
|
-
const element = document.createElement("span");
|
|
42
|
-
element.style.display = "inline-block";
|
|
43
|
-
return element;
|
|
44
|
-
}
|
|
45
|
-
updateDOM() {
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
static importDom() {
|
|
49
|
-
return {
|
|
50
|
-
span: () => ({
|
|
51
|
-
conversion: (element) => {
|
|
52
|
-
const value = atob(
|
|
53
|
-
element.getAttribute("data-lexical-lb-mention")
|
|
54
|
-
);
|
|
55
|
-
const node = $createMentionNode(value);
|
|
56
|
-
return { node };
|
|
57
|
-
},
|
|
58
|
-
priority: 1
|
|
59
|
-
})
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
exportDOM() {
|
|
63
|
-
const element = document.createElement("span");
|
|
64
|
-
const value = this.getTextContent();
|
|
65
|
-
element.setAttribute("data-lexical-lb-mention", btoa(value));
|
|
66
|
-
element.textContent = this.getTextContent();
|
|
67
|
-
return { element };
|
|
68
|
-
}
|
|
69
|
-
static importJSON(serializedNode) {
|
|
70
|
-
const node = $createMentionNode(serializedNode.userId);
|
|
71
|
-
return node;
|
|
72
|
-
}
|
|
73
|
-
exportJSON() {
|
|
74
|
-
return {
|
|
75
|
-
userId: this.__userId,
|
|
76
|
-
type: "lb-mention",
|
|
77
|
-
version: 1
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
getUserId() {
|
|
81
|
-
const self = this.getLatest();
|
|
82
|
-
return self.__userId;
|
|
83
|
-
}
|
|
84
|
-
getId() {
|
|
85
|
-
const self = this.getLatest();
|
|
86
|
-
return self.__id;
|
|
87
|
-
}
|
|
88
|
-
decorate() {
|
|
89
|
-
return /* @__PURE__ */ React__namespace.createElement(mentionComponent.MentionWrapper, {
|
|
90
|
-
nodeKey: this.getKey()
|
|
91
|
-
}, /* @__PURE__ */ React__namespace.createElement(Component, {
|
|
92
|
-
userId: this.__userId
|
|
93
|
-
}));
|
|
94
|
-
}
|
|
28
|
+
const MENTION_CHARACTER = "@";
|
|
29
|
+
class MentionNode extends lexical.DecoratorNode {
|
|
30
|
+
constructor(id, userId, key) {
|
|
31
|
+
super(key);
|
|
32
|
+
this.__id = id;
|
|
33
|
+
this.__userId = userId;
|
|
95
34
|
}
|
|
96
|
-
|
|
97
|
-
return
|
|
35
|
+
static getType() {
|
|
36
|
+
return "lb-mention";
|
|
98
37
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const node = new MentionNode(id, userId);
|
|
102
|
-
return lexical.$applyNodeReplacement(node);
|
|
38
|
+
static clone(node) {
|
|
39
|
+
return new MentionNode(node.__id, node.__userId);
|
|
103
40
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
41
|
+
createDOM() {
|
|
42
|
+
const element = document.createElement("span");
|
|
43
|
+
element.style.display = "inline-block";
|
|
44
|
+
element.style.userSelect = "none";
|
|
45
|
+
return element;
|
|
46
|
+
}
|
|
47
|
+
updateDOM() {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
static importDom() {
|
|
51
|
+
return {
|
|
52
|
+
span: () => ({
|
|
53
|
+
conversion: (element) => {
|
|
54
|
+
const value = atob(element.getAttribute("data-lexical-lb-mention"));
|
|
55
|
+
const node = $createMentionNode(value);
|
|
56
|
+
return { node };
|
|
57
|
+
},
|
|
58
|
+
priority: 1
|
|
59
|
+
})
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
exportDOM() {
|
|
63
|
+
const element = document.createElement("span");
|
|
64
|
+
const value = this.getTextContent();
|
|
65
|
+
element.setAttribute("data-lexical-lb-mention", btoa(value));
|
|
66
|
+
element.textContent = this.getTextContent();
|
|
67
|
+
return { element };
|
|
68
|
+
}
|
|
69
|
+
static importJSON(serializedNode) {
|
|
70
|
+
const node = $createMentionNode(serializedNode.userId);
|
|
71
|
+
return node;
|
|
72
|
+
}
|
|
73
|
+
exportJSON() {
|
|
74
|
+
return {
|
|
75
|
+
userId: this.__userId,
|
|
76
|
+
type: "lb-mention",
|
|
77
|
+
version: 1
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
getUserId() {
|
|
81
|
+
const self = this.getLatest();
|
|
82
|
+
return self.__userId;
|
|
83
|
+
}
|
|
84
|
+
getId() {
|
|
85
|
+
const self = this.getLatest();
|
|
86
|
+
return self.__id;
|
|
87
|
+
}
|
|
88
|
+
decorate() {
|
|
89
|
+
return /* @__PURE__ */ React__namespace.createElement(mentionComponent.Mention, {
|
|
90
|
+
nodeKey: this.getKey()
|
|
91
|
+
}, MENTION_CHARACTER, /* @__PURE__ */ React__namespace.createElement(user.User, {
|
|
92
|
+
userId: this.getUserId()
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function $isMentionNode(node) {
|
|
97
|
+
return node instanceof MentionNode;
|
|
98
|
+
}
|
|
99
|
+
function $createMentionNode(userId) {
|
|
100
|
+
const id = `in_${nanoid.nanoid()}`;
|
|
101
|
+
const node = new MentionNode(id, userId);
|
|
102
|
+
return lexical.$applyNodeReplacement(node);
|
|
109
103
|
}
|
|
110
104
|
|
|
111
|
-
exports
|
|
105
|
+
exports.$createMentionNode = $createMentionNode;
|
|
106
|
+
exports.$isMentionNode = $isMentionNode;
|
|
107
|
+
exports.MentionNode = MentionNode;
|
|
112
108
|
//# sourceMappingURL=mention-node.js.map
|