@innoviatech/lexical-text-editor 1.0.5 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +105 -35
- package/dist/components/ContentPreview.d.ts +1 -1
- package/dist/components/HeadingSelectionList.d.ts +1 -1
- package/dist/components/LexicalTextEditor.d.ts +1 -1
- package/dist/components/common/Dialog.d.ts +9 -0
- package/dist/components/common/Popover.d.ts +21 -0
- package/dist/components/common/Tooltip.d.ts +10 -0
- package/dist/components/ui/button.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lexical-editor.css +1 -0
- package/dist/nodes/ExtendedTextNode.d.ts +11 -0
- package/dist/nodes/ImageNode.d.ts +1 -1
- package/dist/plugins/YoutubePlugin.d.ts +1 -0
- package/package.json +20 -16
- package/rollup.config.js +3 -4
- package/src/components/AlignmentSelectionList.tsx +41 -24
- package/src/components/ColorPicker.tsx +7 -21
- package/src/components/ContentPreview.tsx +27 -20
- package/src/components/DropdownList.tsx +39 -24
- package/src/components/HeadingSelectionList.tsx +48 -32
- package/src/components/ImageComponent.tsx +52 -19
- package/src/components/InsertDropdownList.tsx +1 -1
- package/src/components/LexicalTextEditor.tsx +33 -28
- package/src/components/LinkModal.tsx +42 -45
- package/src/components/common/Dialog.tsx +47 -0
- package/src/components/common/Popover.tsx +87 -0
- package/src/components/common/Tooltip.tsx +43 -0
- package/src/components/ui/command.tsx +0 -1
- package/src/nodes/ExtendedTextNode.tsx +174 -0
- package/src/nodes/ImageNode.tsx +48 -9
- package/src/plugins/ColorPlugin.tsx +19 -14
- package/src/plugins/ImagePlugin.tsx +79 -84
- package/src/plugins/ListPlugin.tsx +20 -38
- package/src/plugins/ToolbarPlugin.tsx +76 -78
- package/src/plugins/VideoPlugin.tsx +46 -55
- package/src/plugins/YoutubePlugin.tsx +83 -0
- package/src/styles/lexical-editor.css +962 -3
- package/dist/style.css +0 -3
- package/postcss.config.js +0 -6
- package/src/assets/react.svg +0 -1
package/src/nodes/ImageNode.tsx
CHANGED
|
@@ -29,13 +29,46 @@ export const $createImageNode = (payload: {
|
|
|
29
29
|
return $applyNodeReplacement(new ImageNode(payload));
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
+
// const convertImageElement = (domNode: Node): DOMConversionOutput | null => {
|
|
33
|
+
// if (domNode instanceof HTMLImageElement) {
|
|
34
|
+
// const { src, alt } = domNode;
|
|
35
|
+
// const node = $createImageNode({ src, altText: alt });
|
|
36
|
+
// return { node };
|
|
37
|
+
// }
|
|
38
|
+
// return null;
|
|
39
|
+
// };
|
|
40
|
+
|
|
32
41
|
const convertImageElement = (domNode: Node): DOMConversionOutput | null => {
|
|
33
|
-
if (domNode instanceof HTMLImageElement)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
if (!(domNode instanceof HTMLImageElement)) return null;
|
|
43
|
+
|
|
44
|
+
const { src, alt } = domNode;
|
|
45
|
+
|
|
46
|
+
// Try reading width/height from attributes
|
|
47
|
+
let width: number | "inherit" | undefined = undefined;
|
|
48
|
+
let height: number | "inherit" | undefined = undefined;
|
|
49
|
+
|
|
50
|
+
if (domNode.width) width = domNode.width;
|
|
51
|
+
if (domNode.height) height = domNode.height;
|
|
52
|
+
|
|
53
|
+
// Also check inline styles if attributes are missing
|
|
54
|
+
const style = domNode.style;
|
|
55
|
+
if ((!width || width === 0) && style.width) {
|
|
56
|
+
const parsed = parseInt(style.width);
|
|
57
|
+
if (!isNaN(parsed)) width = parsed;
|
|
37
58
|
}
|
|
38
|
-
|
|
59
|
+
if ((!height || height === 0) && style.height) {
|
|
60
|
+
const parsed = parseInt(style.height);
|
|
61
|
+
if (!isNaN(parsed)) height = parsed;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const node = $createImageNode({
|
|
65
|
+
src,
|
|
66
|
+
altText: alt,
|
|
67
|
+
width,
|
|
68
|
+
height,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
return { node };
|
|
39
72
|
};
|
|
40
73
|
|
|
41
74
|
export class ImageNode extends DecoratorNode<JSX.Element> {
|
|
@@ -105,9 +138,13 @@ export class ImageNode extends DecoratorNode<JSX.Element> {
|
|
|
105
138
|
}
|
|
106
139
|
|
|
107
140
|
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
108
145
|
static importDOM(): DOMConversionMap | null {
|
|
109
146
|
return {
|
|
110
|
-
img: () => ({ conversion: convertImageElement, priority:
|
|
147
|
+
img: () => ({ conversion: convertImageElement, priority: 1 }),
|
|
111
148
|
};
|
|
112
149
|
}
|
|
113
150
|
|
|
@@ -138,10 +175,12 @@ export class ImageNode extends DecoratorNode<JSX.Element> {
|
|
|
138
175
|
writable.__width = width;
|
|
139
176
|
writable.__height = height;
|
|
140
177
|
}
|
|
141
|
-
updateDOM(): boolean {
|
|
142
|
-
return
|
|
178
|
+
updateDOM(prevNode: ImageNode): boolean {
|
|
179
|
+
return (
|
|
180
|
+
prevNode.__width !== this.__width ||
|
|
181
|
+
prevNode.__height !== this.__height
|
|
182
|
+
);
|
|
143
183
|
}
|
|
144
|
-
|
|
145
184
|
decorate(): JSX.Element {
|
|
146
185
|
return (
|
|
147
186
|
<ImageComponent
|
|
@@ -6,6 +6,7 @@ import { useEffect, useState } from 'react';
|
|
|
6
6
|
import { mergeRegister } from '@lexical/utils';
|
|
7
7
|
import { LOW_PRIORIRTY } from '../constants';
|
|
8
8
|
import { AiOutlineBgColors, AiOutlineFontColors } from 'react-icons/ai';
|
|
9
|
+
import TooltipX from '../components/common/Tooltip';
|
|
9
10
|
|
|
10
11
|
export default function ColorPlugin() {
|
|
11
12
|
const [editor] = useLexicalComposerContext();
|
|
@@ -61,20 +62,24 @@ export default function ColorPlugin() {
|
|
|
61
62
|
|
|
62
63
|
return (
|
|
63
64
|
<>
|
|
64
|
-
<
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
65
|
+
<TooltipX content="Font Color" direction="bottom">
|
|
66
|
+
<ColorPicker
|
|
67
|
+
color={color}
|
|
68
|
+
onChange={(color) => {
|
|
69
|
+
updateColor({ property: 'color', color })
|
|
70
|
+
}}
|
|
71
|
+
icon={<AiOutlineFontColors />}
|
|
72
|
+
/>
|
|
73
|
+
</TooltipX>
|
|
74
|
+
<TooltipX content="Background Color" direction="bottom">
|
|
75
|
+
<ColorPicker
|
|
76
|
+
color={bgColor}
|
|
77
|
+
onChange={(color) => {
|
|
78
|
+
updateColor({ property: 'background', color })
|
|
79
|
+
}}
|
|
80
|
+
icon={<AiOutlineBgColors />}
|
|
81
|
+
/>
|
|
82
|
+
</TooltipX>
|
|
78
83
|
</>
|
|
79
84
|
)
|
|
80
85
|
}
|
|
@@ -1,32 +1,22 @@
|
|
|
1
|
-
|
|
2
1
|
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
3
2
|
import { $insertNodes } from "lexical";
|
|
4
3
|
import { $createImageNode } from "../nodes/ImageNode";
|
|
5
4
|
import { useRef, useState } from "react";
|
|
6
|
-
import { Upload } from "lucide-react";
|
|
7
|
-
import {
|
|
8
|
-
Dialog,
|
|
9
|
-
DialogContent,
|
|
10
|
-
DialogHeader,
|
|
11
|
-
DialogTitle,
|
|
12
|
-
DialogFooter,
|
|
13
|
-
DialogTrigger,
|
|
14
|
-
} from "../components/ui/dialog";
|
|
15
|
-
import { Button } from "../components/ui/button";
|
|
16
|
-
import { Input } from "../components/ui/input";
|
|
17
5
|
import { IoImageOutline } from "react-icons/io5";
|
|
6
|
+
import RawDialog from "../components/common/Dialog";
|
|
7
|
+
import { LuUpload } from "react-icons/lu";
|
|
18
8
|
|
|
19
9
|
export default function ImagePlugin() {
|
|
10
|
+
const [editor] = useLexicalComposerContext();
|
|
11
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
12
|
+
|
|
20
13
|
const [isOpen, setIsOpen] = useState(false);
|
|
21
14
|
const [url, setURL] = useState("");
|
|
22
15
|
const [altText, setAltText] = useState("");
|
|
23
16
|
const [file, setFile] = useState<File>();
|
|
24
|
-
const inputRef = useRef<HTMLInputElement>(null);
|
|
25
|
-
const [editor] = useLexicalComposerContext();
|
|
26
17
|
|
|
27
|
-
const
|
|
28
|
-
let src =
|
|
29
|
-
if (url) src = url;
|
|
18
|
+
const addImage = () => {
|
|
19
|
+
let src = url;
|
|
30
20
|
if (file) src = URL.createObjectURL(file);
|
|
31
21
|
|
|
32
22
|
editor.update(() => {
|
|
@@ -35,89 +25,94 @@ export default function ImagePlugin() {
|
|
|
35
25
|
});
|
|
36
26
|
|
|
37
27
|
setFile(undefined);
|
|
38
|
-
setAltText("")
|
|
28
|
+
setAltText("");
|
|
39
29
|
setURL("");
|
|
40
30
|
setIsOpen(false);
|
|
41
31
|
};
|
|
42
32
|
|
|
43
33
|
return (
|
|
44
|
-
<div>
|
|
45
|
-
{/*
|
|
34
|
+
<div className="lexical-text-editor-dialog">
|
|
35
|
+
{/* hidden file input */}
|
|
46
36
|
<input
|
|
47
37
|
type="file"
|
|
48
38
|
ref={inputRef}
|
|
49
39
|
accept="image/*"
|
|
50
|
-
className="hidden"
|
|
40
|
+
className="lte-hidden"
|
|
51
41
|
onChange={(e) => {
|
|
52
|
-
const
|
|
53
|
-
if (
|
|
54
|
-
e.target.value = "";
|
|
42
|
+
const f = e.target.files?.[0];
|
|
43
|
+
if (f) setFile(f);
|
|
44
|
+
e.target.value = "";
|
|
55
45
|
}}
|
|
56
46
|
/>
|
|
57
47
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
</DialogTrigger>
|
|
68
|
-
|
|
69
|
-
<DialogContent className="sm:max-w-md">
|
|
70
|
-
<DialogHeader>
|
|
71
|
-
<DialogTitle className="!text-lg text-gray-800">
|
|
72
|
-
Add Image
|
|
73
|
-
</DialogTitle>
|
|
74
|
-
</DialogHeader>
|
|
75
|
-
|
|
76
|
-
<div className="flex flex-col gap-4 py-2">
|
|
77
|
-
<div className="flex flex-col items-center gap-4">
|
|
78
|
-
<Input
|
|
79
|
-
value={altText}
|
|
80
|
-
onChange={(e) => setAltText(e.target.value)}
|
|
81
|
-
placeholder="Alt text"
|
|
82
|
-
/>
|
|
83
|
-
<Input
|
|
84
|
-
value={url}
|
|
85
|
-
onChange={(e) => setURL(e.target.value)}
|
|
86
|
-
placeholder="Add Image by URL"
|
|
87
|
-
/>
|
|
88
|
-
|
|
89
|
-
{/* Stylish OR divider */}
|
|
90
|
-
<div className="flex items-center w-full text-gray-500 text-sm">
|
|
91
|
-
<div className="flex-grow border-t border-gray-300"></div>
|
|
92
|
-
<span className="mx-2">or</span>
|
|
93
|
-
<div className="flex-grow border-t border-gray-300"></div>
|
|
94
|
-
</div>
|
|
95
|
-
|
|
96
|
-
<div className="flex flex-col gap-2 w-fit">
|
|
97
|
-
<Button
|
|
98
|
-
variant="outline"
|
|
99
|
-
className="flex items-center gap-2 bg-gray-50 hover:bg-gray-100"
|
|
100
|
-
onClick={() => inputRef.current?.click()}
|
|
101
|
-
>
|
|
102
|
-
<Upload className="h-4 w-4" /> Upload Image
|
|
103
|
-
</Button>
|
|
104
|
-
{file && <span className="text-sm text-gray-600">{file.name}</span>}
|
|
105
|
-
</div>
|
|
106
|
-
</div>
|
|
48
|
+
{/* Open dialog button */}
|
|
49
|
+
<button
|
|
50
|
+
className={`size-8 lexical-btn ${isOpen ? "toolbarActive" : "toolbar"} icon`}
|
|
51
|
+
onClick={() => setIsOpen((prev) => !prev)}
|
|
52
|
+
>
|
|
53
|
+
<IoImageOutline size={18} />
|
|
54
|
+
</button>
|
|
55
|
+
|
|
56
|
+
|
|
107
57
|
|
|
58
|
+
{/* Dialog */}
|
|
59
|
+
<RawDialog open={isOpen} onClose={() => setIsOpen(false)}>
|
|
60
|
+
<div className="lte-dialog-header">Add Image</div>
|
|
61
|
+
|
|
62
|
+
<div className="lte-dialog-body">
|
|
63
|
+
<input
|
|
64
|
+
className="lte-input"
|
|
65
|
+
placeholder="Alt text"
|
|
66
|
+
value={altText}
|
|
67
|
+
onChange={(e) => setAltText(e.target.value)}
|
|
68
|
+
/>
|
|
69
|
+
|
|
70
|
+
<input
|
|
71
|
+
className="lte-input"
|
|
72
|
+
placeholder="Add image by URL"
|
|
73
|
+
value={url}
|
|
74
|
+
onChange={(e) => setURL(e.target.value)}
|
|
75
|
+
/>
|
|
76
|
+
|
|
77
|
+
<div className="lte-divider">
|
|
78
|
+
<span>or</span>
|
|
108
79
|
</div>
|
|
109
80
|
|
|
110
|
-
<
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
81
|
+
{/* <button
|
|
82
|
+
className="lte-outline-btn"
|
|
83
|
+
onClick={() => inputRef.current?.click()}
|
|
84
|
+
>
|
|
85
|
+
|
|
86
|
+
Upload Image
|
|
87
|
+
</button> */}
|
|
88
|
+
|
|
89
|
+
<button
|
|
90
|
+
className={`lexical-btn heading-trigger toolbar-active`}
|
|
91
|
+
onClick={() => inputRef.current?.click()}
|
|
92
|
+
style={{
|
|
93
|
+
width: 'fit-content',
|
|
94
|
+
margin: '0 auto'
|
|
95
|
+
}}
|
|
96
|
+
>
|
|
97
|
+
<LuUpload size={20} />
|
|
98
|
+
<span>Upload Image</span>
|
|
99
|
+
</button>
|
|
100
|
+
|
|
101
|
+
{file && (
|
|
102
|
+
<div className="lte-file-name">{file.name}</div>
|
|
103
|
+
)}
|
|
104
|
+
</div>
|
|
105
|
+
|
|
106
|
+
<div className="lte-dialog-footer">
|
|
107
|
+
<button
|
|
108
|
+
className="lte-primary-btn"
|
|
109
|
+
disabled={!url && !file}
|
|
110
|
+
onClick={addImage}
|
|
111
|
+
>
|
|
112
|
+
Add Image
|
|
113
|
+
</button>
|
|
114
|
+
</div>
|
|
115
|
+
</RawDialog>
|
|
121
116
|
</div>
|
|
122
117
|
);
|
|
123
118
|
}
|
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
|
|
2
|
-
import { Button } from "../components/ui/button";
|
|
3
|
-
import {
|
|
4
|
-
Tooltip,
|
|
5
|
-
TooltipTrigger,
|
|
6
|
-
TooltipContent,
|
|
7
|
-
} from "../components/ui/tooltip";
|
|
8
2
|
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
9
3
|
import {
|
|
10
4
|
INSERT_ORDERED_LIST_COMMAND,
|
|
@@ -12,6 +6,7 @@ import {
|
|
|
12
6
|
REMOVE_LIST_COMMAND,
|
|
13
7
|
} from "@lexical/list";
|
|
14
8
|
import { BsListOl, BsListUl } from "react-icons/bs";
|
|
9
|
+
import TooltipX from "../components/common/Tooltip";
|
|
15
10
|
|
|
16
11
|
interface ListPluginProps {
|
|
17
12
|
blockType: string;
|
|
@@ -38,39 +33,26 @@ export default function ListPlugin({ blockType }: ListPluginProps) {
|
|
|
38
33
|
|
|
39
34
|
return (
|
|
40
35
|
<>
|
|
41
|
-
<
|
|
42
|
-
<
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
36
|
+
<TooltipX content="Ordered list" direction="bottom">
|
|
37
|
+
<button
|
|
38
|
+
className={`size-8 lexical-btn ${blockType === "ol" ? "toolbarActive" : "toolbar"
|
|
39
|
+
} icon`}
|
|
40
|
+
onClick={handleOrderedList}
|
|
41
|
+
>
|
|
42
|
+
<BsListOl />
|
|
43
|
+
</button>
|
|
44
|
+
</TooltipX>
|
|
45
|
+
|
|
46
|
+
<TooltipX content="Unordered list" direction="bottom">
|
|
47
|
+
<button
|
|
48
|
+
className={`size-8 lexical-btn ${blockType === "ul" ? "toolbarActive" : "toolbar"
|
|
49
|
+
} icon`}
|
|
50
|
+
onClick={handleUnorderedList}
|
|
51
|
+
>
|
|
52
|
+
<BsListUl />
|
|
53
|
+
</button>
|
|
54
|
+
</TooltipX>
|
|
57
55
|
|
|
58
|
-
<Tooltip delayDuration={700}>
|
|
59
|
-
<TooltipTrigger asChild>
|
|
60
|
-
<Button
|
|
61
|
-
variant={blockType === "ul" ? "toolbarActive" : "toolbar"}
|
|
62
|
-
size="icon"
|
|
63
|
-
className="size-8"
|
|
64
|
-
aria-label="Add unordered list"
|
|
65
|
-
onClick={handleUnorderedList}
|
|
66
|
-
>
|
|
67
|
-
<BsListUl />
|
|
68
|
-
</Button>
|
|
69
|
-
</TooltipTrigger>
|
|
70
|
-
<TooltipContent side="bottom">
|
|
71
|
-
Unordered list
|
|
72
|
-
</TooltipContent>
|
|
73
|
-
</Tooltip>
|
|
74
56
|
</>
|
|
75
57
|
);
|
|
76
58
|
}
|
|
@@ -14,10 +14,7 @@ import {
|
|
|
14
14
|
$isLinkNode,
|
|
15
15
|
} from "@lexical/link";
|
|
16
16
|
|
|
17
|
-
// import ColorPlugin from "./ColorPlugin"
|
|
18
|
-
// import ListPlugin from "./ListPlugin"
|
|
19
17
|
import { $isListNode, ListNode } from '@lexical/list'
|
|
20
|
-
import { Button } from "../components/ui/button"
|
|
21
18
|
import { Tooltip, TooltipContent, TooltipTrigger } from "../components/ui/tooltip"
|
|
22
19
|
import { DropdownList } from "../components/DropdownList"
|
|
23
20
|
import Separator from "../components/Separator"
|
|
@@ -30,8 +27,7 @@ import ListPlugin from "./ListPlugin"
|
|
|
30
27
|
import ImagePlugin from "./ImagePlugin"
|
|
31
28
|
import VideoPlugin from "./VideoPlugin"
|
|
32
29
|
import ContentPreviewDialog from "../components/ContentPreview"
|
|
33
|
-
|
|
34
|
-
// import YoutubePlugin from "./YoutubePlugin"
|
|
30
|
+
import TooltipX from "../components/common/Tooltip"
|
|
35
31
|
|
|
36
32
|
export const ToolbarPlugin = ({ value }: { value: string }) => {
|
|
37
33
|
|
|
@@ -112,6 +108,7 @@ export const ToolbarPlugin = ({ value }: { value: string }) => {
|
|
|
112
108
|
[HeadingAction.H6]: tag === "h6",
|
|
113
109
|
[HeadingAction.Normal]: element.getType() === "paragraph",
|
|
114
110
|
};
|
|
111
|
+
setBlockType(element.getType())
|
|
115
112
|
setHeadingSelectionMap(newHeadingSelectionMap);
|
|
116
113
|
}
|
|
117
114
|
else {
|
|
@@ -338,16 +335,41 @@ export const ToolbarPlugin = ({ value }: { value: string }) => {
|
|
|
338
335
|
});
|
|
339
336
|
};
|
|
340
337
|
|
|
338
|
+
// const insertLink = useCallback(() => {
|
|
339
|
+
// console.log('insertlink');
|
|
340
|
+
// const selection = $getSelection();
|
|
341
|
+
// if (!$isRangeSelection(selection) || selection.isCollapsed()) {
|
|
342
|
+
// // Nothing selected → do nothing
|
|
343
|
+
// return;
|
|
344
|
+
// }
|
|
345
|
+
|
|
346
|
+
// if (!linkModalOpen) {
|
|
347
|
+
// if (linkUrl !== "") {
|
|
348
|
+
// editor.dispatchCommand(TOGGLE_LINK_COMMAND, linkUrl);
|
|
349
|
+
// }
|
|
350
|
+
// } else {
|
|
351
|
+
// editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);
|
|
352
|
+
// }
|
|
353
|
+
// }, [editor, linkModalOpen]);
|
|
354
|
+
|
|
341
355
|
const insertLink = useCallback(() => {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
if (
|
|
345
|
-
|
|
356
|
+
editor.update(() => {
|
|
357
|
+
const selection = $getSelection();
|
|
358
|
+
if (!$isRangeSelection(selection) || selection.isCollapsed()) {
|
|
359
|
+
// Nothing selected → do nothing
|
|
360
|
+
return;
|
|
346
361
|
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
362
|
+
|
|
363
|
+
if (!linkModalOpen) {
|
|
364
|
+
if (linkUrl !== "") {
|
|
365
|
+
editor.dispatchCommand(TOGGLE_LINK_COMMAND, linkUrl);
|
|
366
|
+
}
|
|
367
|
+
} else {
|
|
368
|
+
editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
}, [editor, linkModalOpen, linkUrl]);
|
|
372
|
+
|
|
351
373
|
|
|
352
374
|
const removeLink = useCallback(() => {
|
|
353
375
|
setLinkUrl("")
|
|
@@ -359,27 +381,29 @@ export const ToolbarPlugin = ({ value }: { value: string }) => {
|
|
|
359
381
|
// <div className="flex gap-1.5 justify-start items-center p-1.5 pb-2 mb-1 border-b-[1px] overflow-x-auto overflow-y-hidden scrollbar-thin">
|
|
360
382
|
|
|
361
383
|
return (
|
|
362
|
-
<div
|
|
384
|
+
<div
|
|
385
|
+
className="lexical-toolbar-wrapper"
|
|
386
|
+
style={{
|
|
387
|
+
position: 'relative',
|
|
388
|
+
padding: 12, marginBottom: 4, borderBottom: '1px solid #e5e7eb'
|
|
389
|
+
}}
|
|
390
|
+
>
|
|
363
391
|
{
|
|
364
392
|
RICH_REDO_UNDO_OPTIONS.map(({ id, label, icon }) => (
|
|
365
393
|
id === RichTextAction.Divider ? <Separator key={id} /> :
|
|
366
|
-
<
|
|
367
|
-
<
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
</
|
|
375
|
-
|
|
376
|
-
{label}
|
|
377
|
-
</TooltipContent>
|
|
378
|
-
</Tooltip>
|
|
379
|
-
|
|
394
|
+
<TooltipX content={label} direction="bottom" key={label}>
|
|
395
|
+
<button
|
|
396
|
+
className={`size-8 lexical-btn ${selectionMap[id] ? "toolbarActive" : "toolbar"
|
|
397
|
+
} icon`}
|
|
398
|
+
onClick={() => onAction(id)}
|
|
399
|
+
disabled={!!disableMap[id]}
|
|
400
|
+
>
|
|
401
|
+
{icon}
|
|
402
|
+
</button>
|
|
403
|
+
</TooltipX>
|
|
380
404
|
))
|
|
381
405
|
}
|
|
382
|
-
<div
|
|
406
|
+
<div style={{ display: 'flex', gap: 6, justifyContent: 'start', alignItems: 'center' }}>
|
|
383
407
|
|
|
384
408
|
<HeadingSelectionList updateHeading={updateHeading} headingSelectionMap={headingSelectionMap} />
|
|
385
409
|
<Separator />
|
|
@@ -387,23 +411,20 @@ export const ToolbarPlugin = ({ value }: { value: string }) => {
|
|
|
387
411
|
{
|
|
388
412
|
RICH_TEXT_OPTIONS.map(({ id, label, icon }) => (
|
|
389
413
|
id === RichTextAction.Divider ? <Separator key={id} /> :
|
|
390
|
-
<
|
|
391
|
-
<
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
{label}
|
|
401
|
-
</TooltipContent>
|
|
402
|
-
</Tooltip>
|
|
414
|
+
<TooltipX key={id} content={label} direction="bottom">
|
|
415
|
+
<button
|
|
416
|
+
className={`size-8 lexical-btn ${selectionMap[id] ? "toolbarActive" : "toolbar"
|
|
417
|
+
} icon`}
|
|
418
|
+
onClick={() => onAction(id)}
|
|
419
|
+
>
|
|
420
|
+
{icon}
|
|
421
|
+
</button>
|
|
422
|
+
</TooltipX>
|
|
423
|
+
|
|
403
424
|
|
|
404
425
|
))
|
|
405
426
|
}
|
|
406
|
-
<div
|
|
427
|
+
<div style={{ display: 'flex', gap: 6, justifyContent: 'start', alignItems: 'center' }}>
|
|
407
428
|
|
|
408
429
|
<ListPlugin blockType={blockType} />
|
|
409
430
|
|
|
@@ -412,27 +433,6 @@ export const ToolbarPlugin = ({ value }: { value: string }) => {
|
|
|
412
433
|
|
|
413
434
|
<ColorPlugin />
|
|
414
435
|
|
|
415
|
-
{/* alignment in single row */}
|
|
416
|
-
|
|
417
|
-
{/* {
|
|
418
|
-
RICH_ALIGNMENT_OPTIONS.map(({ id, label, icon }) => (
|
|
419
|
-
id === RichTextAction.Divider ? <Separator key={id} /> :
|
|
420
|
-
<Tooltip key={id} delayDuration={700}>
|
|
421
|
-
<TooltipTrigger asChild>
|
|
422
|
-
<Button variant={selectionMap[id] ? "toolbarActive" : "toolbar"} size="icon" className="size-8"
|
|
423
|
-
onClick={() => onAction(id)}
|
|
424
|
-
disabled={!!disableMap[id]}
|
|
425
|
-
>
|
|
426
|
-
{icon}
|
|
427
|
-
</Button>
|
|
428
|
-
</TooltipTrigger>
|
|
429
|
-
<TooltipContent side="bottom">
|
|
430
|
-
{label}
|
|
431
|
-
</TooltipContent>
|
|
432
|
-
</Tooltip>
|
|
433
|
-
))
|
|
434
|
-
}
|
|
435
|
-
<Separator /> */}
|
|
436
436
|
|
|
437
437
|
{/* alignment in dropdown */}
|
|
438
438
|
|
|
@@ -440,25 +440,23 @@ export const ToolbarPlugin = ({ value }: { value: string }) => {
|
|
|
440
440
|
<DropdownList onAction={onAction} selectionMap={selectionMap} />
|
|
441
441
|
|
|
442
442
|
|
|
443
|
-
<div
|
|
443
|
+
<div style={{ display: 'flex', gap: 6, justifyContent: 'start', alignItems: 'center' }}>
|
|
444
444
|
<AlignmentSelectionList onAction={onAction} alignmentSelectionMap={selectionMap} />
|
|
445
445
|
<Separator />
|
|
446
446
|
</div>
|
|
447
447
|
|
|
448
448
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
</TooltipContent>
|
|
461
|
-
</Tooltip>
|
|
449
|
+
|
|
450
|
+
<TooltipX content="Link" direction="bottom">
|
|
451
|
+
<button
|
|
452
|
+
className={`size-8 lexical-btn ${selectionMap[RichTextAction.Link] ? "toolbarActive" : "toolbar"
|
|
453
|
+
} icon`}
|
|
454
|
+
onClick={() => onAction(RichTextAction.Link)}
|
|
455
|
+
disabled={!!disableMap[RichTextAction.Link]}
|
|
456
|
+
>
|
|
457
|
+
{<IoIosLink />}
|
|
458
|
+
</button>
|
|
459
|
+
</TooltipX>
|
|
462
460
|
|
|
463
461
|
|
|
464
462
|
{linkModalOpen &&
|