phx-react 1.3.1793 → 1.3.1795
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/dist/cjs/components/Breadcrumb/Breadcrumb.js +1 -1
- package/dist/cjs/components/Breadcrumb/Breadcrumb.js.map +1 -1
- package/dist/cjs/components/TextEditorV2/constants.d.ts +1 -1
- package/dist/cjs/components/TextEditorV2/constants.js +187 -1
- package/dist/cjs/components/TextEditorV2/constants.js.map +1 -1
- package/dist/cjs/components/TextEditorV2/editor.js +4 -1
- package/dist/cjs/components/TextEditorV2/editor.js.map +1 -1
- package/dist/cjs/components/TextEditorV2/nodes/ImageNode.d.ts +99 -3
- package/dist/cjs/components/TextEditorV2/nodes/ImageNode.js +143 -9
- package/dist/cjs/components/TextEditorV2/nodes/ImageNode.js.map +1 -1
- package/dist/cjs/components/TextEditorV2/nodes/InlineImageComponent.d.ts +5 -5
- package/dist/cjs/components/TextEditorV2/nodes/InlineImageComponent.js +66 -66
- package/dist/cjs/components/TextEditorV2/nodes/InlineImageComponent.js.map +1 -1
- package/dist/cjs/components/TextEditorV2/nodes/InlineImageNode.d.ts +90 -1
- package/dist/cjs/components/TextEditorV2/nodes/InlineImageNode.js +128 -5
- package/dist/cjs/components/TextEditorV2/nodes/InlineImageNode.js.map +1 -1
- package/dist/cjs/components/TextEditorV2/nodes/MentionNode.js +2 -0
- package/dist/cjs/components/TextEditorV2/nodes/MentionNode.js.map +1 -1
- package/dist/cjs/components/TextEditorV2/plugins/ImagesPlugin/index.js +1 -0
- package/dist/cjs/components/TextEditorV2/plugins/ImagesPlugin/index.js.map +1 -1
- package/dist/cjs/components/TextEditorV2/plugins/InlineImagePlugin/index.d.ts +9 -0
- package/dist/cjs/components/TextEditorV2/plugins/InlineImagePlugin/index.js +71 -1
- package/dist/cjs/components/TextEditorV2/plugins/InlineImagePlugin/index.js.map +1 -1
- package/dist/cjs/components/TextEditorV2/plugins/PreserveFontSizeOnEnterPlugin/index.d.ts +4 -0
- package/dist/cjs/components/TextEditorV2/plugins/PreserveFontSizeOnEnterPlugin/index.js +37 -0
- package/dist/cjs/components/TextEditorV2/plugins/PreserveFontSizeOnEnterPlugin/index.js.map +1 -1
- package/dist/cjs/components/TextEditorV2/plugins/ToolbarPlugin/components/bullet.js +8 -0
- package/dist/cjs/components/TextEditorV2/plugins/ToolbarPlugin/components/bullet.js.map +1 -1
- package/dist/cjs/components/TextEditorV2/plugins/ToolbarPlugin/components/heading.d.ts +11 -0
- package/dist/cjs/components/TextEditorV2/plugins/ToolbarPlugin/components/heading.js +41 -0
- package/dist/cjs/components/TextEditorV2/plugins/ToolbarPlugin/components/heading.js.map +1 -1
- package/dist/cjs/components/TextEditorV2/plugins/ToolbarPlugin/components/number-bullet.js +8 -0
- package/dist/cjs/components/TextEditorV2/plugins/ToolbarPlugin/components/number-bullet.js.map +1 -1
- package/dist/cjs/components/TextEditorV2/plugins/ToolbarPlugin/components/text-align.d.ts +7 -1
- package/dist/cjs/components/TextEditorV2/plugins/ToolbarPlugin/components/text-align.js +47 -3
- package/dist/cjs/components/TextEditorV2/plugins/ToolbarPlugin/components/text-align.js.map +1 -1
- package/dist/cjs/components/TextEditorV2/plugins/ToolbarPlugin/index.js +42 -12
- package/dist/cjs/components/TextEditorV2/plugins/ToolbarPlugin/index.js.map +1 -1
- package/dist/cjs/components/TextEditorV2/style.js +139 -0
- package/dist/cjs/components/TextEditorV2/style.js.map +1 -1
- package/dist/cjs/components/TextEditorV2/ui/ImageResizer.js +1 -1
- package/dist/cjs/components/TextEditorV2/ui/ImageResizer.js.map +1 -1
- package/dist/esm/components/Breadcrumb/Breadcrumb.js +1 -1
- package/dist/esm/components/Breadcrumb/Breadcrumb.js.map +1 -1
- package/dist/esm/components/TextEditorV2/constants.d.ts +1 -1
- package/dist/esm/components/TextEditorV2/constants.js +187 -1
- package/dist/esm/components/TextEditorV2/constants.js.map +1 -1
- package/dist/esm/components/TextEditorV2/editor.js +4 -1
- package/dist/esm/components/TextEditorV2/editor.js.map +1 -1
- package/dist/esm/components/TextEditorV2/nodes/ImageNode.d.ts +99 -3
- package/dist/esm/components/TextEditorV2/nodes/ImageNode.js +143 -9
- package/dist/esm/components/TextEditorV2/nodes/ImageNode.js.map +1 -1
- package/dist/esm/components/TextEditorV2/nodes/InlineImageComponent.d.ts +5 -5
- package/dist/esm/components/TextEditorV2/nodes/InlineImageComponent.js +66 -65
- package/dist/esm/components/TextEditorV2/nodes/InlineImageComponent.js.map +1 -1
- package/dist/esm/components/TextEditorV2/nodes/InlineImageNode.d.ts +90 -1
- package/dist/esm/components/TextEditorV2/nodes/InlineImageNode.js +128 -5
- package/dist/esm/components/TextEditorV2/nodes/InlineImageNode.js.map +1 -1
- package/dist/esm/components/TextEditorV2/nodes/MentionNode.js +2 -0
- package/dist/esm/components/TextEditorV2/nodes/MentionNode.js.map +1 -1
- package/dist/esm/components/TextEditorV2/plugins/ImagesPlugin/index.js +1 -0
- package/dist/esm/components/TextEditorV2/plugins/ImagesPlugin/index.js.map +1 -1
- package/dist/esm/components/TextEditorV2/plugins/InlineImagePlugin/index.d.ts +9 -0
- package/dist/esm/components/TextEditorV2/plugins/InlineImagePlugin/index.js +71 -1
- package/dist/esm/components/TextEditorV2/plugins/InlineImagePlugin/index.js.map +1 -1
- package/dist/esm/components/TextEditorV2/plugins/PreserveFontSizeOnEnterPlugin/index.d.ts +4 -0
- package/dist/esm/components/TextEditorV2/plugins/PreserveFontSizeOnEnterPlugin/index.js +37 -0
- package/dist/esm/components/TextEditorV2/plugins/PreserveFontSizeOnEnterPlugin/index.js.map +1 -1
- package/dist/esm/components/TextEditorV2/plugins/ToolbarPlugin/components/bullet.js +9 -1
- package/dist/esm/components/TextEditorV2/plugins/ToolbarPlugin/components/bullet.js.map +1 -1
- package/dist/esm/components/TextEditorV2/plugins/ToolbarPlugin/components/heading.d.ts +11 -0
- package/dist/esm/components/TextEditorV2/plugins/ToolbarPlugin/components/heading.js +39 -0
- package/dist/esm/components/TextEditorV2/plugins/ToolbarPlugin/components/heading.js.map +1 -1
- package/dist/esm/components/TextEditorV2/plugins/ToolbarPlugin/components/number-bullet.js +9 -1
- package/dist/esm/components/TextEditorV2/plugins/ToolbarPlugin/components/number-bullet.js.map +1 -1
- package/dist/esm/components/TextEditorV2/plugins/ToolbarPlugin/components/text-align.d.ts +7 -1
- package/dist/esm/components/TextEditorV2/plugins/ToolbarPlugin/components/text-align.js +48 -4
- package/dist/esm/components/TextEditorV2/plugins/ToolbarPlugin/components/text-align.js.map +1 -1
- package/dist/esm/components/TextEditorV2/plugins/ToolbarPlugin/index.js +43 -13
- package/dist/esm/components/TextEditorV2/plugins/ToolbarPlugin/index.js.map +1 -1
- package/dist/esm/components/TextEditorV2/style.js +139 -0
- package/dist/esm/components/TextEditorV2/style.js.map +1 -1
- package/dist/esm/components/TextEditorV2/ui/ImageResizer.js +1 -1
- package/dist/esm/components/TextEditorV2/ui/ImageResizer.js.map +1 -1
- package/package.json +1 -1
|
@@ -11,6 +11,7 @@ import * as React from 'react';
|
|
|
11
11
|
export interface ImagePayload {
|
|
12
12
|
altText: string;
|
|
13
13
|
caption?: LexicalEditor;
|
|
14
|
+
position?: ImagePosition;
|
|
14
15
|
height?: number;
|
|
15
16
|
key?: NodeKey;
|
|
16
17
|
maxWidth?: number;
|
|
@@ -19,11 +20,13 @@ export interface ImagePayload {
|
|
|
19
20
|
width?: number;
|
|
20
21
|
captionsEnabled?: boolean;
|
|
21
22
|
}
|
|
23
|
+
export type ImagePosition = 'left' | 'right' | 'center' | undefined;
|
|
22
24
|
export type SerializedImageNode = Spread<{
|
|
23
25
|
altText: string;
|
|
24
26
|
caption: SerializedEditor;
|
|
25
27
|
height?: number;
|
|
26
28
|
maxWidth: number;
|
|
29
|
+
position?: ImagePosition;
|
|
27
30
|
showCaption: boolean;
|
|
28
31
|
src: string;
|
|
29
32
|
width?: number;
|
|
@@ -36,21 +39,114 @@ export declare class ImageNode extends DecoratorNode<React.JSX.Element> {
|
|
|
36
39
|
__maxWidth: number;
|
|
37
40
|
__showCaption: boolean;
|
|
38
41
|
__caption: LexicalEditor;
|
|
42
|
+
__position: ImagePosition;
|
|
39
43
|
__captionsEnabled: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Gets the Lexical node type for image nodes.
|
|
46
|
+
* @returns Image node type.
|
|
47
|
+
*/
|
|
40
48
|
static getType(): string;
|
|
49
|
+
/**
|
|
50
|
+
* Clones an existing image node.
|
|
51
|
+
* @param node Image node to clone.
|
|
52
|
+
* @returns Cloned image node.
|
|
53
|
+
*/
|
|
41
54
|
static clone(node: ImageNode): ImageNode;
|
|
55
|
+
/**
|
|
56
|
+
* Imports a serialized image node into the editor state.
|
|
57
|
+
* @param serializedNode Serialized image node payload.
|
|
58
|
+
* @returns Hydrated image node.
|
|
59
|
+
*/
|
|
42
60
|
static importJSON(serializedNode: SerializedImageNode): ImageNode;
|
|
61
|
+
/**
|
|
62
|
+
* Exports this image node to DOM.
|
|
63
|
+
* @returns DOM export output containing the image wrapper.
|
|
64
|
+
*/
|
|
43
65
|
exportDOM(): DOMExportOutput;
|
|
66
|
+
/**
|
|
67
|
+
* Defines DOM import conversions for image elements.
|
|
68
|
+
* @returns DOM conversion map for image imports.
|
|
69
|
+
*/
|
|
44
70
|
static importDOM(): DOMConversionMap | null;
|
|
45
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Creates an image node instance.
|
|
73
|
+
* @param src Image source URL.
|
|
74
|
+
* @param altText Accessible alt text.
|
|
75
|
+
* @param maxWidth Maximum rendered image width.
|
|
76
|
+
* @param width Initial image width.
|
|
77
|
+
* @param height Initial image height.
|
|
78
|
+
* @param showCaption Whether the caption editor is visible.
|
|
79
|
+
* @param caption Nested caption editor.
|
|
80
|
+
* @param position Image alignment position.
|
|
81
|
+
* @param captionsEnabled Whether captions are enabled.
|
|
82
|
+
* @param key Optional Lexical node key.
|
|
83
|
+
*/
|
|
84
|
+
constructor(src: string, altText: string, maxWidth: number, width?: 'inherit' | number, height?: 'inherit' | number, showCaption?: boolean, caption?: LexicalEditor, position?: ImagePosition, captionsEnabled?: boolean, key?: NodeKey);
|
|
85
|
+
/**
|
|
86
|
+
* Serializes this image node.
|
|
87
|
+
* @returns Serialized image node payload.
|
|
88
|
+
*/
|
|
46
89
|
exportJSON(): SerializedImageNode;
|
|
90
|
+
/**
|
|
91
|
+
* Updates the stored image dimensions.
|
|
92
|
+
* @param width Next image width.
|
|
93
|
+
* @param height Next image height.
|
|
94
|
+
*/
|
|
47
95
|
setWidthAndHeight(width: 'inherit' | number, height: 'inherit' | number): void;
|
|
96
|
+
/**
|
|
97
|
+
* Updates caption visibility for this image.
|
|
98
|
+
* @param showCaption Whether the caption should be shown.
|
|
99
|
+
*/
|
|
48
100
|
setShowCaption(showCaption: boolean): void;
|
|
101
|
+
/**
|
|
102
|
+
* Gets the current image alignment position.
|
|
103
|
+
* @returns Current image position.
|
|
104
|
+
*/
|
|
105
|
+
getPosition(): ImagePosition;
|
|
106
|
+
/**
|
|
107
|
+
* Updates the image alignment position.
|
|
108
|
+
* @param position Next image position.
|
|
109
|
+
*/
|
|
110
|
+
setPosition(position: ImagePosition): void;
|
|
111
|
+
/**
|
|
112
|
+
* Creates the DOM wrapper for this image node.
|
|
113
|
+
* @param config Lexical editor config.
|
|
114
|
+
* @returns Image wrapper element.
|
|
115
|
+
*/
|
|
49
116
|
createDOM(config: EditorConfig): HTMLElement;
|
|
50
|
-
|
|
117
|
+
/**
|
|
118
|
+
* Updates the DOM wrapper when node state changes.
|
|
119
|
+
* @param prevNode Previous image node state.
|
|
120
|
+
* @param dom Existing image wrapper element.
|
|
121
|
+
* @param config Lexical editor config.
|
|
122
|
+
* @returns False because the existing DOM element is reused.
|
|
123
|
+
*/
|
|
124
|
+
updateDOM(prevNode: ImageNode, dom: HTMLElement, config: EditorConfig): false;
|
|
125
|
+
/**
|
|
126
|
+
* Gets the image source URL.
|
|
127
|
+
* @returns Image source URL.
|
|
128
|
+
*/
|
|
51
129
|
getSrc(): string;
|
|
130
|
+
/**
|
|
131
|
+
* Gets the image alt text.
|
|
132
|
+
* @returns Image alt text.
|
|
133
|
+
*/
|
|
52
134
|
getAltText(): string;
|
|
135
|
+
/**
|
|
136
|
+
* Renders the React decorator for this image node.
|
|
137
|
+
* @returns Image decorator element.
|
|
138
|
+
*/
|
|
53
139
|
decorate(): React.JSX.Element;
|
|
54
140
|
}
|
|
55
|
-
|
|
141
|
+
/**
|
|
142
|
+
* Creates and inserts a replacement image node.
|
|
143
|
+
* @param payload Image node creation payload.
|
|
144
|
+
* @returns Created image node.
|
|
145
|
+
*/
|
|
146
|
+
export declare function $createImageNode({ altText, caption, captionsEnabled, height, key, maxWidth, position, showCaption, src, width, }: ImagePayload): ImageNode;
|
|
147
|
+
/**
|
|
148
|
+
* Checks whether a Lexical node is an ImageNode.
|
|
149
|
+
* @param node Node to test.
|
|
150
|
+
* @returns True when the node is an ImageNode.
|
|
151
|
+
*/
|
|
56
152
|
export declare function $isImageNode(node: LexicalNode | null | undefined): node is ImageNode;
|
|
@@ -11,27 +11,66 @@ import { Suspense } from 'react';
|
|
|
11
11
|
const ImageComponent = React.lazy(
|
|
12
12
|
// @ts-ignore
|
|
13
13
|
() => import('./ImageComponent'));
|
|
14
|
+
/**
|
|
15
|
+
* Gets the image alignment position encoded in a wrapper class name.
|
|
16
|
+
* @param className Wrapper class name to inspect.
|
|
17
|
+
* @returns Matching image position, or undefined when no position class exists.
|
|
18
|
+
*/
|
|
19
|
+
function getPositionFromClassName(className) {
|
|
20
|
+
if (className.includes('position-left')) {
|
|
21
|
+
return 'left';
|
|
22
|
+
}
|
|
23
|
+
if (className.includes('position-right')) {
|
|
24
|
+
return 'right';
|
|
25
|
+
}
|
|
26
|
+
if (className.includes('position-center')) {
|
|
27
|
+
return 'center';
|
|
28
|
+
}
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Converts an imported DOM image element into an ImageNode.
|
|
33
|
+
* @param domNode DOM node provided by Lexical import.
|
|
34
|
+
* @returns DOM conversion output for image nodes, or null for unsupported nodes.
|
|
35
|
+
*/
|
|
14
36
|
function convertImageElement(domNode) {
|
|
37
|
+
var _a;
|
|
15
38
|
if (domNode instanceof HTMLImageElement) {
|
|
16
39
|
const { alt: altText, height, src, width } = domNode;
|
|
17
|
-
const
|
|
40
|
+
const position = getPositionFromClassName(((_a = domNode.parentElement) === null || _a === void 0 ? void 0 : _a.className) || '');
|
|
41
|
+
const node = $createImageNode({ altText, height, position, src, width });
|
|
18
42
|
return { node };
|
|
19
43
|
}
|
|
20
44
|
return null;
|
|
21
45
|
}
|
|
22
46
|
export class ImageNode extends DecoratorNode {
|
|
47
|
+
/**
|
|
48
|
+
* Gets the Lexical node type for image nodes.
|
|
49
|
+
* @returns Image node type.
|
|
50
|
+
*/
|
|
23
51
|
static getType() {
|
|
24
52
|
return 'image';
|
|
25
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Clones an existing image node.
|
|
56
|
+
* @param node Image node to clone.
|
|
57
|
+
* @returns Cloned image node.
|
|
58
|
+
*/
|
|
26
59
|
static clone(node) {
|
|
27
|
-
return new ImageNode(node.__src, node.__altText, node.__maxWidth, node.__width, node.__height, node.__showCaption, node.__caption, node.__captionsEnabled, node.__key);
|
|
60
|
+
return new ImageNode(node.__src, node.__altText, node.__maxWidth, node.__width, node.__height, node.__showCaption, node.__caption, node.__position, node.__captionsEnabled, node.__key);
|
|
28
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Imports a serialized image node into the editor state.
|
|
64
|
+
* @param serializedNode Serialized image node payload.
|
|
65
|
+
* @returns Hydrated image node.
|
|
66
|
+
*/
|
|
29
67
|
static importJSON(serializedNode) {
|
|
30
|
-
const { altText, caption, height, maxWidth, showCaption, src, width } = serializedNode;
|
|
68
|
+
const { altText, caption, height, maxWidth, position, showCaption, src, width } = serializedNode;
|
|
31
69
|
const node = $createImageNode({
|
|
32
70
|
altText,
|
|
33
71
|
height,
|
|
34
72
|
maxWidth,
|
|
73
|
+
position,
|
|
35
74
|
showCaption,
|
|
36
75
|
src,
|
|
37
76
|
width,
|
|
@@ -43,14 +82,25 @@ export class ImageNode extends DecoratorNode {
|
|
|
43
82
|
}
|
|
44
83
|
return node;
|
|
45
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Exports this image node to DOM.
|
|
87
|
+
* @returns DOM export output containing the image wrapper.
|
|
88
|
+
*/
|
|
46
89
|
exportDOM() {
|
|
90
|
+
const wrapper = document.createElement('span');
|
|
91
|
+
wrapper.className = `editor-image position-${this.__position || 'center'}`;
|
|
47
92
|
const element = document.createElement('img');
|
|
48
93
|
element.setAttribute('src', this.__src);
|
|
49
94
|
element.setAttribute('alt', this.__altText);
|
|
50
95
|
element.setAttribute('width', this.__width.toString());
|
|
51
96
|
element.setAttribute('height', this.__height.toString());
|
|
52
|
-
|
|
97
|
+
wrapper.appendChild(element);
|
|
98
|
+
return { element: wrapper };
|
|
53
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Defines DOM import conversions for image elements.
|
|
102
|
+
* @returns DOM conversion map for image imports.
|
|
103
|
+
*/
|
|
54
104
|
static importDOM() {
|
|
55
105
|
return {
|
|
56
106
|
img: () => ({
|
|
@@ -59,7 +109,20 @@ export class ImageNode extends DecoratorNode {
|
|
|
59
109
|
}),
|
|
60
110
|
};
|
|
61
111
|
}
|
|
62
|
-
|
|
112
|
+
/**
|
|
113
|
+
* Creates an image node instance.
|
|
114
|
+
* @param src Image source URL.
|
|
115
|
+
* @param altText Accessible alt text.
|
|
116
|
+
* @param maxWidth Maximum rendered image width.
|
|
117
|
+
* @param width Initial image width.
|
|
118
|
+
* @param height Initial image height.
|
|
119
|
+
* @param showCaption Whether the caption editor is visible.
|
|
120
|
+
* @param caption Nested caption editor.
|
|
121
|
+
* @param position Image alignment position.
|
|
122
|
+
* @param captionsEnabled Whether captions are enabled.
|
|
123
|
+
* @param key Optional Lexical node key.
|
|
124
|
+
*/
|
|
125
|
+
constructor(src, altText, maxWidth, width, height, showCaption, caption, position, captionsEnabled, key) {
|
|
63
126
|
super(key);
|
|
64
127
|
this.__src = src;
|
|
65
128
|
this.__altText = altText;
|
|
@@ -68,14 +131,20 @@ export class ImageNode extends DecoratorNode {
|
|
|
68
131
|
this.__height = height || 'inherit';
|
|
69
132
|
this.__showCaption = showCaption || false;
|
|
70
133
|
this.__caption = caption || createEditor();
|
|
134
|
+
this.__position = position || 'center';
|
|
71
135
|
this.__captionsEnabled = captionsEnabled || captionsEnabled === undefined;
|
|
72
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Serializes this image node.
|
|
139
|
+
* @returns Serialized image node payload.
|
|
140
|
+
*/
|
|
73
141
|
exportJSON() {
|
|
74
142
|
return {
|
|
75
143
|
altText: this.getAltText(),
|
|
76
144
|
caption: this.__caption.toJSON(),
|
|
77
145
|
height: this.__height === 'inherit' ? 0 : this.__height,
|
|
78
146
|
maxWidth: this.__maxWidth,
|
|
147
|
+
position: this.__position,
|
|
79
148
|
showCaption: this.__showCaption,
|
|
80
149
|
src: this.getSrc(),
|
|
81
150
|
type: 'image',
|
|
@@ -83,42 +152,107 @@ export class ImageNode extends DecoratorNode {
|
|
|
83
152
|
width: this.__width === 'inherit' ? 0 : this.__width,
|
|
84
153
|
};
|
|
85
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Updates the stored image dimensions.
|
|
157
|
+
* @param width Next image width.
|
|
158
|
+
* @param height Next image height.
|
|
159
|
+
*/
|
|
86
160
|
setWidthAndHeight(width, height) {
|
|
87
161
|
const writable = this.getWritable();
|
|
88
162
|
writable.__width = width;
|
|
89
163
|
writable.__height = height;
|
|
90
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* Updates caption visibility for this image.
|
|
167
|
+
* @param showCaption Whether the caption should be shown.
|
|
168
|
+
*/
|
|
91
169
|
setShowCaption(showCaption) {
|
|
92
170
|
const writable = this.getWritable();
|
|
93
171
|
writable.__showCaption = showCaption;
|
|
94
172
|
}
|
|
173
|
+
/**
|
|
174
|
+
* Gets the current image alignment position.
|
|
175
|
+
* @returns Current image position.
|
|
176
|
+
*/
|
|
177
|
+
getPosition() {
|
|
178
|
+
return this.__position;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Updates the image alignment position.
|
|
182
|
+
* @param position Next image position.
|
|
183
|
+
*/
|
|
184
|
+
setPosition(position) {
|
|
185
|
+
const writable = this.getWritable();
|
|
186
|
+
writable.__position = position || 'center';
|
|
187
|
+
}
|
|
95
188
|
// View
|
|
189
|
+
/**
|
|
190
|
+
* Creates the DOM wrapper for this image node.
|
|
191
|
+
* @param config Lexical editor config.
|
|
192
|
+
* @returns Image wrapper element.
|
|
193
|
+
*/
|
|
96
194
|
createDOM(config) {
|
|
97
195
|
const span = document.createElement('span');
|
|
98
196
|
const theme = config.theme;
|
|
99
|
-
const className = theme.image
|
|
197
|
+
const className = `${theme.image} position-${this.__position || 'center'}`;
|
|
100
198
|
if (className !== undefined) {
|
|
101
199
|
span.className = className;
|
|
102
200
|
}
|
|
103
201
|
return span;
|
|
104
202
|
}
|
|
105
|
-
|
|
203
|
+
/**
|
|
204
|
+
* Updates the DOM wrapper when node state changes.
|
|
205
|
+
* @param prevNode Previous image node state.
|
|
206
|
+
* @param dom Existing image wrapper element.
|
|
207
|
+
* @param config Lexical editor config.
|
|
208
|
+
* @returns False because the existing DOM element is reused.
|
|
209
|
+
*/
|
|
210
|
+
updateDOM(prevNode, dom, config) {
|
|
211
|
+
const position = this.__position;
|
|
212
|
+
if (position !== prevNode.__position) {
|
|
213
|
+
const className = `${config.theme.image} position-${position || 'center'}`;
|
|
214
|
+
if (className !== undefined) {
|
|
215
|
+
dom.className = className;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
106
218
|
return false;
|
|
107
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* Gets the image source URL.
|
|
222
|
+
* @returns Image source URL.
|
|
223
|
+
*/
|
|
108
224
|
getSrc() {
|
|
109
225
|
return this.__src;
|
|
110
226
|
}
|
|
227
|
+
/**
|
|
228
|
+
* Gets the image alt text.
|
|
229
|
+
* @returns Image alt text.
|
|
230
|
+
*/
|
|
111
231
|
getAltText() {
|
|
112
232
|
return this.__altText;
|
|
113
233
|
}
|
|
234
|
+
/**
|
|
235
|
+
* Renders the React decorator for this image node.
|
|
236
|
+
* @returns Image decorator element.
|
|
237
|
+
*/
|
|
114
238
|
decorate() {
|
|
115
239
|
return (React.createElement(Suspense, { fallback: null },
|
|
116
240
|
React.createElement(ImageComponent, { altText: this.__altText, caption: this.__caption, height: this.__height, maxWidth: this.__maxWidth, nodeKey: this.getKey(), resizable: true, showCaption: this.__showCaption, src: this.__src, width: this.__width })));
|
|
117
241
|
}
|
|
118
242
|
}
|
|
119
|
-
|
|
120
|
-
|
|
243
|
+
/**
|
|
244
|
+
* Creates and inserts a replacement image node.
|
|
245
|
+
* @param payload Image node creation payload.
|
|
246
|
+
* @returns Created image node.
|
|
247
|
+
*/
|
|
248
|
+
export function $createImageNode({ altText, caption, captionsEnabled, height, key, maxWidth = 500, position, showCaption, src, width, }) {
|
|
249
|
+
return $applyNodeReplacement(new ImageNode(src, altText, maxWidth, width, height, showCaption, caption, position || 'center', captionsEnabled, key));
|
|
121
250
|
}
|
|
251
|
+
/**
|
|
252
|
+
* Checks whether a Lexical node is an ImageNode.
|
|
253
|
+
* @param node Node to test.
|
|
254
|
+
* @returns True when the node is an ImageNode.
|
|
255
|
+
*/
|
|
122
256
|
export function $isImageNode(node) {
|
|
123
257
|
return node instanceof ImageNode;
|
|
124
258
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImageNode.js","sourceRoot":"","sources":["../../../../../src/components/TextEditorV2/nodes/ImageNode.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAcH,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC5E,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAA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AED;;;OAGG;IACI,QAAQ;QACb,OAAO,CACL,oBAAC,QAAQ,IAAC,QAAQ,EAAE,IAAI;YACtB,oBAAC,cAAc,IACb,OAAO,EAAE,IAAI,CAAC,SAAS,EACvB,OAAO,EAAE,IAAI,CAAC,SAAS,EACvB,MAAM,EAAE,IAAI,CAAC,QAAQ,EACrB,QAAQ,EAAE,IAAI,CAAC,UAAU,EACzB,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,EACtB,SAAS,QACT,WAAW,EAAE,IAAI,CAAC,aAAa,EAC/B,GAAG,EAAE,IAAI,CAAC,KAAK,EACf,KAAK,EAAE,IAAI,CAAC,OAAO,GACnB,CACO,CACZ,CAAA;IACH,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,EAC/B,OAAO,EACP,OAAO,EACP,eAAe,EACf,MAAM,EACN,GAAG,EACH,QAAQ,GAAG,GAAG,EACd,QAAQ,EACR,WAAW,EACX,GAAG,EACH,KAAK,GACQ;IACb,OAAO,qBAAqB,CAC1B,IAAI,SAAS,CACX,GAAG,EACH,OAAO,EACP,QAAQ,EACR,KAAK,EACL,MAAM,EACN,WAAW,EACX,OAAO,EACP,QAAQ,IAAI,QAAQ,EACpB,eAAe,EACf,GAAG,CACJ,CACF,CAAA;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,IAAoC;IAC/D,OAAO,IAAI,YAAY,SAAS,CAAA;AAClC,CAAC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { Position } from './InlineImageNode';
|
|
2
2
|
import type { LexicalEditor, NodeKey } from 'lexical';
|
|
3
3
|
import * as React from 'react';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Renders an inline image node with selection, resize, and caption behavior.
|
|
6
|
+
* @param props Inline image component props.
|
|
7
|
+
* @returns Inline image decorator element.
|
|
8
|
+
*/
|
|
9
9
|
export default function InlineImageComponent({ altText, caption, height, nodeKey, position, showCaption, src, width, }: {
|
|
10
10
|
altText: string;
|
|
11
11
|
caption: LexicalEditor;
|
|
@@ -7,19 +7,19 @@ import { mergeRegister } from '@lexical/utils';
|
|
|
7
7
|
import { $getNodeByKey, $getSelection, $isNodeSelection, $setSelection, CLICK_COMMAND, COMMAND_PRIORITY_LOW, DRAGSTART_COMMAND, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, KEY_ENTER_COMMAND, KEY_ESCAPE_COMMAND, SELECTION_CHANGE_COMMAND, } from 'lexical';
|
|
8
8
|
import * as React from 'react';
|
|
9
9
|
import { Suspense, useCallback, useEffect, useRef, useState } from 'react';
|
|
10
|
-
import useModal from '../hooks/useModal';
|
|
11
10
|
import FloatingLinkEditorPlugin from '../plugins/FloatingLinkEditorPlugin';
|
|
12
11
|
import FloatingTextFormatToolbarPlugin from '../plugins/FloatingTextFormatToolbarPlugin';
|
|
13
12
|
import LinkPlugin from '../plugins/LinkPlugin';
|
|
14
|
-
import Button from '../ui/Button';
|
|
15
13
|
import ContentEditable from '../ui/ContentEditable';
|
|
16
|
-
import
|
|
14
|
+
import ImageResizer from '../ui/ImageResizer';
|
|
17
15
|
import Placeholder from '../ui/Placeholder';
|
|
18
|
-
import Select from '../ui/Select';
|
|
19
|
-
import TextInput from '../ui/TextInput';
|
|
20
16
|
import { $isInlineImageNode } from './InlineImageNode';
|
|
21
17
|
import { LexicalErrorBoundary } from '../shared/LexicalErrorBoundary';
|
|
22
18
|
const imageCache = new Set();
|
|
19
|
+
/**
|
|
20
|
+
* Suspends rendering until an image source has loaded.
|
|
21
|
+
* @param src Image source URL to preload.
|
|
22
|
+
*/
|
|
23
23
|
function useSuspenseImage(src) {
|
|
24
24
|
if (!imageCache.has(src)) {
|
|
25
25
|
throw new Promise((resolve) => {
|
|
@@ -32,6 +32,11 @@ function useSuspenseImage(src) {
|
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Renders an image after ensuring its source is loaded.
|
|
37
|
+
* @param props Lazy image render props.
|
|
38
|
+
* @returns Rendered image element.
|
|
39
|
+
*/
|
|
35
40
|
function LazyImage({ altText, className, height, imageRef, position, src, width, }) {
|
|
36
41
|
useSuspenseImage(src);
|
|
37
42
|
return (React.createElement("img", { ref: imageRef, alt: altText, className: className || undefined, "data-position": position, draggable: 'false', src: src, style: {
|
|
@@ -40,48 +45,23 @@ function LazyImage({ altText, className, height, imageRef, position, src, width,
|
|
|
40
45
|
width,
|
|
41
46
|
} }));
|
|
42
47
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const [position, setPosition] = useState(node.getPosition());
|
|
49
|
-
const handleShowCaptionChange = (e) => {
|
|
50
|
-
setShowCaption(e.target.checked);
|
|
51
|
-
};
|
|
52
|
-
const handlePositionChange = (e) => {
|
|
53
|
-
setPosition(e.target.value);
|
|
54
|
-
};
|
|
55
|
-
const handleOnConfirm = () => {
|
|
56
|
-
const payload = { altText, position, showCaption };
|
|
57
|
-
if (node) {
|
|
58
|
-
activeEditor.update(() => {
|
|
59
|
-
node.update(payload);
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
onClose();
|
|
63
|
-
};
|
|
64
|
-
return (React.createElement(React.Fragment, null,
|
|
65
|
-
React.createElement("div", { style: { marginBottom: '1em' } },
|
|
66
|
-
React.createElement(TextInput, { "data-test-id": 'image-modal-alt-text-input', label: 'Alt Text', onChange: setAltText, placeholder: 'Descriptive alternative text', value: altText })),
|
|
67
|
-
React.createElement(Select, { id: 'position-select', label: 'Position', name: 'position', onChange: handlePositionChange, style: { marginBottom: '1em', width: '208px' }, value: position },
|
|
68
|
-
React.createElement("option", { value: 'left' }, "Left"),
|
|
69
|
-
React.createElement("option", { value: 'right' }, "Right"),
|
|
70
|
-
React.createElement("option", { value: 'full' }, "Full Width")),
|
|
71
|
-
React.createElement("div", { className: 'Input__wrapper' },
|
|
72
|
-
React.createElement("input", { checked: showCaption, id: 'caption', onChange: handleShowCaptionChange, type: 'checkbox' }),
|
|
73
|
-
React.createElement("label", { htmlFor: 'caption' }, "Show Caption")),
|
|
74
|
-
React.createElement(DialogActions, null,
|
|
75
|
-
React.createElement(Button, { "data-test-id": 'image-modal-file-upload-btn', onClick: () => handleOnConfirm() }, "Confirm"))));
|
|
76
|
-
}
|
|
48
|
+
/**
|
|
49
|
+
* Renders an inline image node with selection, resize, and caption behavior.
|
|
50
|
+
* @param props Inline image component props.
|
|
51
|
+
* @returns Inline image decorator element.
|
|
52
|
+
*/
|
|
77
53
|
export default function InlineImageComponent({ altText, caption, height, nodeKey, position, showCaption, src, width, }) {
|
|
78
|
-
const [modal, showModal] = useModal();
|
|
79
54
|
const imageRef = useRef(null);
|
|
80
|
-
const buttonRef = useRef(null);
|
|
81
55
|
const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection(nodeKey);
|
|
56
|
+
const [isResizing, setIsResizing] = useState(false);
|
|
82
57
|
const [editor] = useLexicalComposerContext();
|
|
83
58
|
const [selection, setSelection] = useState(null);
|
|
84
59
|
const activeEditorRef = useRef(null);
|
|
60
|
+
/**
|
|
61
|
+
* Removes the selected inline image when delete or backspace is pressed.
|
|
62
|
+
* @param payload Keyboard event from the editor command.
|
|
63
|
+
* @returns False to allow other command handlers to continue.
|
|
64
|
+
*/
|
|
85
65
|
const onDelete = useCallback((payload) => {
|
|
86
66
|
if (isSelected && $isNodeSelection($getSelection())) {
|
|
87
67
|
const event = payload;
|
|
@@ -93,27 +73,28 @@ export default function InlineImageComponent({ altText, caption, height, nodeKey
|
|
|
93
73
|
}
|
|
94
74
|
return false;
|
|
95
75
|
}, [isSelected, nodeKey]);
|
|
76
|
+
/**
|
|
77
|
+
* Moves focus into the caption editor when enter is pressed on a selected image.
|
|
78
|
+
* @param event Keyboard event from the editor command.
|
|
79
|
+
* @returns True when focus moved into the caption editor.
|
|
80
|
+
*/
|
|
96
81
|
const onEnter = useCallback((event) => {
|
|
97
82
|
const latestSelection = $getSelection();
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
caption.focus();
|
|
105
|
-
return true;
|
|
106
|
-
}
|
|
107
|
-
else if (buttonElem !== null && buttonElem !== document.activeElement) {
|
|
108
|
-
event.preventDefault();
|
|
109
|
-
buttonElem.focus();
|
|
110
|
-
return true;
|
|
111
|
-
}
|
|
83
|
+
if (isSelected && showCaption && $isNodeSelection(latestSelection) && latestSelection.getNodes().length === 1) {
|
|
84
|
+
// Move focus into nested editor
|
|
85
|
+
$setSelection(null);
|
|
86
|
+
event.preventDefault();
|
|
87
|
+
caption.focus();
|
|
88
|
+
return true;
|
|
112
89
|
}
|
|
113
90
|
return false;
|
|
114
91
|
}, [caption, isSelected, showCaption]);
|
|
115
|
-
|
|
116
|
-
|
|
92
|
+
/**
|
|
93
|
+
* Restores focus from the caption editor back to the inline image node.
|
|
94
|
+
* @returns True when focus was restored to the parent editor.
|
|
95
|
+
*/
|
|
96
|
+
const onEscape = useCallback(() => {
|
|
97
|
+
if (activeEditorRef.current === caption) {
|
|
117
98
|
$setSelection(null);
|
|
118
99
|
editor.update(() => {
|
|
119
100
|
setSelected(true);
|
|
@@ -137,6 +118,9 @@ export default function InlineImageComponent({ altText, caption, height, nodeKey
|
|
|
137
118
|
return false;
|
|
138
119
|
}, COMMAND_PRIORITY_LOW), editor.registerCommand(CLICK_COMMAND, (payload) => {
|
|
139
120
|
const event = payload;
|
|
121
|
+
if (isResizing) {
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
140
124
|
if (event.target === imageRef.current) {
|
|
141
125
|
if (event.shiftKey) {
|
|
142
126
|
setSelected(!isSelected);
|
|
@@ -161,15 +145,32 @@ export default function InlineImageComponent({ altText, caption, height, nodeKey
|
|
|
161
145
|
isMounted = false;
|
|
162
146
|
unregister();
|
|
163
147
|
};
|
|
164
|
-
}, [clearSelection, editor, isSelected, nodeKey, onDelete, onEnter, onEscape, setSelected]);
|
|
165
|
-
|
|
166
|
-
|
|
148
|
+
}, [clearSelection, editor, isResizing, isSelected, nodeKey, onDelete, onEnter, onEscape, setSelected]);
|
|
149
|
+
/**
|
|
150
|
+
* Persists resized image dimensions back to the Lexical node.
|
|
151
|
+
* @param nextWidth Next image width.
|
|
152
|
+
* @param nextHeight Next image height.
|
|
153
|
+
*/
|
|
154
|
+
const onResizeEnd = (nextWidth, nextHeight) => {
|
|
155
|
+
editor.update(() => {
|
|
156
|
+
const node = $getNodeByKey(nodeKey);
|
|
157
|
+
if ($isInlineImageNode(node)) {
|
|
158
|
+
node.setWidthAndHeight(nextWidth, nextHeight);
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
setIsResizing(false);
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Marks the image as actively resizing.
|
|
165
|
+
*/
|
|
166
|
+
const onResizeStart = () => {
|
|
167
|
+
setIsResizing(true);
|
|
168
|
+
};
|
|
169
|
+
const draggable = isSelected && $isNodeSelection(selection) && !isResizing;
|
|
170
|
+
const isFocused = isSelected || isResizing;
|
|
167
171
|
return (React.createElement(Suspense, { fallback: null },
|
|
168
172
|
React.createElement(React.Fragment, null,
|
|
169
173
|
React.createElement("div", { draggable: draggable },
|
|
170
|
-
React.createElement("button", { ref: buttonRef, className: 'image-edit-button', onClick: () => {
|
|
171
|
-
showModal('Update Inline Image', (onClose) => (React.createElement(UpdateInlineImageDialog, { activeEditor: editor, nodeKey: nodeKey, onClose: onClose })));
|
|
172
|
-
}, type: 'button' }, "Edit"),
|
|
173
174
|
React.createElement(LazyImage, { altText: altText, className: isFocused ? `focused ${$isNodeSelection(selection) ? 'draggable' : ''}` : null, height: height, imageRef: imageRef, position: position, src: src, width: width })),
|
|
174
175
|
showCaption && (React.createElement("div", { className: 'image-caption-container' },
|
|
175
176
|
React.createElement(LexicalNestedComposer, { initialEditor: caption },
|
|
@@ -179,7 +180,7 @@ export default function InlineImageComponent({ altText, caption, height, nodeKey
|
|
|
179
180
|
console.log('FloatingLinkEditorPlugin');
|
|
180
181
|
} }),
|
|
181
182
|
React.createElement(FloatingTextFormatToolbarPlugin, null),
|
|
182
|
-
React.createElement(RichTextPlugin, { contentEditable: React.createElement(ContentEditable, { className: 'InlineImageNode__contentEditable' }), ErrorBoundary: LexicalErrorBoundary, placeholder: React.createElement(Placeholder, { className: 'InlineImageNode__placeholder' }, "Enter a caption...") }))))
|
|
183
|
-
|
|
183
|
+
React.createElement(RichTextPlugin, { contentEditable: React.createElement(ContentEditable, { className: 'InlineImageNode__contentEditable' }), ErrorBoundary: LexicalErrorBoundary, placeholder: React.createElement(Placeholder, { className: 'InlineImageNode__placeholder' }, "Enter a caption...") })))),
|
|
184
|
+
$isNodeSelection(selection) && isFocused && (React.createElement(ImageResizer, { editor: editor, imageRef: imageRef, onResizeEnd: onResizeEnd, onResizeStart: onResizeStart })))));
|
|
184
185
|
}
|
|
185
186
|
//# sourceMappingURL=InlineImageComponent.js.map
|