@innoviatech/lexical-text-editor 2.0.6 → 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 (111) hide show
  1. package/README.md +390 -241
  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.d.ts +1 -0
  13. package/dist/components/ImageComponent.js +111 -0
  14. package/dist/components/InsertDropdownList.js +17 -0
  15. package/dist/components/LexicalTextEditor.d.ts +11 -0
  16. package/dist/components/LexicalTextEditor.js +128 -0
  17. package/dist/components/LinkModal.js +47 -0
  18. package/dist/components/Separator.js +4 -0
  19. package/dist/components/SourceView.d.ts +13 -0
  20. package/dist/components/SourceView.js +50 -0
  21. package/dist/components/StatusBar.d.ts +14 -0
  22. package/dist/components/StatusBar.js +30 -0
  23. package/dist/components/ToolbarOverflowModal.d.ts +15 -0
  24. package/dist/components/common/Dialog.js +27 -0
  25. package/dist/components/common/Popover.d.ts +10 -1
  26. package/dist/components/common/Popover.js +37 -0
  27. package/dist/components/common/Tooltip.d.ts +7 -0
  28. package/dist/components/common/Tooltip.js +20 -0
  29. package/dist/components/ui/button.js +35 -0
  30. package/dist/components/ui/command.js +33 -0
  31. package/dist/components/ui/dialog.js +35 -0
  32. package/dist/components/ui/input.js +6 -0
  33. package/dist/components/ui/popover.js +16 -0
  34. package/dist/components/ui/scroll-area.js +12 -0
  35. package/dist/components/ui/tooltip.js +16 -0
  36. package/dist/constants/index.d.ts +23 -1
  37. package/dist/constants/index.js +224 -0
  38. package/dist/index.d.ts +11 -0
  39. package/dist/index.esm.js +1 -1
  40. package/dist/index.esm.js.map +1 -1
  41. package/dist/index.js +1 -1
  42. package/dist/index.js.map +1 -1
  43. package/dist/lexical-editor.css +1 -1
  44. package/dist/lib/utils.js +5 -0
  45. package/dist/nodes/ExtendedTextNode.js +140 -0
  46. package/dist/nodes/ImageNode.d.ts +5 -1
  47. package/dist/nodes/ImageNode.js +149 -0
  48. package/dist/nodes/VideoNode.js +80 -0
  49. package/dist/nodes/YoutubeNode.js +64 -0
  50. package/dist/plugins/CodeBlockPlugin.d.ts +1 -0
  51. package/dist/plugins/CodeBlockPlugin.js +88 -0
  52. package/dist/plugins/ColorPlugin.js +47 -0
  53. package/dist/plugins/CustomOnChangePlugin.js +33 -0
  54. package/dist/plugins/FontFamilyPlugin.d.ts +1 -0
  55. package/dist/plugins/FontFamilyPlugin.js +53 -0
  56. package/dist/plugins/FontSizePlugin.d.ts +1 -0
  57. package/dist/plugins/FontSizePlugin.js +48 -0
  58. package/dist/plugins/ImagePlugin.d.ts +3 -1
  59. package/dist/plugins/ImagePlugin.js +91 -0
  60. package/dist/plugins/ListPlugin.js +44 -0
  61. package/dist/plugins/TablePlugin.d.ts +1 -0
  62. package/dist/plugins/TablePlugin.js +92 -0
  63. package/dist/plugins/ToolbarPlugin.d.ts +14 -1
  64. package/dist/plugins/ToolbarPlugin.js +381 -0
  65. package/dist/plugins/VideoPlugin.js +49 -0
  66. package/dist/plugins/YoutubePlugin.js +30 -0
  67. package/dist/tsconfig.tsbuildinfo +1 -0
  68. package/editor_screenshot.png +0 -0
  69. package/package.json +11 -4
  70. package/googlebd703883f12c69e4.html +0 -1
  71. package/rollup.config.js +0 -55
  72. package/src/components/AlignmentSelectionList.tsx +0 -61
  73. package/src/components/ColorPicker.tsx +0 -66
  74. package/src/components/ContentPreview.tsx +0 -51
  75. package/src/components/DropdownList.tsx +0 -57
  76. package/src/components/HeadingSelectionList.tsx +0 -61
  77. package/src/components/ImageComponent.tsx +0 -140
  78. package/src/components/InsertDropdownList.tsx +0 -36
  79. package/src/components/LexicalTextEditor.tsx +0 -119
  80. package/src/components/LinkModal.tsx +0 -127
  81. package/src/components/Separator.tsx +0 -7
  82. package/src/components/common/Dialog.tsx +0 -47
  83. package/src/components/common/Popover.tsx +0 -87
  84. package/src/components/common/Tooltip.tsx +0 -43
  85. package/src/components/ui/button.tsx +0 -58
  86. package/src/components/ui/command.tsx +0 -183
  87. package/src/components/ui/dialog.tsx +0 -142
  88. package/src/components/ui/input.tsx +0 -21
  89. package/src/components/ui/popover.tsx +0 -46
  90. package/src/components/ui/scroll-area.tsx +0 -56
  91. package/src/components/ui/tooltip.tsx +0 -59
  92. package/src/constants/index.tsx +0 -177
  93. package/src/index.ts +0 -6
  94. package/src/lib/utils.ts +0 -6
  95. package/src/nodes/ExtendedTextNode.tsx +0 -185
  96. package/src/nodes/ImageNode.tsx +0 -195
  97. package/src/nodes/VideoNode.tsx +0 -134
  98. package/src/nodes/YoutubeNode.tsx +0 -101
  99. package/src/plugins/ColorPlugin.tsx +0 -85
  100. package/src/plugins/CustomOnChangePlugin.tsx +0 -50
  101. package/src/plugins/ImagePlugin.tsx +0 -118
  102. package/src/plugins/ListPlugin.tsx +0 -58
  103. package/src/plugins/ToolbarPlugin.tsx +0 -500
  104. package/src/plugins/VideoPlugin.tsx +0 -100
  105. package/src/plugins/YoutubePlugin.tsx +0 -83
  106. package/src/styles/lexical-editor.css +0 -1053
  107. package/src/types/global.d.ts +0 -34
  108. package/src/types/other.d.ts +0 -11
  109. package/src/types/react-icons.d.ts +0 -11
  110. package/tailwind.config.js +0 -10
  111. 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,140 +0,0 @@
