@innoviatech/lexical-text-editor 1.0.6 → 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.
Files changed (44) hide show
  1. package/README.md +105 -35
  2. package/dist/components/ContentPreview.d.ts +1 -1
  3. package/dist/components/HeadingSelectionList.d.ts +1 -1
  4. package/dist/components/LexicalTextEditor.d.ts +1 -1
  5. package/dist/components/common/Dialog.d.ts +9 -0
  6. package/dist/components/common/Popover.d.ts +21 -0
  7. package/dist/components/common/Tooltip.d.ts +10 -0
  8. package/dist/components/ui/button.d.ts +1 -1
  9. package/dist/index.d.ts +1 -1
  10. package/dist/index.esm.js +1 -1
  11. package/dist/index.esm.js.map +1 -1
  12. package/dist/index.js +1 -1
  13. package/dist/index.js.map +1 -1
  14. package/dist/lexical-editor.css +1 -0
  15. package/dist/nodes/ExtendedTextNode.d.ts +11 -0
  16. package/dist/nodes/ImageNode.d.ts +1 -1
  17. package/dist/plugins/YoutubePlugin.d.ts +1 -0
  18. package/package.json +20 -16
  19. package/rollup.config.js +3 -4
  20. package/src/components/AlignmentSelectionList.tsx +41 -24
  21. package/src/components/ColorPicker.tsx +7 -21
  22. package/src/components/ContentPreview.tsx +27 -20
  23. package/src/components/DropdownList.tsx +39 -24
  24. package/src/components/HeadingSelectionList.tsx +48 -32
  25. package/src/components/ImageComponent.tsx +52 -19
  26. package/src/components/InsertDropdownList.tsx +1 -1
  27. package/src/components/LexicalTextEditor.tsx +33 -28
  28. package/src/components/LinkModal.tsx +42 -45
  29. package/src/components/common/Dialog.tsx +47 -0
  30. package/src/components/common/Popover.tsx +87 -0
  31. package/src/components/common/Tooltip.tsx +43 -0
  32. package/src/components/ui/command.tsx +0 -1
  33. package/src/nodes/ExtendedTextNode.tsx +174 -0
  34. package/src/nodes/ImageNode.tsx +48 -9
  35. package/src/plugins/ColorPlugin.tsx +19 -14
  36. package/src/plugins/ImagePlugin.tsx +79 -84
  37. package/src/plugins/ListPlugin.tsx +20 -38
  38. package/src/plugins/ToolbarPlugin.tsx +76 -78
  39. package/src/plugins/VideoPlugin.tsx +46 -55
  40. package/src/plugins/YoutubePlugin.tsx +83 -0
  41. package/src/styles/lexical-editor.css +962 -3
  42. package/dist/style.css +0 -3
  43. package/postcss.config.js +0 -6
  44. package/src/assets/react.svg +0 -1
@@ -3,39 +3,31 @@ import { FaYoutube } from "react-icons/fa";
3
3
  import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
4
4
  import { $insertNodes } from "lexical";
5
5
  import { $createVideoNode } from "../nodes/VideoNode";
6
- import {
7
- Dialog,
8
- DialogContent,
9
- DialogHeader,
10
- DialogTitle,
11
- DialogFooter,
12
- DialogTrigger,
13
- } from "../components/ui/dialog";
14
- import { Button } from "../components/ui/button";
15
- import { Input } from "../components/ui/input";
6
+ import RawDialog from "../components/common/Dialog";
16
7
 
