@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,189 +0,0 @@
1
- import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
2
- import { $insertNodes, COMMAND_PRIORITY_LOW, PASTE_COMMAND } from "lexical";
3
- import { $createImageNode } from "../nodes/ImageNode";
4
- import { useCallback, useEffect, useRef, useState } from "react";
5
- import { IoImageOutline } from "react-icons/io5";
6
- import RawDialog from "../components/common/Dialog";
7
- import { LuUpload } from "react-icons/lu";
8
-
9
- type InsertImageParams = {
10
- src: string;
11
- altText?: string;
12
- caption?: string;
13
- };
14
-
15
- async function insertImage(editor: any, { src, altText = "", caption = "" }: InsertImageParams) {
16
- editor.update(() => {
17
- const node = $createImageNode({ src, altText, caption });
18
- $insertNodes([node]);
19
- });
20
- }
21
-
22
- export default function ImagePlugin({ onImageUpload }: { onImageUpload?: (file: File) => Promise<string> }) {
23
- const [editor] = useLexicalComposerContext();
24
- const inputRef = useRef<HTMLInputElement>(null);
25
-
26
- const [isOpen, setIsOpen] = useState(false);
27
- const [url, setURL] = useState("");
28
- const [altText, setAltText] = useState("");
29
- const [caption, setCaption] = useState("");
30
- const [file, setFile] = useState<File>();
31
- const [isUploading, setIsUploading] = useState(false);
32
-
33
- const handleFileUpload = useCallback(async (file: File, alt: string = "", cap: string = "") => {
34
- let src: string;
35
-
36
- if (onImageUpload) {
37
- src = await onImageUpload(file);
38
- } else {
39
- src = URL.createObjectURL(file);
40
- }
41
-
42
- insertImage(editor, { src, altText: alt, caption: cap });
43
- }, [editor, onImageUpload]);
44
-
45
- const addImage = async () => {
46
- if (isUploading) return;
47
-
48
- if (file) {
49
- setIsUploading(true);
50
- try {
51
- await handleFileUpload(file, altText, caption);
52
- } catch (err) {
53
- console.error("Image upload failed:", err);
54
- setIsUploading(false);
55
- return;
56
- }
57
- setIsUploading(false);
58
- } else if (url) {
59
- insertImage(editor, { src: url, altText, caption });
60
- } else {
61
- return;
62
- }
63
-
64
- setFile(undefined);
65
- setAltText("");
66
- setCaption("");
67
- setURL("");
68
- setIsOpen(false);
69
- };
70
-
71
- useEffect(() => {
72
- const unregister = editor.registerCommand(
73
- PASTE_COMMAND,
74
- (payload: ClipboardEvent | InputEvent) => {
75
- if (payload instanceof ClipboardEvent) {
76
- const items = payload.clipboardData?.items;
77
- if (!items) return false;
78
-
79
- for (const item of items) {
80
- if (item.type.startsWith("image/")) {
81
- payload.preventDefault();
82
- const blob = item.getAsFile();
83
- if (blob) {
84
- handleFileUpload(blob, "", "").catch(console.error);
85
- }
86
- return true;
87
- }
88
- }
89
- }
90
- return false;
91
- },
92
- COMMAND_PRIORITY_LOW,
93
- );
94
- return () => unregister();
95
- }, [editor, handleFileUpload]);
96
-
97
- return (
98
- <div className="lexical-text-editor-dialog">
99
- {/* hidden file input */}
100
- <input
101
- type="file"
102
- ref={inputRef}
103
- accept="image/*"
104
- className="lte-hidden"
105
- onChange={(e) => {
106
- const f = e.target.files?.[0];
107
- if (f) setFile(f);
108
- e.target.value = "";
109
- }}
110
- />
111
-
112
- {/* Open dialog button */}
113
- <button type="button"
114
- className={`size-8 lexical-btn ${isOpen ? "toolbarActive" : "toolbar"} icon`}
115
- onClick={() => setIsOpen((prev) => !prev)}
116
- >
117
- <IoImageOutline size={18} />
118
- </button>
119
-
120
-
121
-
122
- {/* Dialog */}
123
- <RawDialog open={isOpen} onClose={() => setIsOpen(false)}>
124
- <div className="lte-dialog-header">Add Image</div>
125
-
126
- <div className="lte-dialog-body">
127
- <input
128
- className="lte-input"
129
- placeholder="Alt text"
130
- value={altText}
131
- onChange={(e) => setAltText(e.target.value)}
132
- />
133
-
134
- <input
135
- className="lte-input"
136
- placeholder="Caption"
137
- value={caption}
138
- onChange={(e) => setCaption(e.target.value)}
139
- />
140
-
141
- <input
142
- className="lte-input"
143
- placeholder="Add image by URL"
144
- value={url}
145
- onChange={(e) => setURL(e.target.value)}
146
- />
147
-
148
- <div className="lte-divider">
149
- <span>or</span>
150
- </div>
151
-
152
- {/* <button type="button"
153
- className="lte-outline-btn"
154
- onClick={() => inputRef.current?.click()}
155
- >
156
-
157
- Upload Image
158
- </button> */}
159
-
160
- <button type="button"
161
- className={`lexical-btn heading-trigger toolbar-active`}
162
- onClick={() => inputRef.current?.click()}
163
- style={{
164
- width: 'fit-content',
165
- margin: '0 auto'
166
- }}
167
- >
168
- <LuUpload size={20} />
169
- <span>Upload Image</span>
170
- </button>
171
-
172
- {file && (
173
- <div className="lte-file-name">{file.name}</div>
174
- )}
175
- </div>
176
-
177
- <div className="lte-dialog-footer">
178
- <button type="button"
179
- className="lte-primary-btn"
180
- disabled={(!url && !file) || isUploading}
181
- onClick={addImage}
182
- >
183
- {isUploading ? "Uploading..." : "Add Image"}
184
- </button>
185
- </div>
186
- </RawDialog>
187
- </div>
188
- );
189
- }
@@ -1,58 +0,0 @@
1
-
2
- import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
3
- import {
4
- INSERT_ORDERED_LIST_COMMAND,
5
- INSERT_UNORDERED_LIST_COMMAND,
6
- REMOVE_LIST_COMMAND,
7
- } from "@lexical/list";
8
- import { BsListOl, BsListUl } from "react-icons/bs";
9
- import TooltipX from "../components/common/Tooltip";
10
-
11
- interface ListPluginProps {
12
- blockType: string;
13
- }
14
-
15
- export default function ListPlugin({ blockType }: ListPluginProps) {
16
- const [editor] = useLexicalComposerContext();
17
-
18
- const handleOrderedList = () => {
19
- if (blockType === "ol") {
20
- editor.dispatchCommand(REMOVE_LIST_COMMAND, undefined);
21
- } else {
22
- editor.dispatchCommand(INSERT_ORDERED_LIST_COMMAND, undefined);
23
- }
24
- };
25
-
26
- const handleUnorderedList = () => {
27
- if (blockType === "ul") {
28
- editor.dispatchCommand(REMOVE_LIST_COMMAND, undefined);
29
- } else {
30
- editor.dispatchCommand(INSERT_UNORDERED_LIST_COMMAND, undefined);
31
- }
32
- };
33
-
34
- return (
35
- <>
36
- <TooltipX content="Ordered list" direction="bottom">
37
- <button type="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 type="button"
48
- className={`size-8 lexical-btn ${blockType === "ul" ? "toolbarActive" : "toolbar"
49
- } icon`}
50
- onClick={handleUnorderedList}
51
- >
52
- <BsListUl />
53
- </button>
54
- </TooltipX>
55
-
56
- </>
57
- );
58
- }