@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.
- package/README.md +390 -241
- package/dist/components/AlignmentSelectionList.js +19 -0
- package/dist/components/ColorPicker.js +30 -0
- package/dist/components/ContentPreview.js +11 -0
- package/dist/components/DisplayControls.d.ts +16 -0
- package/dist/components/DropdownList.js +18 -0
- package/dist/components/FindReplaceModal.d.ts +11 -0
- package/dist/components/FindReplaceModal.js +120 -0
- package/dist/components/FontSelectionList.d.ts +17 -0
- package/dist/components/FontSelectionList.js +17 -0
- package/dist/components/HeadingSelectionList.js +19 -0
- package/dist/components/ImageComponent.d.ts +1 -0
- package/dist/components/ImageComponent.js +111 -0
- package/dist/components/InsertDropdownList.js +17 -0
- package/dist/components/LexicalTextEditor.d.ts +11 -0
- package/dist/components/LexicalTextEditor.js +128 -0
- package/dist/components/LinkModal.js +47 -0
- package/dist/components/Separator.js +4 -0
- package/dist/components/SourceView.d.ts +13 -0
- package/dist/components/SourceView.js +50 -0
- package/dist/components/StatusBar.d.ts +14 -0
- package/dist/components/StatusBar.js +30 -0
- package/dist/components/ToolbarOverflowModal.d.ts +15 -0
- package/dist/components/common/Dialog.js +27 -0
- package/dist/components/common/Popover.d.ts +10 -1
- package/dist/components/common/Popover.js +37 -0
- package/dist/components/common/Tooltip.d.ts +7 -0
- package/dist/components/common/Tooltip.js +20 -0
- package/dist/components/ui/button.js +35 -0
- package/dist/components/ui/command.js +33 -0
- package/dist/components/ui/dialog.js +35 -0
- package/dist/components/ui/input.js +6 -0
- package/dist/components/ui/popover.js +16 -0
- package/dist/components/ui/scroll-area.js +12 -0
- package/dist/components/ui/tooltip.js +16 -0
- package/dist/constants/index.d.ts +23 -1
- package/dist/constants/index.js +224 -0
- package/dist/index.d.ts +11 -0
- 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 -1
- package/dist/lib/utils.js +5 -0
- package/dist/nodes/ExtendedTextNode.js +140 -0
- package/dist/nodes/ImageNode.d.ts +5 -1
- package/dist/nodes/ImageNode.js +149 -0
- package/dist/nodes/VideoNode.js +80 -0
- package/dist/nodes/YoutubeNode.js +64 -0
- package/dist/plugins/CodeBlockPlugin.d.ts +1 -0
- package/dist/plugins/CodeBlockPlugin.js +88 -0
- package/dist/plugins/ColorPlugin.js +47 -0
- package/dist/plugins/CustomOnChangePlugin.js +33 -0
- package/dist/plugins/FontFamilyPlugin.d.ts +1 -0
- package/dist/plugins/FontFamilyPlugin.js +53 -0
- package/dist/plugins/FontSizePlugin.d.ts +1 -0
- package/dist/plugins/FontSizePlugin.js +48 -0
- package/dist/plugins/ImagePlugin.d.ts +3 -1
- package/dist/plugins/ImagePlugin.js +91 -0
- package/dist/plugins/ListPlugin.js +44 -0
- package/dist/plugins/TablePlugin.d.ts +1 -0
- package/dist/plugins/TablePlugin.js +92 -0
- package/dist/plugins/ToolbarPlugin.d.ts +14 -1
- package/dist/plugins/ToolbarPlugin.js +381 -0
- package/dist/plugins/VideoPlugin.js +49 -0
- package/dist/plugins/YoutubePlugin.js +30 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/editor_screenshot.png +0 -0
- package/package.json +11 -4
- package/googlebd703883f12c69e4.html +0 -1
- package/rollup.config.js +0 -55
- package/src/components/AlignmentSelectionList.tsx +0 -61
- package/src/components/ColorPicker.tsx +0 -66
- package/src/components/ContentPreview.tsx +0 -51
- package/src/components/DropdownList.tsx +0 -57
- package/src/components/HeadingSelectionList.tsx +0 -61
- package/src/components/ImageComponent.tsx +0 -140
- package/src/components/InsertDropdownList.tsx +0 -36
- package/src/components/LexicalTextEditor.tsx +0 -119
- package/src/components/LinkModal.tsx +0 -127
- package/src/components/Separator.tsx +0 -7
- package/src/components/common/Dialog.tsx +0 -47
- package/src/components/common/Popover.tsx +0 -87
- package/src/components/common/Tooltip.tsx +0 -43
- package/src/components/ui/button.tsx +0 -58
- package/src/components/ui/command.tsx +0 -183
- package/src/components/ui/dialog.tsx +0 -142
- package/src/components/ui/input.tsx +0 -21
- package/src/components/ui/popover.tsx +0 -46
- package/src/components/ui/scroll-area.tsx +0 -56
- package/src/components/ui/tooltip.tsx +0 -59
- package/src/constants/index.tsx +0 -177
- package/src/index.ts +0 -6
- package/src/lib/utils.ts +0 -6
- package/src/nodes/ExtendedTextNode.tsx +0 -185
- package/src/nodes/ImageNode.tsx +0 -195
- package/src/nodes/VideoNode.tsx +0 -134
- package/src/nodes/YoutubeNode.tsx +0 -101
- package/src/plugins/ColorPlugin.tsx +0 -85
- package/src/plugins/CustomOnChangePlugin.tsx +0 -50
- package/src/plugins/ImagePlugin.tsx +0 -118
- package/src/plugins/ListPlugin.tsx +0 -58
- package/src/plugins/ToolbarPlugin.tsx +0 -500
- package/src/plugins/VideoPlugin.tsx +0 -100
- package/src/plugins/YoutubePlugin.tsx +0 -83
- package/src/styles/lexical-editor.css +0 -1053
- package/src/types/global.d.ts +0 -34
- package/src/types/other.d.ts +0 -11
- package/src/types/react-icons.d.ts +0 -11
- package/tailwind.config.js +0 -10
- package/tsconfig.json +0 -32
package/src/nodes/VideoNode.tsx
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DecoratorNode,
|
|
3
|
-
type DOMConversionMap,
|
|
4
|
-
type DOMConversionOutput,
|
|
5
|
-
type DOMExportOutput,
|
|
6
|
-
type NodeKey,
|
|
7
|
-
type SerializedLexicalNode,
|
|
8
|
-
} from "lexical";
|
|
9
|
-
import type { JSX } from "react";
|
|
10
|
-
|
|
11
|
-
export interface SerializedVideoNode extends SerializedLexicalNode {
|
|
12
|
-
id: string;
|
|
13
|
-
provider: "youtube" | "drive";
|
|
14
|
-
type: "video";
|
|
15
|
-
version: 1;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const $createVideoNode = ({
|
|
19
|
-
id,
|
|
20
|
-
provider,
|
|
21
|
-
}: {
|
|
22
|
-
id: string;
|
|
23
|
-
provider: "youtube" | "drive";
|
|
24
|
-
}) => {
|
|
25
|
-
return new VideoNode({ id, provider });
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const ID_ATTR = "data-lexical-video";
|
|
29
|
-
const PROVIDER_ATTR = "data-provider";
|
|
30
|
-
const HEIGHT = "315px";
|
|
31
|
-
const WIDTH = "560px";
|
|
32
|
-
|
|
33
|
-
const getEmbedLink = (id: string, provider: "youtube" | "drive") => {
|
|
34
|
-
if (provider === "drive") {
|
|
35
|
-
return `https://drive.google.com/file/d/${id}/preview`;
|
|
36
|
-
}
|
|
37
|
-
return `https://www.youtube-nocookie.com/embed/${id}`;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const convertVideoElement = (domNode: HTMLElement): DOMConversionOutput | null => {
|
|
41
|
-
const id = domNode?.getAttribute(ID_ATTR);
|
|
42
|
-
const provider = (domNode?.getAttribute(PROVIDER_ATTR) as
|
|
43
|
-
| "youtube"
|
|
44
|
-
| "drive") ?? "youtube";
|
|
45
|
-
if (!id) return null;
|
|
46
|
-
const node = $createVideoNode({ id, provider });
|
|
47
|
-
return { node };
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export class VideoNode extends DecoratorNode<JSX.Element> {
|
|
51
|
-
__id: string;
|
|
52
|
-
__provider: "youtube" | "drive";
|
|
53
|
-
|
|
54
|
-
constructor({
|
|
55
|
-
id,
|
|
56
|
-
provider,
|
|
57
|
-
key,
|
|
58
|
-
}: {
|
|
59
|
-
id: string;
|
|
60
|
-
provider: "youtube" | "drive";
|
|
61
|
-
key?: NodeKey;
|
|
62
|
-
}) {
|
|
63
|
-
super(key);
|
|
64
|
-
this.__id = id;
|
|
65
|
-
this.__provider = provider;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
static getType(): string {
|
|
69
|
-
return "video";
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
static clone(node: VideoNode): VideoNode {
|
|
73
|
-
return new VideoNode({
|
|
74
|
-
id: node.__id,
|
|
75
|
-
provider: node.__provider,
|
|
76
|
-
key: node.getKey(),
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
static importJSON(serializedNode: SerializedVideoNode): VideoNode {
|
|
81
|
-
return $createVideoNode({
|
|
82
|
-
id: serializedNode.id,
|
|
83
|
-
provider: serializedNode.provider,
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
exportJSON(): SerializedVideoNode {
|
|
88
|
-
return {
|
|
89
|
-
id: this.__id,
|
|
90
|
-
provider: this.__provider,
|
|
91
|
-
type: "video",
|
|
92
|
-
version: 1,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
updateDOM(): boolean {
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
decorate(): JSX.Element {
|
|
101
|
-
return (
|
|
102
|
-
<iframe
|
|
103
|
-
height={HEIGHT}
|
|
104
|
-
width={WIDTH}
|
|
105
|
-
src={getEmbedLink(this.__id, this.__provider)}
|
|
106
|
-
frameBorder="0"
|
|
107
|
-
allowFullScreen
|
|
108
|
-
/>
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
createDOM(): HTMLElement {
|
|
113
|
-
return document.createElement("div");
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
exportDOM(): DOMExportOutput {
|
|
117
|
-
const iframe = document.createElement("iframe");
|
|
118
|
-
iframe.setAttribute(ID_ATTR, this.__id);
|
|
119
|
-
iframe.setAttribute(PROVIDER_ATTR, this.__provider);
|
|
120
|
-
iframe.setAttribute("height", HEIGHT);
|
|
121
|
-
iframe.setAttribute("width", WIDTH);
|
|
122
|
-
iframe.setAttribute("src", getEmbedLink(this.__id, this.__provider));
|
|
123
|
-
return { element: iframe };
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
static importDOM(): DOMConversionMap | null {
|
|
127
|
-
return {
|
|
128
|
-
iframe: () => ({
|
|
129
|
-
conversion: convertVideoElement,
|
|
130
|
-
priority: 0,
|
|
131
|
-
}),
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DecoratorNode,
|
|
3
|
-
type DOMConversionMap,
|
|
4
|
-
type DOMConversionOutput,
|
|
5
|
-
type DOMExportOutput,
|
|
6
|
-
type NodeKey,
|
|
7
|
-
type SerializedLexicalNode,
|
|
8
|
-
} from "lexical";
|
|
9
|
-
import type { JSX } from "react";
|
|
10
|
-
|
|
11
|
-
export interface SerializedYoutubeNode extends SerializedLexicalNode {
|
|
12
|
-
id: string;
|
|
13
|
-
type: "youtube";
|
|
14
|
-
version: 1;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const $createYoutubeNode = ({ id }: { id: string }) => {
|
|
18
|
-
return new YoutubeNode({ id });
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const ID_ATTR = "data-lexical-youtube";
|
|
22
|
-
const HEIGHT = "315px";
|
|
23
|
-
const WIDTH = "560px";
|
|
24
|
-
const getYoutubeLink = (id: string) =>
|
|
25
|
-
`https://www.youtube-nocookie.com/embed/${id}`;
|
|
26
|
-
|
|
27
|
-
const convertYoutubeElement = (
|
|
28
|
-
domNode: HTMLElement
|
|
29
|
-
): DOMConversionOutput | null => {
|
|
30
|
-
const id = domNode?.getAttribute(ID_ATTR);
|
|
31
|
-
if (!id) return null;
|
|
32
|
-
const node = $createYoutubeNode({ id });
|
|
33
|
-
return { node };
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export class YoutubeNode extends DecoratorNode<JSX.Element> {
|
|
37
|
-
__id: string;
|
|
38
|
-
|
|
39
|
-
constructor({ id, key }: { id: string; key?: NodeKey }) {
|
|
40
|
-
super(key);
|
|
41
|
-
this.__id = id;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
static getType(): string {
|
|
45
|
-
return "youtube";
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
static clone(node: YoutubeNode): YoutubeNode {
|
|
49
|
-
return new YoutubeNode({
|
|
50
|
-
id: node.__id,
|
|
51
|
-
key: node.getKey(),
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Correctly typed importJSON
|
|
56
|
-
static importJSON(serializedNode: SerializedYoutubeNode): YoutubeNode {
|
|
57
|
-
return $createYoutubeNode({ id: serializedNode.id });
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
exportJSON(): SerializedYoutubeNode {
|
|
61
|
-
return {
|
|
62
|
-
id: this.__id,
|
|
63
|
-
type: "youtube",
|
|
64
|
-
version: 1,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
decorate(): JSX.Element {
|
|
69
|
-
return (
|
|
70
|
-
<iframe
|
|
71
|
-
height={HEIGHT}
|
|
72
|
-
width={WIDTH}
|
|
73
|
-
src={getYoutubeLink(this.__id)}
|
|
74
|
-
frameBorder="0"
|
|
75
|
-
allowFullScreen
|
|
76
|
-
/>
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
createDOM(): HTMLElement {
|
|
81
|
-
return document.createElement("div");
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
exportDOM(): DOMExportOutput {
|
|
85
|
-
const iframe = document.createElement("iframe");
|
|
86
|
-
iframe.setAttribute(ID_ATTR, this.__id);
|
|
87
|
-
iframe.setAttribute("height", HEIGHT);
|
|
88
|
-
iframe.setAttribute("width", WIDTH);
|
|
89
|
-
iframe.setAttribute("src", getYoutubeLink(this.__id));
|
|
90
|
-
return { element: iframe };
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
static importDOM(): DOMConversionMap | null {
|
|
94
|
-
return {
|
|
95
|
-
iframe: () => ({
|
|
96
|
-
conversion: convertYoutubeElement,
|
|
97
|
-
priority: 0,
|
|
98
|
-
}),
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import ColorPicker from '../components/ColorPicker'
|
|
2
|
-
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'
|
|
3
|
-
import { $getSelection, $isRangeSelection, SELECTION_CHANGE_COMMAND } from 'lexical';
|
|
4
|
-
import { $patchStyleText, $getSelectionStyleValueForProperty } from '@lexical/selection'
|
|
5
|
-
import { useEffect, useState } from 'react';
|
|
6
|
-
import { mergeRegister } from '@lexical/utils';
|
|
7
|
-
import { LOW_PRIORIRTY } from '../constants';
|
|
8
|
-
import { AiOutlineBgColors, AiOutlineFontColors } from 'react-icons/ai';
|
|
9
|
-
import TooltipX from '../components/common/Tooltip';
|
|
10
|
-
|
|
11
|
-
export default function ColorPlugin() {
|
|
12
|
-
const [editor] = useLexicalComposerContext();
|
|
13
|
-
const [{ color, bgColor }, setColors] = useState({
|
|
14
|
-
color: '#000',
|
|
15
|
-
bgColor: '#fff'
|
|
16
|
-
})
|
|
17
|
-
const updateToolbar = () => {
|
|
18
|
-
const selection = $getSelection();
|
|
19
|
-
if ($isRangeSelection(selection)) {
|
|
20
|
-
const color = $getSelectionStyleValueForProperty(
|
|
21
|
-
selection,
|
|
22
|
-
"color",
|
|
23
|
-
"#000"
|
|
24
|
-
);
|
|
25
|
-
const bgColor = $getSelectionStyleValueForProperty(
|
|
26
|
-
selection,
|
|
27
|
-
"background",
|
|
28
|
-
"#fff"
|
|
29
|
-
);
|
|
30
|
-
setColors({ color, bgColor })
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
useEffect(() => {
|
|
34
|
-
return mergeRegister(
|
|
35
|
-
editor.registerUpdateListener(({ editorState }) => {
|
|
36
|
-
editorState.read(() => {
|
|
37
|
-
updateToolbar();
|
|
38
|
-
})
|
|
39
|
-
}),
|
|
40
|
-
editor.registerCommand(
|
|
41
|
-
SELECTION_CHANGE_COMMAND,
|
|
42
|
-
() => {
|
|
43
|
-
updateToolbar();
|
|
44
|
-
return false;
|
|
45
|
-
},
|
|
46
|
-
LOW_PRIORIRTY
|
|
47
|
-
),
|
|
48
|
-
)
|
|
49
|
-
}, [editor])
|
|
50
|
-
|
|
51
|
-
const updateColor = ({ property, color }:
|
|
52
|
-
{
|
|
53
|
-
property: 'background' | 'color',
|
|
54
|
-
color: string
|
|
55
|
-
}
|
|
56
|
-
) => {
|
|
57
|
-
editor.update(() => {
|
|
58
|
-
const selection = $getSelection();
|
|
59
|
-
if (selection) $patchStyleText(selection, { [property]: color })
|
|
60
|
-
})
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return (
|
|
64
|
-
<>
|
|
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>
|
|
83
|
-
</>
|
|
84
|
-
)
|
|
85
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from "react";
|
|
2
|
-
import { OnChangePlugin } from "@lexical/react/LexicalOnChangePlugin";
|
|
3
|
-
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
4
|
-
import { $generateHtmlFromNodes, $generateNodesFromDOM } from "@lexical/html";
|
|
5
|
-
import { $getRoot, $insertNodes } from "lexical";
|
|
6
|
-
|
|
7
|
-
interface CustomOnChangePluginProps {
|
|
8
|
-
value: string;
|
|
9
|
-
onChange: (value: string) => void;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export default function CustomOnChangePlugin({
|
|
13
|
-
value,
|
|
14
|
-
onChange,
|
|
15
|
-
}: CustomOnChangePluginProps) {
|
|
16
|
-
const [editor] = useLexicalComposerContext();
|
|
17
|
-
const [isFirstRender, setIsFirstRender] = useState(true);
|
|
18
|
-
|
|
19
|
-
useEffect(() => {
|
|
20
|
-
if (!value || !isFirstRender) return;
|
|
21
|
-
|
|
22
|
-
setIsFirstRender(false);
|
|
23
|
-
editor.update(() => {
|
|
24
|
-
const currentHTML = $generateHtmlFromNodes(editor);
|
|
25
|
-
|
|
26
|
-
if (currentHTML !== value) {
|
|
27
|
-
$getRoot().clear();
|
|
28
|
-
const parser = new DOMParser();
|
|
29
|
-
const dom = parser.parseFromString(value, "text/html");
|
|
30
|
-
const nodes = $generateNodesFromDOM(editor, dom);
|
|
31
|
-
|
|
32
|
-
$insertNodes(nodes);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
}, [editor, value, isFirstRender]);
|
|
36
|
-
|
|
37
|
-
useEffect(() => {
|
|
38
|
-
setIsFirstRender(true);
|
|
39
|
-
}, [value]);
|
|
40
|
-
|
|
41
|
-
return (
|
|
42
|
-
<OnChangePlugin
|
|
43
|
-
onChange={(editorState) => {
|
|
44
|
-
editorState.read(() => {
|
|
45
|
-
onChange($generateHtmlFromNodes(editor));
|
|
46
|
-
});
|
|
47
|
-
}}
|
|
48
|
-
/>
|
|
49
|
-
);
|
|
50
|
-
}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
2
|
-
import { $insertNodes } from "lexical";
|
|
3
|
-
import { $createImageNode } from "../nodes/ImageNode";
|
|
4
|
-
import { 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
|
-
export default function ImagePlugin() {
|
|
10
|
-
const [editor] = useLexicalComposerContext();
|
|
11
|
-
const inputRef = useRef<HTMLInputElement>(null);
|
|
12
|
-
|
|
13
|
-
const [isOpen, setIsOpen] = useState(false);
|
|
14
|
-
const [url, setURL] = useState("");
|
|
15
|
-
const [altText, setAltText] = useState("");
|
|
16
|
-
const [file, setFile] = useState<File>();
|
|
17
|
-
|
|
18
|
-
const addImage = () => {
|
|
19
|
-
let src = url;
|
|
20
|
-
if (file) src = URL.createObjectURL(file);
|
|
21
|
-
|
|
22
|
-
editor.update(() => {
|
|
23
|
-
const node = $createImageNode({ src, altText });
|
|
24
|
-
$insertNodes([node]);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
setFile(undefined);
|
|
28
|
-
setAltText("");
|
|
29
|
-
setURL("");
|
|
30
|
-
setIsOpen(false);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
return (
|
|
34
|
-
<div className="lexical-text-editor-dialog">
|
|
35
|
-
{/* hidden file input */}
|
|
36
|
-
<input
|
|
37
|
-
type="file"
|
|
38
|
-
ref={inputRef}
|
|
39
|
-
accept="image/*"
|
|
40
|
-
className="lte-hidden"
|
|
41
|
-
onChange={(e) => {
|
|
42
|
-
const f = e.target.files?.[0];
|
|
43
|
-
if (f) setFile(f);
|
|
44
|
-
e.target.value = "";
|
|
45
|
-
}}
|
|
46
|
-
/>
|
|
47
|
-
|
|
48
|
-
{/* Open dialog button */}
|
|
49
|
-
<button type="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
|
-
|
|
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>
|
|
79
|
-
</div>
|
|
80
|
-
|
|
81
|
-
{/* <button type="button"
|
|
82
|
-
className="lte-outline-btn"
|
|
83
|
-
onClick={() => inputRef.current?.click()}
|
|
84
|
-
>
|
|
85
|
-
|
|
86
|
-
Upload Image
|
|
87
|
-
</button> */}
|
|
88
|
-
|
|
89
|
-
<button type="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 type="button"
|
|
108
|
-
className="lte-primary-btn"
|
|
109
|
-
disabled={!url && !file}
|
|
110
|
-
onClick={addImage}
|
|
111
|
-
>
|
|
112
|
-
Add Image
|
|
113
|
-
</button>
|
|
114
|
-
</div>
|
|
115
|
-
</RawDialog>
|
|
116
|
-
</div>
|
|
117
|
-
);
|
|
118
|
-
}
|
|
@@ -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
|
-
}
|