@innoviatech/lexical-text-editor 2.0.7 → 3.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.
Files changed (108) hide show
  1. package/README.md +390 -288
  2. package/dist/components/AlignmentSelectionList.js +19 -0
  3. package/dist/components/ColorPicker.js +30 -0
  4. package/dist/components/ContentPreview.js +11 -0
  5. package/dist/components/DisplayControls.d.ts +16 -0
  6. package/dist/components/DropdownList.js +18 -0
  7. package/dist/components/FindReplaceModal.d.ts +11 -0
  8. package/dist/components/FindReplaceModal.js +120 -0
  9. package/dist/components/FontSelectionList.d.ts +17 -0
  10. package/dist/components/FontSelectionList.js +17 -0
  11. package/dist/components/HeadingSelectionList.js +19 -0
  12. package/dist/components/ImageComponent.js +111 -0
  13. package/dist/components/InsertDropdownList.js +17 -0
  14. package/dist/components/LexicalTextEditor.d.ts +10 -0
  15. package/dist/components/LexicalTextEditor.js +128 -0
  16. package/dist/components/LinkModal.js +47 -0
  17. package/dist/components/Separator.js +4 -0
  18. package/dist/components/SourceView.d.ts +13 -0
  19. package/dist/components/SourceView.js +50 -0
  20. package/dist/components/StatusBar.d.ts +14 -0
  21. package/dist/components/StatusBar.js +30 -0
  22. package/dist/components/ToolbarOverflowModal.d.ts +15 -0
  23. package/dist/components/common/Dialog.js +27 -0
  24. package/dist/components/common/Popover.d.ts +10 -1
  25. package/dist/components/common/Popover.js +37 -0
  26. package/dist/components/common/Tooltip.d.ts +7 -0
  27. package/dist/components/common/Tooltip.js +20 -0
  28. package/dist/components/ui/button.js +35 -0
  29. package/dist/components/ui/command.js +33 -0
  30. package/dist/components/ui/dialog.js +35 -0
  31. package/dist/components/ui/input.js +6 -0
  32. package/dist/components/ui/popover.js +16 -0
  33. package/dist/components/ui/scroll-area.js +12 -0
  34. package/dist/components/ui/tooltip.js +16 -0
  35. package/dist/constants/index.d.ts +23 -1
  36. package/dist/constants/index.js +224 -0
  37. package/dist/index.d.ts +10 -0
  38. package/dist/index.esm.js +1 -1
  39. package/dist/index.esm.js.map +1 -1
  40. package/dist/index.js +1 -1
  41. package/dist/index.js.map +1 -1
  42. package/dist/lexical-editor.css +1 -1
  43. package/dist/lib/utils.js +5 -0
  44. package/dist/nodes/ExtendedTextNode.js +140 -0
  45. package/dist/nodes/ImageNode.js +149 -0
  46. package/dist/nodes/VideoNode.js +80 -0
  47. package/dist/nodes/YoutubeNode.js +64 -0
  48. package/dist/plugins/CodeBlockPlugin.d.ts +1 -0
  49. package/dist/plugins/CodeBlockPlugin.js +88 -0
  50. package/dist/plugins/ColorPlugin.js +47 -0
  51. package/dist/plugins/CustomOnChangePlugin.js +33 -0
  52. package/dist/plugins/FontFamilyPlugin.d.ts +1 -0
  53. package/dist/plugins/FontFamilyPlugin.js +53 -0
  54. package/dist/plugins/FontSizePlugin.d.ts +1 -0
  55. package/dist/plugins/FontSizePlugin.js +48 -0
  56. package/dist/plugins/ImagePlugin.js +91 -0
  57. package/dist/plugins/ListPlugin.js +44 -0
  58. package/dist/plugins/TablePlugin.d.ts +1 -0
  59. package/dist/plugins/TablePlugin.js +92 -0
  60. package/dist/plugins/ToolbarPlugin.d.ts +13 -1
  61. package/dist/plugins/ToolbarPlugin.js +381 -0
  62. package/dist/plugins/VideoPlugin.js +49 -0
  63. package/dist/plugins/YoutubePlugin.js +30 -0
  64. package/dist/tsconfig.tsbuildinfo +1 -0
  65. package/editor_screenshot.png +0 -0
  66. package/package.json +11 -4
  67. package/googlebd703883f12c69e4.html +0 -1
  68. package/rollup.config.js +0 -55
  69. package/src/components/AlignmentSelectionList.tsx +0 -61
  70. package/src/components/ColorPicker.tsx +0 -66
  71. package/src/components/ContentPreview.tsx +0 -51
  72. package/src/components/DropdownList.tsx +0 -57
  73. package/src/components/HeadingSelectionList.tsx +0 -61
  74. package/src/components/ImageComponent.tsx +0 -206
  75. package/src/components/InsertDropdownList.tsx +0 -36
  76. package/src/components/LexicalTextEditor.tsx +0 -119
  77. package/src/components/LinkModal.tsx +0 -127
  78. package/src/components/Separator.tsx +0 -7
  79. package/src/components/common/Dialog.tsx +0 -47
  80. package/src/components/common/Popover.tsx +0 -87
  81. package/src/components/common/Tooltip.tsx +0 -43
  82. package/src/components/ui/button.tsx +0 -58
  83. package/src/components/ui/command.tsx +0 -183
  84. package/src/components/ui/dialog.tsx +0 -142
  85. package/src/components/ui/input.tsx +0 -21
  86. package/src/components/ui/popover.tsx +0 -46
  87. package/src/components/ui/scroll-area.tsx +0 -56
  88. package/src/components/ui/tooltip.tsx +0 -59
  89. package/src/constants/index.tsx +0 -177
  90. package/src/index.ts +0 -6
  91. package/src/lib/utils.ts +0 -6
  92. package/src/nodes/ExtendedTextNode.tsx +0 -174
  93. package/src/nodes/ImageNode.tsx +0 -232
  94. package/src/nodes/VideoNode.tsx +0 -134
  95. package/src/nodes/YoutubeNode.tsx +0 -101
  96. package/src/plugins/ColorPlugin.tsx +0 -85
  97. package/src/plugins/CustomOnChangePlugin.tsx +0 -50
  98. package/src/plugins/ImagePlugin.tsx +0 -189
  99. package/src/plugins/ListPlugin.tsx +0 -58
  100. package/src/plugins/ToolbarPlugin.tsx +0 -500
  101. package/src/plugins/VideoPlugin.tsx +0 -100
  102. package/src/plugins/YoutubePlugin.tsx +0 -83
  103. package/src/styles/lexical-editor.css +0 -1053
  104. package/src/types/global.d.ts +0 -34
  105. package/src/types/other.d.ts +0 -11
  106. package/src/types/react-icons.d.ts +0 -11
  107. package/tailwind.config.js +0 -10
  108. package/tsconfig.json +0 -32
