@innoviatech/lexical-text-editor 1.0.6 → 2.0.1
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 +107 -36
- package/dist/components/ContentPreview.d.ts +1 -1
- package/dist/components/HeadingSelectionList.d.ts +1 -1
- package/dist/components/LexicalTextEditor.d.ts +1 -1
- package/dist/components/common/Dialog.d.ts +9 -0
- package/dist/components/common/Popover.d.ts +21 -0
- package/dist/components/common/Tooltip.d.ts +10 -0
- package/dist/components/ui/button.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- 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 -0
- package/dist/nodes/ExtendedTextNode.d.ts +11 -0
- package/dist/nodes/ImageNode.d.ts +10 -14
- package/dist/plugins/YoutubePlugin.d.ts +1 -0
- package/editor_screenshot.png +0 -0
- package/innoviatech-lexical-text-editor-2.0.0.tgz +0 -0
- package/package.json +20 -16
- package/rollup.config.js +3 -4
- package/src/components/AlignmentSelectionList.tsx +41 -24
- package/src/components/ColorPicker.tsx +7 -21
- package/src/components/ContentPreview.tsx +26 -20
- package/src/components/DropdownList.tsx +39 -24
- package/src/components/HeadingSelectionList.tsx +48 -32
- package/src/components/ImageComponent.tsx +52 -19
- package/src/components/InsertDropdownList.tsx +1 -1
- package/src/components/LexicalTextEditor.tsx +33 -28
- package/src/components/LinkModal.tsx +42 -45
- package/src/components/common/Dialog.tsx +47 -0
- package/src/components/common/Popover.tsx +87 -0
- package/src/components/common/Tooltip.tsx +43 -0
- package/src/components/ui/command.tsx +0 -1
- package/src/nodes/ExtendedTextNode.tsx +174 -0
- package/src/nodes/ImageNode.tsx +87 -48
- package/src/plugins/ColorPlugin.tsx +19 -14
- package/src/plugins/ImagePlugin.tsx +79 -84
- package/src/plugins/ListPlugin.tsx +20 -38
- package/src/plugins/ToolbarPlugin.tsx +76 -78
- package/src/plugins/VideoPlugin.tsx +46 -55
- package/src/plugins/YoutubePlugin.tsx +83 -0
- package/src/styles/lexical-editor.css +961 -3
- package/dist/style.css +0 -3
- package/postcss.config.js +0 -6
- package/src/assets/react.svg +0 -1
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import {
|
|
2
|
+
$applyNodeReplacement,
|
|
3
|
+
$isTextNode,
|
|
4
|
+
DOMConversion,
|
|
5
|
+
DOMConversionMap,
|
|
6
|
+
DOMConversionOutput,
|
|
7
|
+
NodeKey,
|
|
8
|
+
TextNode,
|
|
9
|
+
SerializedTextNode,
|
|
10
|
+
LexicalNode
|
|
11
|
+
} from 'lexical';
|
|
12
|
+
|
|
13
|
+
export class ExtendedTextNode extends TextNode {
|
|
14
|
+
constructor(text: string, key?: NodeKey) {
|
|
15
|
+
super(text, key);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static getType(): string {
|
|
19
|
+
return 'extended-text';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static clone(node: ExtendedTextNode): ExtendedTextNode {
|
|
23
|
+
return new ExtendedTextNode(node.__text, node.__key);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static importDOM(): DOMConversionMap | null {
|
|
27
|
+
const importers = TextNode.importDOM();
|
|
28
|
+
return {
|
|
29
|
+
...importers,
|
|
30
|
+
span: () => ({
|
|
31
|
+
conversion: patchStyleConversion(importers?.span),
|
|
32
|
+
priority: 1
|
|
33
|
+
}),
|
|
34
|
+
div: () => ({
|
|
35
|
+
conversion: patchStyleConversion(importers?.div),
|
|
36
|
+
priority: 1
|
|
37
|
+
}),
|
|
38
|
+
p: () => ({
|
|
39
|
+
conversion: patchStyleConversion(importers?.p),
|
|
40
|
+
priority: 1
|
|
41
|
+
}),
|
|
42
|
+
b: () => ({
|
|
43
|
+
conversion: patchStyleConversion(importers?.b),
|
|
44
|
+
priority: 1
|
|
45
|
+
}),
|
|
46
|
+
strong: () => ({
|
|
47
|
+
conversion: patchStyleConversion(importers?.strong),
|
|
48
|
+
priority: 1
|
|
49
|
+
}),
|
|
50
|
+
i: () => ({
|
|
51
|
+
conversion: patchStyleConversion(importers?.i),
|
|
52
|
+
priority: 1
|
|
53
|
+
}),
|
|
54
|
+
em: () => ({
|
|
55
|
+
conversion: patchStyleConversion(importers?.em),
|
|
56
|
+
priority: 1
|
|
57
|
+
}),
|
|
58
|
+
u: () => ({
|
|
59
|
+
conversion: patchStyleConversion(importers?.u),
|
|
60
|
+
priority: 1
|
|
61
|
+
}),
|
|
62
|
+
s: () => ({
|
|
63
|
+
conversion: patchStyleConversion(importers?.s),
|
|
64
|
+
priority: 1
|
|
65
|
+
}),
|
|
66
|
+
strike: () => ({
|
|
67
|
+
conversion: patchStyleConversion(importers?.strike),
|
|
68
|
+
priority: 1
|
|
69
|
+
}),
|
|
70
|
+
code: () => ({
|
|
71
|
+
conversion: patchStyleConversion(importers?.code),
|
|
72
|
+
priority: 1
|
|
73
|
+
})
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static importJSON(serializedNode: SerializedTextNode): ExtendedTextNode {
|
|
78
|
+
return $createExtendedTextNode().updateFromJSON(serializedNode);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
isSimpleText() {
|
|
82
|
+
return this.__type === 'extended-text' && this.__mode === 0;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function $createExtendedTextNode(text: string = ''): ExtendedTextNode {
|
|
87
|
+
return $applyNodeReplacement(new ExtendedTextNode(text));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function $isExtendedTextNode(node: LexicalNode | null | undefined): node is ExtendedTextNode {
|
|
91
|
+
return node instanceof ExtendedTextNode;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Helper function to patch style conversion
|
|
95
|
+
function patchStyleConversion(
|
|
96
|
+
originalDOMConverter?: (node: HTMLElement) => DOMConversion | null
|
|
97
|
+
): (node: HTMLElement) => DOMConversionOutput | null {
|
|
98
|
+
return (node) => {
|
|
99
|
+
const original = originalDOMConverter?.(node);
|
|
100
|
+
if (!original) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
const originalOutput = original.conversion(node);
|
|
104
|
+
|
|
105
|
+
if (!originalOutput) {
|
|
106
|
+
return originalOutput;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Extract all style properties
|
|
110
|
+
const style = node.style;
|
|
111
|
+
const styleAttributes: string[] = [];
|
|
112
|
+
|
|
113
|
+
if (style.backgroundColor) {
|
|
114
|
+
styleAttributes.push(`background-color: ${style.backgroundColor}`);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (style.color) {
|
|
118
|
+
styleAttributes.push(`color: ${style.color}`);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (style.fontFamily) {
|
|
122
|
+
styleAttributes.push(`font-family: ${style.fontFamily}`);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (style.fontWeight) {
|
|
126
|
+
styleAttributes.push(`font-weight: ${style.fontWeight}`);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (style.fontSize) {
|
|
130
|
+
styleAttributes.push(`font-size: ${style.fontSize}`);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (style.fontStyle) {
|
|
134
|
+
styleAttributes.push(`font-style: ${style.fontStyle}`);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (style.textDecoration) {
|
|
138
|
+
styleAttributes.push(`text-decoration: ${style.textDecoration}`);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (style.whiteSpace) {
|
|
142
|
+
styleAttributes.push(`white-space: ${style.whiteSpace}`);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (style.textAlign) {
|
|
146
|
+
styleAttributes.push(`text-align: ${style.textAlign}`);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const inlineStyle = node.getAttribute('style');
|
|
150
|
+
if (inlineStyle) {
|
|
151
|
+
// Parse the style string to avoid duplicates
|
|
152
|
+
const stylePairs = inlineStyle.split(';').filter(pair => pair.trim());
|
|
153
|
+
stylePairs.forEach(pair => {
|
|
154
|
+
const [property] = pair.split(':').map(s => s.trim());
|
|
155
|
+
if (property && !styleAttributes.some(attr => attr.startsWith(property))) {
|
|
156
|
+
styleAttributes.push(pair.trim());
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return {
|
|
162
|
+
...originalOutput,
|
|
163
|
+
forChild: (lexicalNode, parent) => {
|
|
164
|
+
const originalForChild = originalOutput?.forChild ?? ((x) => x);
|
|
165
|
+
const result = originalForChild(lexicalNode, parent);
|
|
166
|
+
if ($isTextNode(result) && styleAttributes.length > 0) {
|
|
167
|
+
const styleString = styleAttributes.join('; ');
|
|
168
|
+
return result.setStyle(styleString);
|
|
169
|
+
}
|
|
170
|
+
return result;
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
}
|
package/src/nodes/ImageNode.tsx
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
} from "lexical";
|
|
10
10
|
import type { JSX } from "react";
|
|
11
11
|
|
|
12
|
+
|
|
12
13
|
export interface SerializedImageNode {
|
|
13
14
|
type: "image";
|
|
14
15
|
version: 1;
|
|
@@ -19,65 +20,96 @@ export interface SerializedImageNode {
|
|
|
19
20
|
height?: number | "inherit";
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
export
|
|
23
|
+
export type ImageNodePayload = {
|
|
24
|
+
src: string;
|
|
23
25
|
altText: string;
|
|
24
|
-
height?: number;
|
|
25
26
|
maxWidth?: number;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
27
|
+
width?: number | "inherit";
|
|
28
|
+
height?: number | "inherit";
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
export const $createImageNode = (payload: ImageNodePayload) => {
|
|
29
34
|
return $applyNodeReplacement(new ImageNode(payload));
|
|
30
35
|
};
|
|
31
36
|
|
|
37
|
+
|
|
32
38
|
const convertImageElement = (domNode: Node): DOMConversionOutput | null => {
|
|
33
|
-
if (domNode instanceof HTMLImageElement)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
39
|
+
if (!(domNode instanceof HTMLImageElement)) return null;
|
|
40
|
+
|
|
41
|
+
const { src, alt } = domNode;
|
|
42
|
+
|
|
43
|
+
let width: number | "inherit" | undefined;
|
|
44
|
+
let height: number | "inherit" | undefined;
|
|
45
|
+
|
|
46
|
+
// Attributes
|
|
47
|
+
if (domNode.width) width = domNode.width;
|
|
48
|
+
if (domNode.height) height = domNode.height;
|
|
49
|
+
|
|
50
|
+
// Inline styles fallback
|
|
51
|
+
const style = domNode.style;
|
|
52
|
+
|
|
53
|
+
if ((!width || width === 0) && style.width) {
|
|
54
|
+
const parsed = parseInt(style.width, 10);
|
|
55
|
+
if (!Number.isNaN(parsed)) width = parsed;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if ((!height || height === 0) && style.height) {
|
|
59
|
+
const parsed = parseInt(style.height, 10);
|
|
60
|
+
if (!Number.isNaN(parsed)) height = parsed;
|
|
37
61
|
}
|
|
38
|
-
|
|
62
|
+
|
|
63
|
+
const node = $createImageNode({
|
|
64
|
+
src,
|
|
65
|
+
altText: alt,
|
|
66
|
+
width: width ?? "inherit",
|
|
67
|
+
height: height ?? "inherit",
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
return { node };
|
|
39
71
|
};
|
|
40
72
|
|
|
73
|
+
|
|
41
74
|
export class ImageNode extends DecoratorNode<JSX.Element> {
|
|
42
75
|
__src: string;
|
|
43
76
|
__altText: string;
|
|
44
|
-
|
|
45
|
-
|
|
77
|
+
__width?: number | "inherit";
|
|
78
|
+
__height?: number | "inherit";
|
|
46
79
|
__maxWidth: number;
|
|
47
80
|
|
|
48
|
-
constructor(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
key?: NodeKey;
|
|
62
|
-
} = {}) {
|
|
81
|
+
constructor(
|
|
82
|
+
{
|
|
83
|
+
src = "",
|
|
84
|
+
altText = "",
|
|
85
|
+
maxWidth = 1080,
|
|
86
|
+
width = "inherit",
|
|
87
|
+
height = "inherit",
|
|
88
|
+
key,
|
|
89
|
+
}: ImageNodePayload & { key?: NodeKey } = {
|
|
90
|
+
src: "",
|
|
91
|
+
altText: "",
|
|
92
|
+
}
|
|
93
|
+
) {
|
|
63
94
|
super(key);
|
|
64
|
-
this.__altText = altText;
|
|
65
95
|
this.__src = src;
|
|
96
|
+
this.__altText = altText;
|
|
66
97
|
this.__maxWidth = maxWidth;
|
|
67
|
-
this.__height = height;
|
|
68
98
|
this.__width = width;
|
|
99
|
+
this.__height = height;
|
|
69
100
|
}
|
|
70
101
|
|
|
102
|
+
|
|
71
103
|
static getType(): string {
|
|
72
104
|
return "image";
|
|
73
105
|
}
|
|
74
106
|
|
|
75
107
|
static clone(node: ImageNode): ImageNode {
|
|
76
108
|
return new ImageNode({
|
|
77
|
-
altText: node.__altText,
|
|
78
109
|
src: node.__src,
|
|
79
|
-
|
|
110
|
+
altText: node.__altText,
|
|
80
111
|
width: node.__width,
|
|
112
|
+
height: node.__height,
|
|
81
113
|
maxWidth: node.__maxWidth,
|
|
82
114
|
key: node.getKey(),
|
|
83
115
|
});
|
|
@@ -87,27 +119,37 @@ export class ImageNode extends DecoratorNode<JSX.Element> {
|
|
|
87
119
|
return document.createElement("span");
|
|
88
120
|
}
|
|
89
121
|
|
|
122
|
+
updateDOM(prevNode: ImageNode): boolean {
|
|
123
|
+
return (
|
|
124
|
+
prevNode.__width !== this.__width ||
|
|
125
|
+
prevNode.__height !== this.__height
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
|
|
90
130
|
exportDOM(): DOMExportOutput {
|
|
91
|
-
const
|
|
92
|
-
image.setAttribute("src", this.__src);
|
|
93
|
-
image.setAttribute("alt", this.__altText);
|
|
131
|
+
const img = document.createElement("img");
|
|
94
132
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
if (this.__height && this.__height !== "inherit") {
|
|
99
|
-
image.setAttribute("height", String(this.__height));
|
|
100
|
-
}
|
|
133
|
+
img.src = this.__src;
|
|
134
|
+
img.alt = this.__altText;
|
|
101
135
|
|
|
136
|
+
if (this.__width !== "inherit") {
|
|
137
|
+
img.width = this.__width ?? 0;
|
|
138
|
+
}
|
|
102
139
|
|
|
140
|
+
if (this.__height !== "inherit") {
|
|
141
|
+
img.height = this.__height ?? 0;
|
|
142
|
+
}
|
|
103
143
|
|
|
104
|
-
return { element:
|
|
144
|
+
return { element: img };
|
|
105
145
|
}
|
|
106
146
|
|
|
107
|
-
|
|
108
147
|
static importDOM(): DOMConversionMap | null {
|
|
109
148
|
return {
|
|
110
|
-
img: () => ({
|
|
149
|
+
img: () => ({
|
|
150
|
+
conversion: convertImageElement,
|
|
151
|
+
priority: 1,
|
|
152
|
+
}),
|
|
111
153
|
};
|
|
112
154
|
}
|
|
113
155
|
|
|
@@ -133,14 +175,13 @@ export class ImageNode extends DecoratorNode<JSX.Element> {
|
|
|
133
175
|
});
|
|
134
176
|
}
|
|
135
177
|
|
|
178
|
+
|
|
136
179
|
updateDimensions(width: number, height: number) {
|
|
137
180
|
const writable = this.getWritable();
|
|
138
181
|
writable.__width = width;
|
|
139
182
|
writable.__height = height;
|
|
140
183
|
}
|
|
141
|
-
|
|
142
|
-
return false;
|
|
143
|
-
}
|
|
184
|
+
|
|
144
185
|
|
|
145
186
|
decorate(): JSX.Element {
|
|
146
187
|
return (
|
|
@@ -155,5 +196,3 @@ export class ImageNode extends DecoratorNode<JSX.Element> {
|
|
|
155
196
|
);
|
|
156
197
|
}
|
|
157
198
|
}
|
|
158
|
-
|
|
159
|
-
|
|
@@ -6,6 +6,7 @@ import { useEffect, useState } from 'react';
|
|
|
6
6
|
import { mergeRegister } from '@lexical/utils';
|
|
7
7
|
import { LOW_PRIORIRTY } from '../constants';
|
|
8
8
|
import { AiOutlineBgColors, AiOutlineFontColors } from 'react-icons/ai';
|
|
9
|
+
import TooltipX from '../components/common/Tooltip';
|
|
9
10
|
|
|
10
11
|
export default function ColorPlugin() {
|
|
11
12
|
const [editor] = useLexicalComposerContext();
|
|
@@ -61,20 +62,24 @@ export default function ColorPlugin() {
|
|
|
61
62
|
|
|
62
63
|
return (
|
|
63
64
|
<>
|
|
64
|
-
<
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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>
|
|
78
83
|
</>
|
|
79
84
|
)
|
|
80
85
|
}
|
|
@@ -1,32 +1,22 @@
|
|
|
1
|
-
|
|
2
1
|
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
3
2
|
import { $insertNodes } from "lexical";
|
|
4
3
|
import { $createImageNode } from "../nodes/ImageNode";
|
|
5
4
|
import { useRef, useState } from "react";
|
|
6
|
-
import { Upload } from "lucide-react";
|
|
7
|
-
import {
|
|
8
|
-
Dialog,
|
|
9
|
-
DialogContent,
|
|
10
|
-
DialogHeader,
|
|
11
|
-
DialogTitle,
|
|
12
|
-
DialogFooter,
|
|
13
|
-
DialogTrigger,
|
|
14
|
-
} from "../components/ui/dialog";
|
|
15
|
-
import { Button } from "../components/ui/button";
|
|
16
|
-
import { Input } from "../components/ui/input";
|
|
17
5
|
import { IoImageOutline } from "react-icons/io5";
|
|
6
|
+
import RawDialog from "../components/common/Dialog";
|
|
7
|
+
import { LuUpload } from "react-icons/lu";
|
|
18
8
|
|
|
19
9
|
export default function ImagePlugin() {
|
|
10
|
+
const [editor] = useLexicalComposerContext();
|
|
11
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
12
|
+
|
|
20
13
|
const [isOpen, setIsOpen] = useState(false);
|
|
21
14
|
const [url, setURL] = useState("");
|
|
22
15
|
const [altText, setAltText] = useState("");
|
|
23
16
|
const [file, setFile] = useState<File>();
|
|
24
|
-
const inputRef = useRef<HTMLInputElement>(null);
|
|
25
|
-
const [editor] = useLexicalComposerContext();
|
|
26
17
|
|
|
27
|
-
const
|
|
28
|
-
let src =
|
|
29
|
-
if (url) src = url;
|
|
18
|
+
const addImage = () => {
|
|
19
|
+
let src = url;
|
|
30
20
|
if (file) src = URL.createObjectURL(file);
|
|
31
21
|
|
|
32
22
|
editor.update(() => {
|
|
@@ -35,89 +25,94 @@ export default function ImagePlugin() {
|
|
|
35
25
|
});
|
|
36
26
|
|
|
37
27
|
setFile(undefined);
|
|
38
|
-
setAltText("")
|
|
28
|
+
setAltText("");
|
|
39
29
|
setURL("");
|
|
40
30
|
setIsOpen(false);
|
|
41
31
|
};
|
|
42
32
|
|
|
43
33
|
return (
|
|
44
|
-
<div>
|
|
45
|
-
{/*
|
|
34
|
+
<div className="lexical-text-editor-dialog">
|
|
35
|
+
{/* hidden file input */}
|
|
46
36
|
<input
|
|
47
37
|
type="file"
|
|
48
38
|
ref={inputRef}
|
|
49
39
|
accept="image/*"
|
|
50
|
-
className="hidden"
|
|
40
|
+
className="lte-hidden"
|
|
51
41
|
onChange={(e) => {
|
|
52
|
-
const
|
|
53
|
-
if (
|
|
54
|
-
e.target.value = "";
|
|
42
|
+
const f = e.target.files?.[0];
|
|
43
|
+
if (f) setFile(f);
|
|
44
|
+
e.target.value = "";
|
|
55
45
|
}}
|
|
56
46
|
/>
|
|
57
47
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
</DialogTrigger>
|
|
68
|
-
|
|
69
|
-
<DialogContent className="sm:max-w-md">
|
|
70
|
-
<DialogHeader>
|
|
71
|
-
<DialogTitle className="!text-lg text-gray-800">
|
|
72
|
-
Add Image
|
|
73
|
-
</DialogTitle>
|
|
74
|
-
</DialogHeader>
|
|
75
|
-
|
|
76
|
-
<div className="flex flex-col gap-4 py-2">
|
|
77
|
-
<div className="flex flex-col items-center gap-4">
|
|
78
|
-
<Input
|
|
79
|
-
value={altText}
|
|
80
|
-
onChange={(e) => setAltText(e.target.value)}
|
|
81
|
-
placeholder="Alt text"
|
|
82
|
-
/>
|
|
83
|
-
<Input
|
|
84
|
-
value={url}
|
|
85
|
-
onChange={(e) => setURL(e.target.value)}
|
|
86
|
-
placeholder="Add Image by URL"
|
|
87
|
-
/>
|
|
88
|
-
|
|
89
|
-
{/* Stylish OR divider */}
|
|
90
|
-
<div className="flex items-center w-full text-gray-500 text-sm">
|
|
91
|
-
<div className="flex-grow border-t border-gray-300"></div>
|
|
92
|
-
<span className="mx-2">or</span>
|
|
93
|
-
<div className="flex-grow border-t border-gray-300"></div>
|
|
94
|
-
</div>
|
|
95
|
-
|
|
96
|
-
<div className="flex flex-col gap-2 w-fit">
|
|
97
|
-
<Button
|
|
98
|
-
variant="outline"
|
|
99
|
-
className="flex items-center gap-2 bg-gray-50 hover:bg-gray-100"
|
|
100
|
-
onClick={() => inputRef.current?.click()}
|
|
101
|
-
>
|
|
102
|
-
<Upload className="h-4 w-4" /> Upload Image
|
|
103
|
-
</Button>
|
|
104
|
-
{file && <span className="text-sm text-gray-600">{file.name}</span>}
|
|
105
|
-
</div>
|
|
106
|
-
</div>
|
|
48
|
+
{/* Open dialog button */}
|
|
49
|
+
<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
|
+
|
|
107
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>
|
|
108
79
|
</div>
|
|
109
80
|
|
|
110
|
-
<
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
81
|
+
{/* <button
|
|
82
|
+
className="lte-outline-btn"
|
|
83
|
+
onClick={() => inputRef.current?.click()}
|
|
84
|
+
>
|
|
85
|
+
|
|
86
|
+
Upload Image
|
|
87
|
+
</button> */}
|
|
88
|
+
|
|
89
|
+
<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
|
|
108
|
+
className="lte-primary-btn"
|
|
109
|
+
disabled={!url && !file}
|
|
110
|
+
onClick={addImage}
|
|
111
|
+
>
|
|
112
|
+
Add Image
|
|
113
|
+
</button>
|
|
114
|
+
</div>
|
|
115
|
+
</RawDialog>
|
|
121
116
|
</div>
|
|
122
117
|
);
|
|
123
118
|
}
|