1
- import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
2
- import { $getNodeByKey, type NodeKey } from "lexical";
3
- import { useRef } 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
- };
13
-
14
- export const ImageComponent: React.FC<ImageComponentProps> = ({
15
- src,
16
- altText,
17
- nodeKey,
18
- width,
19
- height,
20
- maxWidth,
21
- }) => {
22
- const [editor] = useLexicalComposerContext();
23
-
24
- const dragSizeRef = useRef<{ width: number; height: number, ratio: number } | null>(null);
25
-
26
- const wrapperRef = useRef<HTMLDivElement>(null);
27
- const startPos = useRef<{
28
- x: number;
29
- y: number;
30
- width: number;
31
- height: number;
32
- } | null>(null);
33
-
34
- const onMouseDown = (e: React.MouseEvent) => {
35
- e.preventDefault();
36
- e.stopPropagation();
37
-
38
- const img = wrapperRef.current?.querySelector("img");
39
- if (!img) return;
40
-
41
- const renderedWidth = img.getBoundingClientRect().width;
42
- const naturalRatio = img.naturalHeight / img.naturalWidth;
43
- const renderedHeight = renderedWidth * naturalRatio;
44
-
45
- startPos.current = {
46
- x: e.clientX,
47
- y: e.clientY,
48
- width: renderedWidth,
49
- height: renderedHeight,
50
- };
51
-
52
- dragSizeRef.current = {
53
- width: renderedWidth,
54
- height: renderedHeight,
55
- ratio: naturalRatio,
56
- };
57
-
58
- window.addEventListener("mousemove", onMouseMove);
59
- window.addEventListener("mouseup", onMouseUp);
60
- };
61
-
62
-
63
-
64
- const onMouseMove = (e: MouseEvent) => {
65
- if (!startPos.current || !dragSizeRef.current) return;
66
-
67
- const deltaX = e.clientX - startPos.current.x;
68
- const newWidth = Math.min(
69
- maxWidth,
70
- Math.max(50, startPos.current.width + deltaX)
71
- );
72
-
73
- const newHeight = newWidth * dragSizeRef.current.ratio;
74
-
75
- dragSizeRef.current.width = newWidth;
76
- dragSizeRef.current.height = newHeight;
77
-
78
- const img = wrapperRef.current?.querySelector("img");
79
- if (img) {
80
- img.style.width = newWidth + "px";
81
- img.style.height = newHeight + "px";
82
- }
83
- };
84
-
85
-
86
- const onMouseUp = () => {
87
- if (!dragSizeRef.current) return;
88
-
89
- const { width: finalWidth, height: finalHeight } = dragSizeRef.current;
90
-
91
- editor.update(() => {
92
- const node = $getNodeByKey(nodeKey);
93
- if (node && typeof (node as any).updateDimensions === "function") {
94
- (node as any).updateDimensions(finalWidth, finalHeight);
95
- }
96
- });
97
-
98
- dragSizeRef.current = null;
99
- startPos.current = null;
100
-
101
- window.removeEventListener("mousemove", onMouseMove);
102
- window.removeEventListener("mouseup", onMouseUp);
103
- };
104
-
105
- return (
106
- <div
107
- ref={wrapperRef}
108
- style={{
109
- display: "inline-block",
110
- position: "relative",
111
- maxWidth,
112
- }}
113
- >
114
- <img
115
- src={src}
116
- alt={altText}
117
- width={width === "inherit" ? undefined : width}
118
- height={height === "inherit" ? undefined : height}
119
- style={{
120
- maxWidth: "100%",
121
- display: "block",
122
- }}
123
- />
124
- <div
125
- onMouseDown={onMouseDown}
126
- style={{
127
- position: "absolute",
128
- bottom: 0,
129
- right: 0,
130
- width: 14,
131
- height: 14,
132
- background: "white",
133
- border: "1px solid #999",
134
- cursor: "nwse-resize",
135
- borderRadius: 2,
136
- }}
137
- />
138
- </div>
139
- );
140
- };
@@ -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 { LineBreakNode, 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
- }
30
-
31
- const theme: EditorThemeClasses = {
32
- text: {
33
- bold: "lexical-bold",
34
- underline: "lexical-underline",
35
- italic: "lexical-italic",
36
- strikethrough: "lexical-strikethrough",
37
- underlineStrikethrough: "lexical-underline-strikethrough",
38
- uppercase: "lexical-uppercase",
39
- lowercase: "lexical-lowercase",
40
- capitalize: "lexical-capitalize",
41
- code: "lexical-code",
42
- },
43
- paragraph: "lexical-paragraph",
44
- list: {
45
- ul: "lexical-list-ul",
46
- ol: "lexical-list-ol",
47
- listitem: "lexical-listitem",
48
- },
49
- quote: "lexical-quote",
50
- link: "lexical-link",
51
- }
52
-
53
- export const LexicalTextEditor: React.FC<LexiTexProps> = React.memo(
54
- function LexicalTextEditor({ name, value, onChange, placeholder, maxWidth = null, height = null }) {
55
-
56
- const initialConfig = useMemo(
57
- () => ({
58
- namespace: name,
59
- theme: theme,
60
- onError: (error: Error) => {
61
- console.error("Lexical error:", error);
62
- },
63
- nodes: [
64
- ExtendedTextNode,
65
- {
66
- replace: TextNode,
67
- with: (node: TextNode) => new ExtendedTextNode(node.__text),
68
- withKlass: ExtendedTextNode,
69
- },
70
- HeadingNode,
71
- CodeHighlightNode,
72
- CodeNode,
73
- ListNode,
74
- ListItemNode,
75
- QuoteNode,
76
- LinkNode,
77
- ImageNode,
78
- YoutubeNode,
79
- VideoNode,
80
- LineBreakNode
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} />
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
- )
@@ -1,127 +0,0 @@
1
- import { useEffect, useRef, useState } from "react";
2
- import { BsPencilSquare } from "react-icons/bs";
3
- import { MdCheck } from "react-icons/md";
4
- import { BiUnlink } from "react-icons/bi";
5
-
6
- interface LinkEditorProps {
7
- linkUrl: string;
8
- setLinkUrl: React.Dispatch<React.SetStateAction<string>>;
9
- onConfirm: (url: string) => void;
10
- onCancel: () => void;
11
- removeLink: () => void;
12
- }
13
-
14
- export default function LinkModal({
15
- linkUrl,
16
- setLinkUrl,
17
- onConfirm,
18
- onCancel,
19
- removeLink,
20
- }: LinkEditorProps) {
21
- const [isEditMode, setEditMode] = useState(false);
22
- const editorRef = useRef<HTMLDivElement | null>(null);
23
- const inputRef = useRef<HTMLInputElement | null>(null);
24
-
25
- useEffect(() => {
26
- if (linkUrl === "https://") setEditMode(true);
27
- }, [linkUrl]);
28
-
29
- useEffect(() => {
30
- if (isEditMode) inputRef.current?.focus();
31
- }, [isEditMode]);
32
-
33
- useEffect(() => {
34
- const handleClickOutside = (event: MouseEvent) => {
35
- if (
36
- editorRef.current &&
37
- !editorRef.current.contains(event.target as Node)
38
- ) {
39
- onCancel();
40
- }
41
- };
42
-
43
- document.addEventListener("mousedown", handleClickOutside);
44
- return () => document.removeEventListener("mousedown", handleClickOutside);
45
- }, [onCancel]);
46
-
47
- return (
48
- <div ref={editorRef} className="lexical-text-editor-link link-editor-container">
49
- <div className="link-editor-input-wrapper">
50
- {isEditMode ? (
51
- <input
52
- ref={inputRef}
53
- className="link-editor-input"
54
- value={linkUrl}
55
- onChange={(e) => setLinkUrl(e.target.value)}
56
- onKeyDown={(e) => {
57
- if (e.key === "Enter") {
58
- e.preventDefault();
59
- onConfirm(linkUrl);
60
- setEditMode(false);
61
- } else if (e.key === "Escape") {
62
- e.preventDefault();
63
- setEditMode(false);
64
- onCancel();
65
- }
66
- }}
67
- />
68
- ) : (
69
- <a
70
- href={linkUrl}
71
- target="_blank"
72
- rel="noopener noreferrer"
73
- className="link-editor-url"
74
- >
75
- {linkUrl}
76
- </a>
77
- )}
78
- </div>
79
-
80
- <div className="link-editor-buttons">
81
-
82
- <button type="button"
83
- className={`lexical-btn heading-trigger toolbar`}
84
- onClick={() => {
85
- if (isEditMode) {
86
- onConfirm(linkUrl);
87
- setEditMode(false);
88
- } else setEditMode(true);
89
- }}
90
- >
91
- {isEditMode ? <MdCheck size={18} /> : <BsPencilSquare size={14} />}
92
- </button>
93
-
94
- <button type="button"
95
- className={`lexical-btn heading-trigger toolbar`}
96
- onMouseDown={(e) => e.preventDefault()}
97
- onClick={removeLink}
98
- >
99
- <BiUnlink size={14} style={{ stroke: 'black' }} />
100
- </button>
101
-
102
-
103
-
104
- {/* <button type="button"
105
- onMouseDown={(e) => e.preventDefault()}
106
- onClick={() => {
107
- if (isEditMode) {
108
- onConfirm(linkUrl);
109
- setEditMode(false);
110
- } else setEditMode(true);
111
- }}
112
- className={`size-8 toolbar icon`}
113
- >
114
- {isEditMode ? <MdCheck size={18} /> : <BsPencilSquare size={14} />}
115
- </button> */}
116
-
117
- {/* <button type="button"
118
- onMouseDown={(e) => e.preventDefault()}
119
- onClick={removeLink}
120
- className={`size-8 toolbar icon`}
121
- >
122
- <BiUnlink size={14} style={{ stroke: 'black' }} />
123
- </button> */}
124
- </div>
125
- </div>
126
- );
127
- }
@@ -1,7 +0,0 @@
1
-
2
-
3
- export default function Separator() {
4
- return (
5
- <div className="w-[1px] h-[20px] mx-[2px] bg-gray-300 shrink-0" />
6
- )
7
- }