@@ -1,66 +0,0 @@
1
- import { useState, useRef, useEffect } from "react";
2
- import { SketchPicker } from "react-color";
3
- import { createPortal } from "react-dom";
4
-
5
- interface ColorPickerProps {
6
- color: string;
7
- onChange: (color: string) => void;
8
- icon: React.ReactElement;
9
- }
10
-
11
- export default function ColorPicker({ color, onChange, icon }: ColorPickerProps) {
12
- const [open, setOpen] = useState(false);
13
- const triggerRef = useRef<HTMLButtonElement>(null);
14
- const popoverRef = useRef<HTMLDivElement>(null);
15
-
16
- useEffect(() => {
17
- const handleClickOutside = (event: MouseEvent) => {
18
- if (
19
- popoverRef.current &&
20
- !popoverRef.current.contains(event.target as Node) &&
21
- triggerRef.current &&
22
- !triggerRef.current.contains(event.target as Node)
23
- ) {
24
- setOpen(false);
25
- }
26
- };
27
- document.addEventListener("mousedown", handleClickOutside);
28
- return () => document.removeEventListener("mousedown", handleClickOutside);
29
- }, []);
30
-
31
- const preventFocus = (e: React.MouseEvent) => e.preventDefault();
32
-
33
- return (
34
- <div className="color-picker-wrapper">
35
- <button type="button"
36
- ref={triggerRef}
37
- className={`size-8 lexical-btn ${open ? "toolbarActive" : "toolbar"} icon`}
38
- onClick={() => setOpen((prev) => !prev)}
39
- >
40
- {icon}
41
- </button>
42
-
43
- {open &&
44
- createPortal(
45
- <div
46
- ref={popoverRef}
47
- className={`lexical-color-popover ${open ? "open" : ""}`}
48
- style={{
49
- top: triggerRef.current?.getBoundingClientRect().bottom,
50
- left: triggerRef.current?.getBoundingClientRect().left,
51
- position: "absolute",
52
- }}
53
- onMouseDown={preventFocus}
54
- >
55
- <SketchPicker
56
- color={color}
57
- onChangeComplete={(c: any) => {
58
- onChange(c.hex);
59
- }}
60
- />
61
- </div>,
62
- document.body
63
- )}
64
- </div>
65
- );
66
- }
@@ -1,51 +0,0 @@
1
- import { useState } from "react";
2
- import { VscPreview } from "react-icons/vsc";
3
- import RawDialog from "./common/Dialog";
4
-
5
- type HtmlPreviewProps = {
6
- value: string;
7
- };
8
-
9
- export function HtmlPreview({ value }: HtmlPreviewProps) {
10
- return (
11
- <div
12
- className="lexical-text-editor-html-preview"
13
- dangerouslySetInnerHTML={{ __html: value }}
14
- />
15
- );
16
- }
17
-
18
- type ContentPreviewDialogProps = {
19
- value: string;
20
- triggerLabel?: string;
21
- };
22
-
23
- export default function ContentPreviewDialog({
24
- value,
25
- triggerLabel = "Preview",
26
- }: ContentPreviewDialogProps) {
27
- const [isOpen, setIsOpen] = useState(false);
28
- return (
29
- <div className="lexical-text-editor-dialog">
30
- {/* Trigger button */}
31
-
32
- <button type="button"
33
- className={`lexical-btn heading-trigger ${isOpen ? "toolbar-active" : "toolbar"}`}
34
- onClick={() => setIsOpen((prev) => !prev)}
35
- >
36
- <VscPreview size={18} />
37
- <span>{triggerLabel}</span>
38
- </button>
39
-
40
- {/* Dialog */}
41
- <RawDialog open={isOpen} onClose={() => setIsOpen(false)} forPreview>
42
- <div className="lte-dialog-header">Content Preview</div>
43
-
44
- <div className="lte-preview-container">
45
- <div className="lte-preview-title">CONTENT</div>
46
- <HtmlPreview value={value} />
47
- </div>
48
- </RawDialog>
49
- </div>
50
- );
51
- }
@@ -1,57 +0,0 @@
1
- import { RICH_TEXT_FORMAT_OPTIONS, RichTextAction } from "../constants/index";
2
- import { useRef, useState } from "react"
3
- import { HiChevronDown } from "react-icons/hi2";
4
- import { Popover, PopoverContent, PopoverTrigger } from "./common/Popover";
5
-
6
- interface Props {
7
- onAction: (id: RichTextAction) => void,
8
- selectionMap: {
9
- [id: string]: boolean;
10
- }
11
- }
12
- export function DropdownList({ onAction, selectionMap }: Props) {
13
- const [isOpen, setIsOpen] = useState(false)
14
- const triggerRef = useRef<HTMLDivElement | null>(null);
15
- const contentRef = useRef<HTMLDivElement | null>(null);
16
- return (
17
- <Popover open={isOpen} onOpenChange={setIsOpen}>
18
- <PopoverTrigger triggerRef={triggerRef}>
19
- <button type="button"
20
- className={`lexical-btn heading-trigger ${isOpen ? "toolbar-active" : "toolbar"}`}
21
- onClick={() => setIsOpen((prev) => !prev)}
22
- >
23
- <span>Aa</span>
24
- <HiChevronDown className={`chevron ${isOpen ? "rotated" : ""}`} />
25
- </button>
26
- </PopoverTrigger>
27
- <PopoverContent open={isOpen} align="start" onClose={() => setIsOpen(false)} contentRef={contentRef}>
28
- <div
29
- style={{
30
- display: 'flex', flexDirection: 'column', gap: 5
31
- }}
32
- >
33
- {
34
- RICH_TEXT_FORMAT_OPTIONS.map(({ id, label, icon }) => (
35
- <button type="button"
36
- key={id}
37
- className={`lexical-btn ${selectionMap[id] ? "toolbar-active" : "toolbar"
38
- }`}
39
- onClick={() => {
40
- onAction(id);
41
- setIsOpen(false)
42
- }}
43
- style={{
44
- minWidth: 130
45
- }}
46
- >
47
- {icon}
48
- <span className="label">{label}</span>
49
- </button>
50
- ))
51
- }
52
-
53
- </div>
54
- </PopoverContent>
55
- </Popover>
56
- )
57
- }
@@ -1,61 +0,0 @@
1
- import { HEADINGS } from "../constants/index";
2
- import { type HeadingTagType } from "@lexical/rich-text";
3
- import { useRef, useState } from "react";
4
- import { HiChevronDown } from "react-icons/hi2";
5
- import { Popover, PopoverContent, PopoverTrigger } from "./common/Popover";
6
-
7
-
8
- interface Props {
9
- updateHeading: (heading: HeadingTagType | "normal") => void;
10
- headingSelectionMap: { [id: string]: boolean };
11
- }
12
-
13
-
14
-
15
- export function HeadingSelectionList({ updateHeading, headingSelectionMap }: Props) {
16
- const activeHeading = HEADINGS.find((h) => headingSelectionMap[h.id]);
17
- const [open, setOpen] = useState(false);
18
- const triggerRef = useRef<HTMLDivElement | null>(null);
19
- const contentRef = useRef<HTMLDivElement | null>(null);
20
-
21
- return (
22
- <Popover open={open} onOpenChange={setOpen}>
23
- <PopoverTrigger triggerRef={triggerRef}>
24
- <button type="button"
25
- className={`lexical-btn heading-trigger ${open ? "toolbar-active" : "toolbar"}`}
26
- onClick={() => setOpen((prev) => !prev)}
27
- style={{
28
- minWidth: 132
29
- }}
30
- >
31
- {activeHeading?.icon}
32
- <span>{activeHeading?.label}</span>
33
- <HiChevronDown className={`chevron ${open ? "rotated" : ""}`} />
34
- </button>
35
- </PopoverTrigger>
36
-
37
- <PopoverContent open={open} align="start" onClose={() => setOpen(false)} contentRef={contentRef}>
38
- <div
39
- style={{
40
- display: 'flex', flexDirection: 'column', gap: 5
41
- }}>
42
- {HEADINGS.map(({ id, label, icon }) => (
43
- <button type="button"
44
- key={id}
45
- className={`lexical-btn ${headingSelectionMap[id] ? "toolbar-active" : "toolbar"
46
- }`}
47
- onClick={() => {
48
- updateHeading(id as HeadingTagType | "normal");
49
- setOpen(false);
50
- }}
51
- >
52
- {icon}
53
- <span className="label">{label}</span>
54
- </button>
55
- ))}
56
- </div>
57
- </PopoverContent>
58
- </Popover>
59
-
60
- );
61
- }
@@ -1,206 +0,0 @@
1
- import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
2
- import { $getNodeByKey, type NodeKey } from "lexical";
3
- import { useRef, useState } from "react";
4
-
5
- type ImageComponentProps = {
6
- src: string;
7
- altText: string;
8
- nodeKey: NodeKey;
9
- width?: number | "inherit";
10
- height?: number | "inherit";
11
- maxWidth: number;
12
- caption?: string;
13
- };
14
-
15
- export const ImageComponent: React.FC<ImageComponentProps> = ({
16
- src,
17
- altText,
18
- nodeKey,
19
- width,
20
- height,
21
- maxWidth,
22
- caption = "",
23
- }) => {
24
- const [editor] = useLexicalComposerContext();
25
- const [editingCaption, setEditingCaption] = useState(false);
26
- const [captionText, setCaptionText] = useState(caption);
27
- const captionInputRef = useRef<HTMLInputElement>(null);
28
-
29
- const dragSizeRef = useRef<{ width: number; height: number, ratio: number } | null>(null);
30
-
31
- const wrapperRef = useRef<HTMLDivElement>(null);
32
- const startPos = useRef<{
33
- x: number;
34
- y: number;
35
- width: number;
36
- height: number;
37
- } | null>(null);
38
-
39
- const onMouseDown = (e: React.MouseEvent) => {
40
- e.preventDefault();
41
- e.stopPropagation();
42
-
43
- const img = wrapperRef.current?.querySelector("img");
44
- if (!img) return;
45
-
46
- const renderedWidth = img.getBoundingClientRect().width;
47
- const naturalRatio = img.naturalHeight / img.naturalWidth;
48
- const renderedHeight = renderedWidth * naturalRatio;
49
-
50
- startPos.current = {
51
- x: e.clientX,
52
- y: e.clientY,
53
- width: renderedWidth,
54
- height: renderedHeight,
55
- };
56
-
57
- dragSizeRef.current = {
58
- width: renderedWidth,
59
- height: renderedHeight,
60
- ratio: naturalRatio,
61
- };
62
-
63
- window.addEventListener("mousemove", onMouseMove);
64
- window.addEventListener("mouseup", onMouseUp);
65
- };
66
-
67
-
68
-
69
- const onMouseMove = (e: MouseEvent) => {
70
- if (!startPos.current || !dragSizeRef.current) return;
71
-
72
- const deltaX = e.clientX - startPos.current.x;
73
- const newWidth = Math.min(
74
- maxWidth,
75
- Math.max(50, startPos.current.width + deltaX)
76
- );
77
-
78
- const newHeight = newWidth * dragSizeRef.current.ratio;
79
-
80
- dragSizeRef.current.width = newWidth;
81
- dragSizeRef.current.height = newHeight;
82
-
83
- const img = wrapperRef.current?.querySelector("img");
84
- if (img) {
85
- img.style.width = newWidth + "px";
86
- img.style.height = newHeight + "px";
87
- }
88
- };
89
-
90
-
91
- const onMouseUp = () => {
92
- if (!dragSizeRef.current) return;
93
-
94
- const { width: finalWidth, height: finalHeight } = dragSizeRef.current;
95
-
96
- editor.update(() => {
97
- const node = $getNodeByKey(nodeKey);
98
- if (node && typeof (node as any).updateDimensions === "function") {
99
- (node as any).updateDimensions(finalWidth, finalHeight);
100
- }
101
- });
102
-
103
- dragSizeRef.current = null;
104
- startPos.current = null;
105
-
106
- window.removeEventListener("mousemove", onMouseMove);
107
- window.removeEventListener("mouseup", onMouseUp);
108
- };
109
-
110
- const saveCaption = () => {
111
- setEditingCaption(false);
112
- editor.update(() => {
113
- const node = $getNodeByKey(nodeKey);
114
- if (node && typeof (node as any).setCaption === "function") {
115
- (node as any).setCaption(captionText);
116
- }
117
- });
118
- };
119
-
120
- const startCaptionEdit = () => {
121
- setCaptionText(caption);
122
- setEditingCaption(true);
123
- setTimeout(() => captionInputRef.current?.focus(), 0);
124
- };
125
-
126
- return (
127
- <div
128
- ref={wrapperRef}
129
- style={{
130
- display: "inline-block",
131
- position: "relative",
132
- maxWidth,
133
- }}
134
- >
135
- <img
136
- src={src}
137
- alt={altText}
138
- width={width === "inherit" ? undefined : width}
139
- height={height === "inherit" ? undefined : height}
140
- style={{
141
- maxWidth: "100%",
142
- display: "block",
143
- }}
144
- />
145
- {(caption || editingCaption) && (
146
- <div style={{ textAlign: "center", marginTop: 4 }}>
147
- {editingCaption ? (
148
- <input
149
- ref={captionInputRef}
150
- className="lte-input"
151
- style={{ width: "100%", textAlign: "center" }}
152
- value={captionText}
153
- onChange={(e) => setCaptionText(e.target.value)}
154
- onBlur={saveCaption}
155
- onKeyDown={(e) => {
156
- if (e.key === "Enter") saveCaption();
157
- }}
158
- />
159
- ) : (
160
- <span
161
- style={{
162
- fontSize: 13,
163
- color: "#666",
164
- cursor: "text",
165
- display: "inline-block",
166
- minWidth: 20,
167
- minHeight: 18,
168
- }}
169
- onClick={startCaptionEdit}
170
- >
171
- {caption}
172
- </span>
173
- )}
174
- </div>
175
- )}
176
- {!caption && !editingCaption && (
177
- <div style={{ textAlign: "center", marginTop: 2 }}>
178
- <span
179
- style={{
180
- fontSize: 12,
181
- color: "#999",
182
- cursor: "pointer",
183
- }}
184
- onClick={startCaptionEdit}
185
- >
186
- + Add caption
187
- </span>
188
- </div>
189
- )}
190
- <div
191
- onMouseDown={onMouseDown}
192
- style={{
193
- position: "absolute",
194
- bottom: caption || editingCaption ? 40 : 0,
195
- right: 0,
196
- width: 14,
197
- height: 14,
198
- background: "white",
199
- border: "1px solid #999",
200
- cursor: "nwse-resize",
201
- borderRadius: 2,
202
- }}
203
- />
204
- </div>
205
- );
206
- };
@@ -1,36 +0,0 @@
1
- import { Button } from "./ui/button"
2
- import {
3
- Popover,
4
- PopoverContent,
5
- PopoverTrigger,
6
- } from "./ui/popover"
7
- // import { RichTextAction } from "constants";
8
- import { useState } from "react"
9
- import { BsPlus } from "react-icons/bs";
10
- import { HiChevronDown } from "react-icons/hi2";
11
-
12
- // interface Props {
13
- // onAction: (id: RichTextAction) => void,
14
- // selectionMap: {
15
- // [id: string]: boolean;
16
- // }
17
- // }
18
- export function InsertDropdownList({ }) {
19
- const [isOpen, setIsOpen] = useState(false)
20
- return (
21
- <Popover open={isOpen} onOpenChange={(s) => setIsOpen(s)}>
22
- <PopoverTrigger asChild>
23
- <Button variant={isOpen ? "toolbarActive" : "toolbar"}
24
- onClick={() => setIsOpen(!isOpen)} size="icon" className="size-8 w-fit p-2 select-none border-[1px] border-gray-100"
25
- >
26
- <BsPlus /> <span>Insert</span> <HiChevronDown className={` transition-normal duration-100 ${isOpen ? "rotate-180" : "rotate-0"}`} />
27
- </Button>
28
- </PopoverTrigger>
29
- <PopoverContent className="p-2 w-fit flex flex-col items-start gap-1">
30
-
31
-
32
-
33
- </PopoverContent>
34
- </Popover>
35
- )
36
- }
@@ -1,119 +0,0 @@
1
- import { LexicalComposer } from "@lexical/react/LexicalComposer"
2
- import React, { useMemo } from "react"
3
- import { HeadingNode, QuoteNode } from "@lexical/rich-text"
4
- import { CodeHighlightNode, CodeNode } from "@lexical/code"
5
- import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin"
6
- import { ContentEditable } from "@lexical/react/LexicalContentEditable"
7
- import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary"
8
- import { TextNode, type EditorThemeClasses } from "lexical"
9
- import { HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin"
10
- import { ListPlugin } from "@lexical/react/LexicalListPlugin"
11
- import { ListItemNode, ListNode } from "@lexical/list"
12
- import { ToolbarPlugin } from "../plugins/ToolbarPlugin"
13
- import { LinkNode } from "@lexical/link"
14
- import { LinkPlugin } from "@lexical/react/LexicalLinkPlugin"
15
- import CustomOnChangePlugin from "../plugins/CustomOnChangePlugin"
16
- import { ImageNode } from "../nodes/ImageNode"
17
- import { YoutubeNode } from "../nodes/YoutubeNode"
18
- import { VideoNode } from "../nodes/VideoNode"
19
- import "../styles/lexical-editor.css"
20
- import { ExtendedTextNode } from "../nodes/ExtendedTextNode"
21
-
22
- export interface LexiTexProps {
23
- value: string
24
- onChange: (value: string) => void
25
- placeholder?: string
26
- name: string,
27
- height?: string | null | undefined;
28
- maxWidth?: string | null | undefined;
29
- onImageUpload?: (file: File) => Promise<string>;
30
- }
31
-
32
- const theme: EditorThemeClasses = {
33
- text: {
34
- bold: "lexical-bold",
35
- underline: "lexical-underline",
36
- italic: "lexical-italic",
37
- strikethrough: "lexical-strikethrough",
38
- underlineStrikethrough: "lexical-underline-strikethrough",
39
- uppercase: "lexical-uppercase",
40
- lowercase: "lexical-lowercase",
41
- capitalize: "lexical-capitalize",
42
- code: "lexical-code",
43
- },
44
- paragraph: "lexical-paragraph",
45
- list: {
46
- ul: "lexical-list-ul",
47
- ol: "lexical-list-ol",
48
- listitem: "lexical-listitem",
49
- },
50
- quote: "lexical-quote",
51
- link: "lexical-link",
52
- }
53
-
54
- export const LexicalTextEditor: React.FC<LexiTexProps> = React.memo(
55
- function LexicalTextEditor({ name, value, onChange, placeholder, maxWidth = null, height = null, onImageUpload }) {
56
-
57
- const initialConfig = useMemo(
58
- () => ({
59
- namespace: name,
60
- theme: theme,
61
- onError: (error: Error) => {
62
- console.error("Lexical error:", error);
63
- },
64
- nodes: [
65
- ExtendedTextNode,
66
- {
67
- replace: TextNode,
68
- with: (node: TextNode) => new ExtendedTextNode(node.__text),
69
- withKlass: ExtendedTextNode,
70
- },
71
- HeadingNode,
72
- CodeHighlightNode,
73
- CodeNode,
74
- ListNode,
75
- ListItemNode,
76
- QuoteNode,
77
- LinkNode,
78
- ImageNode,
79
- YoutubeNode,
80
- VideoNode
81
- ],
82
- }) as any,
83
- [name]
84
- );
85
-
86
- return (
87
- <div className="lexical-text-editor lexical-editor-container"
88
- style={{
89
- maxWidth: maxWidth ? maxWidth : '1090px',
90
- }}
91
- >
92
- <LexicalComposer initialConfig={initialConfig}>
93
- <div className="lexical-toolbar-container">
94
- <ToolbarPlugin value={value} onImageUpload={onImageUpload} />
95
- </div>
96
- <div className="lexical-editor-inner">
97
- <RichTextPlugin
98
- contentEditable={
99
- <ContentEditable className="lexical-content-editable" style={{
100
- height: height ? height : '500px',
101
- }} />
102
- }
103
- placeholder={
104
- <div className="lexical-placeholder">
105
- {placeholder || "Some Text"}
106
- </div>
107
- }
108
- ErrorBoundary={LexicalErrorBoundary}
109
- />
110
- </div>
111
- <HistoryPlugin />
112
- <ListPlugin />
113
- <LinkPlugin />
114
- <CustomOnChangePlugin value={value} onChange={onChange} />
115
- </LexicalComposer>
116
- </div>
117
- )
118
- }
119
- )