@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.
Files changed (111) hide show
  1. package/README.md +390 -241
  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.d.ts +1 -0
  13. package/dist/components/ImageComponent.js +111 -0
  14. package/dist/components/InsertDropdownList.js +17 -0
  15. package/dist/components/LexicalTextEditor.d.ts +11 -0
  16. package/dist/components/LexicalTextEditor.js +128 -0
  17. package/dist/components/LinkModal.js +47 -0
  18. package/dist/components/Separator.js +4 -0
  19. package/dist/components/SourceView.d.ts +13 -0
  20. package/dist/components/SourceView.js +50 -0
  21. package/dist/components/StatusBar.d.ts +14 -0
  22. package/dist/components/StatusBar.js +30 -0
  23. package/dist/components/ToolbarOverflowModal.d.ts +15 -0
  24. package/dist/components/common/Dialog.js +27 -0
  25. package/dist/components/common/Popover.d.ts +10 -1
  26. package/dist/components/common/Popover.js +37 -0
  27. package/dist/components/common/Tooltip.d.ts +7 -0
  28. package/dist/components/common/Tooltip.js +20 -0
  29. package/dist/components/ui/button.js +35 -0
  30. package/dist/components/ui/command.js +33 -0
  31. package/dist/components/ui/dialog.js +35 -0
  32. package/dist/components/ui/input.js +6 -0
  33. package/dist/components/ui/popover.js +16 -0
  34. package/dist/components/ui/scroll-area.js +12 -0
  35. package/dist/components/ui/tooltip.js +16 -0
  36. package/dist/constants/index.d.ts +23 -1
  37. package/dist/constants/index.js +224 -0
  38. package/dist/index.d.ts +11 -0
  39. package/dist/index.esm.js +1 -1
  40. package/dist/index.esm.js.map +1 -1
  41. package/dist/index.js +1 -1
  42. package/dist/index.js.map +1 -1
  43. package/dist/lexical-editor.css +1 -1
  44. package/dist/lib/utils.js +5 -0
  45. package/dist/nodes/ExtendedTextNode.js +140 -0
  46. package/dist/nodes/ImageNode.d.ts +5 -1
  47. package/dist/nodes/ImageNode.js +149 -0
  48. package/dist/nodes/VideoNode.js +80 -0
  49. package/dist/nodes/YoutubeNode.js +64 -0
  50. package/dist/plugins/CodeBlockPlugin.d.ts +1 -0
  51. package/dist/plugins/CodeBlockPlugin.js +88 -0
  52. package/dist/plugins/ColorPlugin.js +47 -0
  53. package/dist/plugins/CustomOnChangePlugin.js +33 -0
  54. package/dist/plugins/FontFamilyPlugin.d.ts +1 -0
  55. package/dist/plugins/FontFamilyPlugin.js +53 -0
  56. package/dist/plugins/FontSizePlugin.d.ts +1 -0
  57. package/dist/plugins/FontSizePlugin.js +48 -0
  58. package/dist/plugins/ImagePlugin.d.ts +3 -1
  59. package/dist/plugins/ImagePlugin.js +91 -0
  60. package/dist/plugins/ListPlugin.js +44 -0
  61. package/dist/plugins/TablePlugin.d.ts +1 -0
  62. package/dist/plugins/TablePlugin.js +92 -0
  63. package/dist/plugins/ToolbarPlugin.d.ts +14 -1
  64. package/dist/plugins/ToolbarPlugin.js +381 -0
  65. package/dist/plugins/VideoPlugin.js +49 -0
  66. package/dist/plugins/YoutubePlugin.js +30 -0
  67. package/dist/tsconfig.tsbuildinfo +1 -0
  68. package/editor_screenshot.png +0 -0
  69. package/package.json +11 -4
  70. package/googlebd703883f12c69e4.html +0 -1
  71. package/rollup.config.js +0 -55
  72. package/src/components/AlignmentSelectionList.tsx +0 -61
  73. package/src/components/ColorPicker.tsx +0 -66
  74. package/src/components/ContentPreview.tsx +0 -51
  75. package/src/components/DropdownList.tsx +0 -57
  76. package/src/components/HeadingSelectionList.tsx +0 -61
  77. package/src/components/ImageComponent.tsx +0 -140
  78. package/src/components/InsertDropdownList.tsx +0 -36
  79. package/src/components/LexicalTextEditor.tsx +0 -119
  80. package/src/components/LinkModal.tsx +0 -127
  81. package/src/components/Separator.tsx +0 -7
  82. package/src/components/common/Dialog.tsx +0 -47
  83. package/src/components/common/Popover.tsx +0 -87
  84. package/src/components/common/Tooltip.tsx +0 -43
  85. package/src/components/ui/button.tsx +0 -58
  86. package/src/components/ui/command.tsx +0 -183
  87. package/src/components/ui/dialog.tsx +0 -142
  88. package/src/components/ui/input.tsx +0 -21
  89. package/src/components/ui/popover.tsx +0 -46
  90. package/src/components/ui/scroll-area.tsx +0 -56
  91. package/src/components/ui/tooltip.tsx +0 -59
  92. package/src/constants/index.tsx +0 -177
  93. package/src/index.ts +0 -6
  94. package/src/lib/utils.ts +0 -6
  95. package/src/nodes/ExtendedTextNode.tsx +0 -185
  96. package/src/nodes/ImageNode.tsx +0 -195
  97. package/src/nodes/VideoNode.tsx +0 -134
  98. package/src/nodes/YoutubeNode.tsx +0 -101
  99. package/src/plugins/ColorPlugin.tsx +0 -85
  100. package/src/plugins/CustomOnChangePlugin.tsx +0 -50
  101. package/src/plugins/ImagePlugin.tsx +0 -118
  102. package/src/plugins/ListPlugin.tsx +0 -58
  103. package/src/plugins/ToolbarPlugin.tsx +0 -500
  104. package/src/plugins/VideoPlugin.tsx +0 -100
  105. package/src/plugins/YoutubePlugin.tsx +0 -83
  106. package/src/styles/lexical-editor.css +0 -1053
  107. package/src/types/global.d.ts +0 -34
  108. package/src/types/other.d.ts +0 -11
  109. package/src/types/react-icons.d.ts +0 -11
  110. package/tailwind.config.js +0 -10
  111. package/tsconfig.json +0 -32