17
8
  export default function VideoPlugin() {
18
9
  const [isOpen, setIsOpen] = useState(false);
19
10
  const [showMessage, setShowMessage] = useState(false);
20
11
  const [url, setURL] = useState("");
12
+
21
13
  const [editor] = useLexicalComposerContext();
22
14
 
23
15
  const onEmbed = () => {
24
16
  if (!url) return;
25
17
 
26
-
27
18
  let provider: "youtube" | "drive" | null = null;
28
19
  let id: string | null = null;
29
20
 
30
- // Detect YouTube
21
+ // youtube
31
22
  const ytMatch =
32
23
  /^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/.exec(url);
24
+
33
25
  if (ytMatch && ytMatch[2]?.length === 11) {
34
26
  provider = "youtube";
35
27
  id = ytMatch[2];
36
28
  }
37
29
 
38
- // Detect Google Drive
30
+ // drive
39
31
  const driveMatch = /drive\.google\.com\/file\/d\/([a-zA-Z0-9_-]+)\//.exec(url);
40
32
  if (driveMatch && driveMatch[1]) {
41
33
  provider = "drive";
@@ -43,7 +35,7 @@ export default function VideoPlugin() {
43
35
  }
44
36
 
45
37
  if (!id || !provider) {
46
- setShowMessage(true)
38
+ setShowMessage(true);
47
39
  return;
48
40
  }
49
41
 
@@ -53,58 +45,57 @@ export default function VideoPlugin() {
53
45
  });
54
46
 
55
47
  setURL("");
56
- setShowMessage(false)
48
+ setShowMessage(false);
57
49
  setIsOpen(false);
58
50
  };
59
51
 
60
52
  useEffect(() => {
61
53
  if (!isOpen) {
62
54
  setURL("");
63
- setShowMessage(false)
55
+ setShowMessage(false);
64
56
  }
65
57
  }, [isOpen]);
66
58
 
67
59
  return (
68
- <div>
69
- <Dialog open={isOpen} onOpenChange={setIsOpen}>
70
- <DialogTrigger asChild>
71
- <Button
72
- size="icon"
73
- variant="ghost"
74
- className="rounded-md text-gray-700 hover:bg-gray-200"
60
+ <div className="lexical-text-editor-dialog">
61
+ {/* Open dialog button */}
62
+ <button
63
+ type="button"
64
+ className={`size-8 lexical-btn ${isOpen ? "toolbarActive" : "toolbar"} icon`}
65
+ onClick={() => setIsOpen(true)}
66
+ >
67
+ <FaYoutube size={18} color="red" />
68
+ </button>
69
+
70
+ {/* Dialog */}
71
+ <RawDialog open={isOpen} onClose={() => setIsOpen(false)}>
72
+ <div className="lte-dialog-header">Embed Video</div>
73
+
74
+ <div className="lte-dialog-body">
75
+ <input
76
+ className="lte-input"
77
+ placeholder="Add YouTube or Google Drive URL"
78
+ value={url}
79
+ onChange={(e) => setURL(e.target.value)}
80
+ />
81
+
82
+ {showMessage && (
83
+ <p className="lte-error-text">
84
+ It's not a valid YouTube or Google Drive URL
85
+ </p>
86
+ )}
87
+ </div>
88
+
89
+ <div className="lte-dialog-footer">
90
+ <button
91
+ className="lte-primary-btn"
92
+ disabled={!url}
93
+ onClick={onEmbed}
75
94
  >
76
- <FaYoutube />
77
- </Button>
78
- </DialogTrigger>
79
-
80
- <DialogContent className="sm:max-w-md">
81
- <DialogHeader>
82
- <DialogTitle className="!text-lg text-gray-800">Embed Video</DialogTitle>
83
- </DialogHeader>
84
-
85
- <div className="py-2">
86
- <Input
87
- value={url}
88
- onChange={(e) => setURL(e.target.value)}
89
- placeholder="Add YouTube or Google Drive URL"
90
- />
91
- {showMessage && <p className="mt-1.5 text-red-800/80 text-[0.8rem]">It's not a valid youtube or google drive URL</p>}
92
- </div>
93
-
94
-
95
-
96
- <DialogFooter>
97
- <Button
98
- onClick={onEmbed}
99
- disabled={!url}
100
- className="bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-50"
101
- >
102
- Embed
103
- </Button>
104
- </DialogFooter>
105
- </DialogContent>
106
- </Dialog>
95
+ Embed
96
+ </button>
97
+ </div>
98
+ </RawDialog>
107
99
  </div>
108
100
  );
109
101
  }
110
-
@@ -0,0 +1,83 @@
1
+ "use client";
2
+
3
+ import { useState } from "react";
4
+ import { Youtube } from "lucide-react";
5
+ import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
6
+ import { $insertNodes } from "lexical";
7
+ import { $createYoutubeNode } from "../nodes/YoutubeNode";
8
+ import {
9
+ Dialog,
10
+ DialogContent,
11
+ DialogHeader,
12
+ DialogTitle,
13
+ DialogFooter,
14
+ DialogTrigger,
15
+ } from "../components/ui/dialog";
16
+ import { Button } from "../components/ui/button";
17
+ import { Input } from "../components/ui/input";
18
+
19
+ export default function YoutubePlugin() {
20
+ const [isOpen, setIsOpen] = useState(false);
21
+ const [url, setURL] = useState("");
22
+
23
+ const [editor] = useLexicalComposerContext();
24
+
25
+ const onEmbed = () => {
26
+ if (!url) return;
27
+ const match =
28
+ /^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/.exec(url);
29
+ const id = match && match?.[2]?.length === 11 ? match?.[2] : null;
30
+ if (!id) return;
31
+
32
+ editor.update(() => {
33
+ const node = $createYoutubeNode({ id });
34
+ $insertNodes([node]);
35
+ });
36
+
37
+ setURL("");
38
+ setIsOpen(false);
39
+ };
40
+
41
+ return (
42
+ <div>
43
+ <Dialog open={isOpen} onOpenChange={setIsOpen}>
44
+ <DialogTrigger asChild>
45
+ <Button
46
+ size="icon"
47
+ variant="ghost"
48
+ className="rounded-md text-gray-700 hover:bg-gray-200"
49
+ >
50
+ <Youtube className="h-4 w-4 text-red-600" />
51
+ </Button>
52
+ </DialogTrigger>
53
+
54
+ <DialogContent className="sm:max-w-md">
55
+ <DialogHeader>
56
+ <DialogTitle className="!text-xl">
57
+ Embed YouTube Video
58
+
59
+ </DialogTitle>
60
+ </DialogHeader>
61
+
62
+ <div className="py-2">
63
+ <Input
64
+ value={url}
65
+ onChange={(e) => setURL(e.target.value)}
66
+ placeholder="Add YouTube URL"
67
+ />
68
+ </div>
69
+
70
+ <DialogFooter>
71
+ <Button
72
+ onClick={onEmbed}
73
+ disabled={!url}
74
+ className="bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-50"
75
+ >
76
+ Embed
77
+ </Button>
78
+ </DialogFooter>
79
+ </DialogContent>
80
+ </Dialog>
81
+ </div>
82
+ );
83
+ }