@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.
- package/README.md +390 -288
- 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.js +111 -0
- package/dist/components/InsertDropdownList.js +17 -0
- package/dist/components/LexicalTextEditor.d.ts +10 -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 +10 -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.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.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 +13 -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 -206
- 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 -174
- package/src/nodes/ImageNode.tsx +0 -232
- 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 -189
- 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/ImageNode.tsx
DELETED
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
import { ImageComponent } from "../components/ImageComponent";
|
|
2
|
-
import {
|
|
3
|
-
DecoratorNode,
|
|
4
|
-
type DOMConversionMap,
|
|
5
|
-
type DOMConversionOutput,
|
|
6
|
-
type DOMExportOutput,
|
|
7
|
-
type NodeKey,
|
|
8
|
-
$applyNodeReplacement,
|
|
9
|
-
} from "lexical";
|
|
10
|
-
import type { JSX } from "react";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export interface SerializedImageNode {
|
|
14
|
-
type: "image";
|
|
15
|
-
version: 1;
|
|
16
|
-
src: string;
|
|
17
|
-
altText: string;
|
|
18
|
-
maxWidth: number;
|
|
19
|
-
width?: number | "inherit";
|
|
20
|
-
height?: number | "inherit";
|
|
21
|
-
caption?: string;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export type ImageNodePayload = {
|
|
25
|
-
src: string;
|
|
26
|
-
altText: string;
|
|
27
|
-
maxWidth?: number;
|
|
28
|
-
width?: number | "inherit";
|
|
29
|
-
height?: number | "inherit";
|
|
30
|
-
caption?: string;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
export const $createImageNode = (payload: ImageNodePayload) => {
|
|
35
|
-
return $applyNodeReplacement(new ImageNode(payload));
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const convertImageElement = (domNode: Node): DOMConversionOutput | null => {
|
|
40
|
-
if (!(domNode instanceof HTMLImageElement)) return null;
|
|
41
|
-
|
|
42
|
-
const { src, alt } = domNode;
|
|
43
|
-
|
|
44
|
-
let width: number | "inherit" | undefined;
|
|
45
|
-
let height: number | "inherit" | undefined;
|
|
46
|
-
|
|
47
|
-
// Attributes
|
|
48
|
-
if (domNode.width) width = domNode.width;
|
|
49
|
-
if (domNode.height) height = domNode.height;
|
|
50
|
-
|
|
51
|
-
// Inline styles fallback
|
|
52
|
-
const style = domNode.style;
|
|
53
|
-
|
|
54
|
-
if ((!width || width === 0) && style.width) {
|
|
55
|
-
const parsed = parseInt(style.width, 10);
|
|
56
|
-
if (!Number.isNaN(parsed)) width = parsed;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if ((!height || height === 0) && style.height) {
|
|
60
|
-
const parsed = parseInt(style.height, 10);
|
|
61
|
-
if (!Number.isNaN(parsed)) height = parsed;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const node = $createImageNode({
|
|
65
|
-
src,
|
|
66
|
-
altText: alt,
|
|
67
|
-
width: width ?? "inherit",
|
|
68
|
-
height: height ?? "inherit",
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
return { node };
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
export class ImageNode extends DecoratorNode<JSX.Element> {
|
|
76
|
-
__src: string;
|
|
77
|
-
__altText: string;
|
|
78
|
-
__width?: number | "inherit";
|
|
79
|
-
__height?: number | "inherit";
|
|
80
|
-
__maxWidth: number;
|
|
81
|
-
__caption: string;
|
|
82
|
-
|
|
83
|
-
constructor(
|
|
84
|
-
{
|
|
85
|
-
src = "",
|
|
86
|
-
altText = "",
|
|
87
|
-
maxWidth = 1080,
|
|
88
|
-
width = "inherit",
|
|
89
|
-
height = "inherit",
|
|
90
|
-
caption = "",
|
|
91
|
-
key,
|
|
92
|
-
}: ImageNodePayload & { key?: NodeKey } = {
|
|
93
|
-
src: "",
|
|
94
|
-
altText: "",
|
|
95
|
-
}
|
|
96
|
-
) {
|
|
97
|
-
super(key);
|
|
98
|
-
this.__src = src;
|
|
99
|
-
this.__altText = altText;
|
|
100
|
-
this.__maxWidth = maxWidth;
|
|
101
|
-
this.__width = width;
|
|
102
|
-
this.__height = height;
|
|
103
|
-
this.__caption = caption;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
static getType(): string {
|
|
107
|
-
return "image";
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
static clone(node: ImageNode): ImageNode {
|
|
111
|
-
return new ImageNode({
|
|
112
|
-
src: node.__src,
|
|
113
|
-
altText: node.__altText,
|
|
114
|
-
width: node.__width,
|
|
115
|
-
height: node.__height,
|
|
116
|
-
maxWidth: node.__maxWidth,
|
|
117
|
-
caption: node.__caption,
|
|
118
|
-
key: node.getKey(),
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
createDOM(): HTMLElement {
|
|
123
|
-
return document.createElement("span");
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
updateDOM(prevNode: ImageNode): boolean {
|
|
127
|
-
return (
|
|
128
|
-
prevNode.__width !== this.__width ||
|
|
129
|
-
prevNode.__height !== this.__height
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
exportDOM(): DOMExportOutput {
|
|
135
|
-
const img = document.createElement("img");
|
|
136
|
-
|
|
137
|
-
img.src = this.__src;
|
|
138
|
-
img.alt = this.__altText;
|
|
139
|
-
|
|
140
|
-
if (this.__width !== "inherit") {
|
|
141
|
-
img.width = this.__width ?? 0;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if (this.__height !== "inherit") {
|
|
145
|
-
img.height = this.__height ?? 0;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (this.__caption) {
|
|
149
|
-
const figure = document.createElement("figure");
|
|
150
|
-
const figcaption = document.createElement("figcaption");
|
|
151
|
-
figcaption.textContent = this.__caption;
|
|
152
|
-
figure.appendChild(img);
|
|
153
|
-
figure.appendChild(figcaption);
|
|
154
|
-
return { element: figure };
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
return { element: img };
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
static importDOM(): DOMConversionMap | null {
|
|
161
|
-
return {
|
|
162
|
-
img: () => ({
|
|
163
|
-
conversion: convertImageElement,
|
|
164
|
-
priority: 1,
|
|
165
|
-
}),
|
|
166
|
-
figure: () => ({
|
|
167
|
-
conversion: (node: HTMLElement) => {
|
|
168
|
-
const img = node.querySelector("img");
|
|
169
|
-
if (!img) return null;
|
|
170
|
-
const figcaption = node.querySelector("figcaption");
|
|
171
|
-
const caption = figcaption?.textContent || "";
|
|
172
|
-
const result = convertImageElement(img);
|
|
173
|
-
if (result?.node instanceof ImageNode && caption) {
|
|
174
|
-
result.node.__caption = caption;
|
|
175
|
-
}
|
|
176
|
-
return result;
|
|
177
|
-
},
|
|
178
|
-
priority: 1,
|
|
179
|
-
}),
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
exportJSON(): SerializedImageNode {
|
|
184
|
-
return {
|
|
185
|
-
type: "image",
|
|
186
|
-
version: 1,
|
|
187
|
-
src: this.__src,
|
|
188
|
-
altText: this.__altText,
|
|
189
|
-
maxWidth: this.__maxWidth,
|
|
190
|
-
width: this.__width,
|
|
191
|
-
height: this.__height,
|
|
192
|
-
caption: this.__caption,
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
static importJSON(serializedNode: SerializedImageNode): ImageNode {
|
|
197
|
-
return new ImageNode({
|
|
198
|
-
src: serializedNode.src,
|
|
199
|
-
altText: serializedNode.altText,
|
|
200
|
-
maxWidth: serializedNode.maxWidth,
|
|
201
|
-
width: serializedNode.width,
|
|
202
|
-
height: serializedNode.height,
|
|
203
|
-
caption: serializedNode.caption,
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
updateDimensions(width: number, height: number) {
|
|
208
|
-
const writable = this.getWritable();
|
|
209
|
-
writable.__width = width;
|
|
210
|
-
writable.__height = height;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
setCaption(caption: string) {
|
|
214
|
-
const writable = this.getWritable();
|
|
215
|
-
writable.__caption = caption;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
decorate(): JSX.Element {
|
|
220
|
-
return (
|
|
221
|
-
<ImageComponent
|
|
222
|
-
src={this.__src}
|
|
223
|
-
altText={this.__altText}
|
|
224
|
-
nodeKey={this.getKey()}
|
|
225
|
-
width={this.__width}
|
|
226
|
-
height={this.__height}
|
|
227
|
-
maxWidth={this.__maxWidth}
|
|
228
|
-
caption={this.__caption}
|
|
229
|
-
/>
|
|
230
|
-
);
|
|
231
|
-
}
|
|
232
|
-
}
|
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
|
-
}
|