@@ -1,59 +0,0 @@
1
- import * as React from "react"
2
- import * as TooltipPrimitive from "@radix-ui/react-tooltip"
3
-
4
- import { cn } from "../../lib/utils"
5
-
6
- function TooltipProvider({
7
- delayDuration = 0,
8
- ...props
9
- }: React.ComponentProps<typeof TooltipPrimitive.Provider>) {
10
- return (
11
- <TooltipPrimitive.Provider
12
- data-slot="tooltip-provider"
13
- delayDuration={delayDuration}
14
- {...props}
15
- />
16
- )
17
- }
18
-
19
- function Tooltip({
20
- ...props
21
- }: React.ComponentProps<typeof TooltipPrimitive.Root>) {
22
- return (
23
- <TooltipProvider>
24
- <TooltipPrimitive.Root data-slot="tooltip" {...props} />
25
- </TooltipProvider>
26
- )
27
- }
28
-
29
- function TooltipTrigger({
30
- ...props
31
- }: React.ComponentProps<typeof TooltipPrimitive.Trigger>) {
32
- return <TooltipPrimitive.Trigger data-slot="tooltip-trigger" {...props} />
33
- }
34
-
35
- function TooltipContent({
36
- className,
37
- sideOffset = 0,
38
- children,
39
- ...props
40
- }: React.ComponentProps<typeof TooltipPrimitive.Content>) {
41
- return (
42
- <TooltipPrimitive.Portal>
43
- <TooltipPrimitive.Content
44
- data-slot="tooltip-content"
45
- sideOffset={sideOffset}
46
- className={cn(
47
- "bg-foreground text-background animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance",
48
- className
49
- )}
50
- {...props}
51
- >
52
- {children}
53
- <TooltipPrimitive.Arrow className="bg-foreground fill-foreground z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]" />
54
- </TooltipPrimitive.Content>
55
- </TooltipPrimitive.Portal>
56
- )
57
- }
58
-
59
- export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider }
@@ -1,177 +0,0 @@
1
-
2
- import { RxLetterCaseLowercase, RxLetterCaseCapitalize, RxLetterCaseUppercase } from "react-icons/rx";
3
- import { TbBold, TbItalic, TbUnderline } from "react-icons/tb";
4
- import { BsArrowClockwise, BsArrowCounterclockwise, BsChatSquareQuote, BsJustify, BsJustifyLeft, BsJustifyRight, BsSubscript, BsSuperscript, BsTextCenter, BsTextParagraph, BsTypeH1, BsTypeH2, BsTypeH3, BsTypeH4, BsTypeH5, BsTypeH6 } from "react-icons/bs";
5
- import { AiOutlineStrikethrough } from "react-icons/ai";
6
- import { IoCodeSlashOutline } from "react-icons/io5";
7
- import { PiHighlighterLight } from "react-icons/pi";
8
-
9
- export enum RichTextAction {
10
- Bold = "bold",
11
- Italics = "italics",
12
- Underline = "underline",
13
- Quote = 'quote',
14
- Lowercase = "lowercase",
15
- Uppercase = "uppercase",
16
- Capitalize = "capitalize",
17
- Strikethrough = "strikethrough",
18
- Superscript = "superscript",
19
- Subscript = "subscript",
20
- Highlight = "highlight",
21
- Code = "code",
22
- Link = 'link',
23
- LeftAlign = "leftAlign",
24
- CenterAlign = "centerAlign",
25
- RightAlign = "rightAlign",
26
- JustifyAlign = "justifyAlign",
27
- Divider = "divider",
28
- Undo = "undo",
29
- Redo = "redo",
30
- }
31
-
32
- export enum HeadingAction {
33
- Normal = 'normal',
34
- H1 = 'h1',
35
- H2 = 'h2',
36
- H3 = 'h3',
37
- H4 = 'h4',
38
- H5 = 'h5',
39
- H6 = 'h6',
40
- }
41
-
42
- export const RICH_TEXT_FORMAT_OPTIONS = [
43
- {
44
- id: RichTextAction.Lowercase,
45
- icon: <RxLetterCaseLowercase />,
46
- label: "Lowercase",
47
- },
48
- {
49
- id: RichTextAction.Uppercase,
50
- icon: <RxLetterCaseUppercase />,
51
- label: "Uppercase",
52
- },
53
- {
54
- id: RichTextAction.Capitalize,
55
- icon: <RxLetterCaseCapitalize />,
56
- label: "Capitalize",
57
- },
58
- {
59
- id: RichTextAction.Strikethrough,
60
- icon: <AiOutlineStrikethrough />,
61
- label: "Strikethrough",
62
- },
63
- {
64
- id: RichTextAction.Highlight,
65
- icon: <PiHighlighterLight />,
66
- label: "Highlight",
67
- fontSize: 10,
68
- },
69
- {
70
- id: RichTextAction.Superscript,
71
- icon: <BsSuperscript />,
72
- label: "Superscript",
73
- },
74
- {
75
- id: RichTextAction.Subscript,
76
- icon: <BsSubscript />,
77
- label: "Subscript",
78
- },
79
-
80
- ];
81
-
82
- export const RICH_TEXT_OPTIONS = [
83
- { id: RichTextAction.Bold, icon: <TbBold />, label: "Bold" },
84
- { id: RichTextAction.Italics, icon: <TbItalic />, label: "Italics" },
85
- { id: RichTextAction.Underline, icon: <TbUnderline />, label: "Underline" },
86
- { id: RichTextAction.Divider },
87
- { id: RichTextAction.Quote, icon: <BsChatSquareQuote />, label: "Quote" },
88
- // { id: RichTextAction.Divider },
89
-
90
- {
91
- id: RichTextAction.Code,
92
- icon: <IoCodeSlashOutline />,
93
- label: "Code",
94
- },
95
- // { id: RichTextAction.Link, label: "Link", icon: <IoIosLink /> },
96
-
97
- ];
98
-
99
- export const RICH_REDO_UNDO_OPTIONS = [
100
- {
101
- id: RichTextAction.Undo,
102
- icon: <BsArrowCounterclockwise />,
103
- label: "Undo",
104
- },
105
- {
106
- id: RichTextAction.Redo,
107
- icon: <BsArrowClockwise />,
108
- label: "Redo",
109
- },
110
- { id: RichTextAction.Divider },
111
- ]
112
-
113
- export const RICH_ALIGNMENT_OPTIONS = [
114
-
115
- {
116
- id: RichTextAction.LeftAlign,
117
- icon: <BsJustifyLeft />,
118
- label: "Left Align",
119
- },
120
- {
121
- id: RichTextAction.CenterAlign,
122
- icon: <BsTextCenter />,
123
- label: "Center Align",
124
- },
125
- {
126
- id: RichTextAction.RightAlign,
127
- icon: <BsJustifyRight />,
128
- label: "Right Align",
129
- },
130
- {
131
- id: RichTextAction.JustifyAlign,
132
- icon: <BsJustify />,
133
- label: "Justify Align",
134
- },
135
- ];
136
-
137
- export const LOW_PRIORIRTY = 1;
138
- export const HEADINGS = [
139
- {
140
- id: "normal",
141
- label: "Normal",
142
- icon: <BsTextParagraph />
143
- },
144
- {
145
- id: "h1",
146
- label: "Heading 1",
147
- icon: <BsTypeH1 />
148
- },
149
- {
150
- id: "h2",
151
- label: "Heading 2",
152
- icon: <BsTypeH2 />
153
- },
154
- {
155
- id: "h3",
156
- label: "Heading 3",
157
- icon: <BsTypeH3 />
158
- },
159
- {
160
- id: "h4",
161
- label: "Heading 4",
162
- icon: <BsTypeH4 />
163
- },
164
- {
165
- id: "h5",
166
- label: "Heading 5",
167
- icon: <BsTypeH5 />
168
- },
169
- {
170
- id: "h6",
171
- label: "Heading 6",
172
- icon: <BsTypeH6 />
173
- },
174
-
175
- ]
176
-
177
- // ["Normal", "H1", "H2", "H3", "H4", "H5", "H6"];
package/src/index.ts DELETED
@@ -1,6 +0,0 @@
1
- // Export main component
2
- export { LexicalTextEditor } from './components/LexicalTextEditor';
3
- export type { LexiTexProps as LexicalTextEditorProps } from './components/LexicalTextEditor';
4
-
5
- // Export styles
6
- import './styles/lexical-editor.css';
package/src/lib/utils.ts DELETED
@@ -1,6 +0,0 @@
1
- import { clsx } from "clsx";
2
- import { twMerge } from "tailwind-merge";
3
-
4
- export function cn(...inputs: any[]) {
5
- return twMerge(clsx(inputs));
6
- }
@@ -1,185 +0,0 @@
1
- import {
2
- $applyNodeReplacement,
3
- $isTextNode,
4
- DOMConversion,
5
- DOMConversionMap,
6
- DOMConversionOutput,
7
- NodeKey,
8
- TextNode,
9
- SerializedTextNode,
10
- LexicalNode,
11
- LineBreakNode,
12
- $createLineBreakNode,
13
- } from 'lexical';
14
-
15
- export class ExtendedTextNode extends TextNode {
16
- constructor(text: string, key?: NodeKey) {
17
- super(text, key);
18
- }
19
-
20
- static getType(): string {
21
- return 'extended-text';
22
- }
23
-
24
- static clone(node: ExtendedTextNode): ExtendedTextNode {
25
- return new ExtendedTextNode(node.__text, node.__key);
26
- }
27
-
28
- static importDOM(): DOMConversionMap | null {
29
- const importers = TextNode.importDOM();
30
- return {
31
- ...importers,
32
-
33
- br: () => ({
34
- conversion: () => ({
35
- node: $createLineBreakNode(),
36
- }),
37
- priority: 1,
38
- }),
39
-
40
- span: () => ({
41
- conversion: patchStyleConversion(importers?.span),
42
- priority: 1,
43
- }),
44
- div: () => ({
45
- conversion: patchStyleConversion(importers?.div),
46
- priority: 1,
47
- }),
48
- p: () => ({
49
- conversion: patchStyleConversion(importers?.p),
50
- priority: 1,
51
- }),
52
- b: () => ({
53
- conversion: patchStyleConversion(importers?.b),
54
- priority: 1,
55
- }),
56
- strong: () => ({
57
- conversion: patchStyleConversion(importers?.strong),
58
- priority: 1,
59
- }),
60
- i: () => ({
61
- conversion: patchStyleConversion(importers?.i),
62
- priority: 1,
63
- }),
64
- em: () => ({
65
- conversion: patchStyleConversion(importers?.em),
66
- priority: 1,
67
- }),
68
- u: () => ({
69
- conversion: patchStyleConversion(importers?.u),
70
- priority: 1,
71
- }),
72
- s: () => ({
73
- conversion: patchStyleConversion(importers?.s),
74
- priority: 1,
75
- }),
76
- strike: () => ({
77
- conversion: patchStyleConversion(importers?.strike),
78
- priority: 1,
79
- }),
80
- code: () => ({
81
- conversion: patchStyleConversion(importers?.code),
82
- priority: 1,
83
- }),
84
- };
85
- }
86
-
87
- static importJSON(serializedNode: SerializedTextNode): ExtendedTextNode {
88
- return $createExtendedTextNode().updateFromJSON(serializedNode);
89
- }
90
-
91
- isSimpleText() {
92
- return this.__type === 'extended-text' && this.__mode === 0;
93
- }
94
- }
95
-
96
- export function $createExtendedTextNode(text: string = ''): ExtendedTextNode {
97
- return $applyNodeReplacement(new ExtendedTextNode(text));
98
- }
99
-
100
- export function $isExtendedTextNode(
101
- node: LexicalNode | null | undefined
102
- ): node is ExtendedTextNode {
103
- return node instanceof ExtendedTextNode;
104
- }
105
-
106
- // Helper function to patch style conversion
107
- function patchStyleConversion(
108
- originalDOMConverter?: (node: HTMLElement) => DOMConversion | null
109
- ): (node: HTMLElement) => DOMConversionOutput | null {
110
- return (node) => {
111
- const original = originalDOMConverter?.(node);
112
- if (!original) {
113
- return null;
114
- }
115
- const originalOutput = original.conversion(node);
116
-
117
- if (!originalOutput) {
118
- return originalOutput;
119
- }
120
-
121
- // Extract all style properties
122
- const style = node.style;
123
- const styleAttributes: string[] = [];
124
-
125
- if (style.backgroundColor) {
126
- styleAttributes.push(`background-color: ${style.backgroundColor}`);
127
- }
128
-
129
- if (style.color) {
130
- styleAttributes.push(`color: ${style.color}`);
131
- }
132
-
133
- if (style.fontFamily) {
134
- styleAttributes.push(`font-family: ${style.fontFamily}`);
135
- }
136
-
137
- if (style.fontWeight) {
138
- styleAttributes.push(`font-weight: ${style.fontWeight}`);
139
- }
140
-
141
- if (style.fontSize) {
142
- styleAttributes.push(`font-size: ${style.fontSize}`);
143
- }
144
-
145
- if (style.fontStyle) {
146
- styleAttributes.push(`font-style: ${style.fontStyle}`);
147
- }
148
-
149
- if (style.textDecoration) {
150
- styleAttributes.push(`text-decoration: ${style.textDecoration}`);
151
- }
152
-
153
- if (style.whiteSpace) {
154
- styleAttributes.push(`white-space: ${style.whiteSpace}`);
155
- }
156
-
157
- if (style.textAlign) {
158
- styleAttributes.push(`text-align: ${style.textAlign}`);
159
- }
160
-
161
- const inlineStyle = node.getAttribute('style');
162
- if (inlineStyle) {
163
- const stylePairs = inlineStyle.split(';').filter(pair => pair.trim());
164
- stylePairs.forEach(pair => {
165
- const [property] = pair.split(':').map(s => s.trim());
166
- if (property && !styleAttributes.some(attr => attr.startsWith(property))) {
167
- styleAttributes.push(pair.trim());
168
- }
169
- });
170
- }
171
-
172
- return {
173
- ...originalOutput,
174
- forChild: (lexicalNode, parent) => {
175
- const originalForChild = originalOutput?.forChild ?? ((x) => x);
176
- const result = originalForChild(lexicalNode, parent);
177
- if ($isTextNode(result) && styleAttributes.length > 0) {
178
- const styleString = styleAttributes.join('; ');
179
- return result.setStyle(styleString);
180
- }
181
- return result;
182
- },
183
- };
184
- };
185
- }
@@ -1,195 +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
- }
22
-
23
- export type ImageNodePayload = {
24
- src: string;
25
- altText: string;
26
- maxWidth?: number;
27
- width?: number | "inherit";
28
- height?: number | "inherit";
29
- };
30
-
31
-
32
- export const $createImageNode = (payload: ImageNodePayload) => {
33
- return $applyNodeReplacement(new ImageNode(payload));
34
- };
35
-
36
-
37
- const convertImageElement = (domNode: Node): DOMConversionOutput | null => {
38
- if (!(domNode instanceof HTMLImageElement)) return null;
39
-
40
- const { src, alt } = domNode;
41
-
42
- let width: number | "inherit" | undefined;
43
- let height: number | "inherit" | undefined;
44
-
45
- // Attributes
46
- if (domNode.width) width = domNode.width;
47
- if (domNode.height) height = domNode.height;
48
-
49
- // Inline styles fallback
50
- const style = domNode.style;
51
-
52
- if ((!width || width === 0) && style.width) {
53
- const parsed = parseInt(style.width, 10);
54
- if (!Number.isNaN(parsed)) width = parsed;
55
- }
56
-
57
- if ((!height || height === 0) && style.height) {
58
- const parsed = parseInt(style.height, 10);
59
- if (!Number.isNaN(parsed)) height = parsed;
60
- }
61
-
62
- const node = $createImageNode({
63
- src,
64
- altText: alt,
65
- width: width ?? "inherit",
66
- height: height ?? "inherit",
67
- });
68
-
69
- return { node };
70
- };
71
-
72
-
73
- export class ImageNode extends DecoratorNode<JSX.Element> {
74
- __src: string;
75
- __altText: string;
76
- __width?: number | "inherit";
77
- __height?: number | "inherit";
78
- __maxWidth: number;
79
-
80
- constructor(
81
- {
82
- src = "",
83
- altText = "",
84
- maxWidth = 1080,
85
- width = "inherit",
86
- height = "inherit",
87
- key,
88
- }: ImageNodePayload & { key?: NodeKey } = {
89
- src: "",
90
- altText: "",
91
- }
92
- ) {
93
- super(key);
94
- this.__src = src;
95
- this.__altText = altText;
96
- this.__maxWidth = maxWidth;
97
- this.__width = width;
98
- this.__height = height;
99
- }
100
-
101
- static getType(): string {
102
- return "image";
103
- }
104
-
105
- static clone(node: ImageNode): ImageNode {
106
- return new ImageNode({
107
- src: node.__src,
108
- altText: node.__altText,
109
- width: node.__width,
110
- height: node.__height,
111
- maxWidth: node.__maxWidth,
112
- key: node.getKey(),
113
- });
114
- }
115
-
116
- createDOM(): HTMLElement {
117
- return document.createElement("span");
118
- }
119
-
120
- updateDOM(prevNode: ImageNode): boolean {
121
- return (
122
- prevNode.__width !== this.__width ||
123
- prevNode.__height !== this.__height
124
- );
125
- }
126
-
127
-
128
- exportDOM(): DOMExportOutput {
129
- const img = document.createElement("img");
130
-
131
- img.src = this.__src;
132
- img.alt = this.__altText;
133
-
134
- if (this.__width !== "inherit") {
135
- img.width = this.__width ?? 0;
136
- }
137
-
138
- if (this.__height !== "inherit") {
139
- img.height = this.__height ?? 0;
140
- }
141
-
142
- return { element: img };
143
- }
144
-
145
- static importDOM(): DOMConversionMap | null {
146
- return {
147
- img: () => ({
148
- conversion: convertImageElement,
149
- priority: 1,
150
- }),
151
- };
152
- }
153
-
154
- exportJSON(): SerializedImageNode {
155
- return {
156
- type: "image",
157
- version: 1,
158
- src: this.__src,
159
- altText: this.__altText,
160
- maxWidth: this.__maxWidth,
161
- width: this.__width,
162
- height: this.__height,
163
- };
164
- }
165
-
166
- static importJSON(serializedNode: SerializedImageNode): ImageNode {
167
- return new ImageNode({
168
- src: serializedNode.src,
169
- altText: serializedNode.altText,
170
- maxWidth: serializedNode.maxWidth,
171
- width: serializedNode.width,
172
- height: serializedNode.height,
173
- });
174
- }
175
-
176
- updateDimensions(width: number, height: number) {
177
- const writable = this.getWritable();
178
- writable.__width = width;
179
- writable.__height = height;
180
- }
181
-
182
-
183
- decorate(): JSX.Element {
184
- return (
185
- <ImageComponent
186
- src={this.__src}
187
- altText={this.__altText}
188
- nodeKey={this.getKey()}
189
- width={this.__width}
190
- height={this.__height}
191
- maxWidth={this.__maxWidth}
192
- />
193
- );
194
- }
195
- }