phx-react 1.3.1792 → 1.3.1794
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/TableV6/TableV6.d.ts +2 -1
- package/dist/cjs/components/TableV6/TableV6.js +13 -5
- package/dist/cjs/components/TableV6/TableV6.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/TableV6/TableV6.d.ts +2 -1
- package/dist/esm/components/TableV6/TableV6.js +13 -5
- package/dist/esm/components/TableV6/TableV6.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
|
@@ -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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InlineImageComponent.js","sourceRoot":"","sources":["../../../../../src/components/TextEditorV2/nodes/InlineImageComponent.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAA;AACvE,OAAO,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAA;AACjF,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAA;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAA;AACrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAA;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EACL,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,wBAAwB,GACzB,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC1E,OAAO,
|
|
1
|
+
{"version":3,"file":"InlineImageComponent.js","sourceRoot":"","sources":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,EAAC,8BAA8B,yBAAiC,GACnG,CACoB,CACpB,CACP;YACA,gBAAgB,CAAC,SAAS,CAAC,IAAI,SAAS,IAAI,CAC3C,oBAAC,YAAY,IAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,GAAI,CAC7G,CACA,CACM,CACZ,CAAA;AACH,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { DOMConversionMap, DOMExportOutput, EditorConfig, LexicalEditor, LexicalNode, NodeKey, SerializedEditor, SerializedLexicalNode, Spread } from 'lexical';
|
|
2
2
|
import { DecoratorNode } from 'lexical';
|
|
3
3
|
import * as React from 'react';
|
|
4
|
-
export type Position = 'left' | 'right' | 'full' | undefined;
|
|
4
|
+
export type Position = 'left' | 'right' | 'full' | 'center' | undefined;
|
|
5
5
|
export interface InlineImagePayload {
|
|
6
6
|
altText: string;
|
|
7
7
|
caption?: LexicalEditor;
|
|
@@ -34,21 +34,110 @@ export declare class InlineImageNode extends DecoratorNode<React.JSX.Element> {
|
|
|
34
34
|
__showCaption: boolean;
|
|
35
35
|
__caption: LexicalEditor;
|
|
36
36
|
__position: Position;
|
|
37
|
+
/**
|
|
38
|
+
* Gets the Lexical node type for inline image nodes.
|
|
39
|
+
* @returns Inline image node type.
|
|
40
|
+
*/
|
|
37
41
|
static getType(): string;
|
|
42
|
+
/**
|
|
43
|
+
* Clones an existing inline image node.
|
|
44
|
+
* @param node Inline image node to clone.
|
|
45
|
+
* @returns Cloned inline image node.
|
|
46
|
+
*/
|
|
38
47
|
static clone(node: InlineImageNode): InlineImageNode;
|
|
48
|
+
/**
|
|
49
|
+
* Imports a serialized inline image node into the editor state.
|
|
50
|
+
* @param serializedNode Serialized inline image node payload.
|
|
51
|
+
* @returns Hydrated inline image node.
|
|
52
|
+
*/
|
|
39
53
|
static importJSON(serializedNode: SerializedInlineImageNode): InlineImageNode;
|
|
54
|
+
/**
|
|
55
|
+
* Defines DOM import conversions for inline image elements.
|
|
56
|
+
* @returns DOM conversion map for inline image imports.
|
|
57
|
+
*/
|
|
40
58
|
static importDOM(): DOMConversionMap | null;
|
|
59
|
+
/**
|
|
60
|
+
* Creates an inline image node instance.
|
|
61
|
+
* @param src Image source URL.
|
|
62
|
+
* @param altText Accessible alt text.
|
|
63
|
+
* @param position Inline image alignment position.
|
|
64
|
+
* @param width Initial image width.
|
|
65
|
+
* @param height Initial image height.
|
|
66
|
+
* @param showCaption Whether the caption editor is visible.
|
|
67
|
+
* @param caption Nested caption editor.
|
|
68
|
+
* @param key Optional Lexical node key.
|
|
69
|
+
*/
|
|
41
70
|
constructor(src: string, altText: string, position: Position, width?: 'inherit' | number, height?: 'inherit' | number, showCaption?: boolean, caption?: LexicalEditor, key?: NodeKey);
|
|
71
|
+
/**
|
|
72
|
+
* Exports this inline image node to DOM.
|
|
73
|
+
* @returns DOM export output containing the inline image wrapper.
|
|
74
|
+
*/
|
|
42
75
|
exportDOM(): DOMExportOutput;
|
|
76
|
+
/**
|
|
77
|
+
* Serializes this inline image node.
|
|
78
|
+
* @returns Serialized inline image node payload.
|
|
79
|
+
*/
|
|
43
80
|
exportJSON(): SerializedInlineImageNode;
|
|
81
|
+
/**
|
|
82
|
+
* Gets the image source URL.
|
|
83
|
+
* @returns Image source URL.
|
|
84
|
+
*/
|
|
44
85
|
getSrc(): string;
|
|
86
|
+
/**
|
|
87
|
+
* Gets the image alt text.
|
|
88
|
+
* @returns Image alt text.
|
|
89
|
+
*/
|
|
45
90
|
getAltText(): string;
|
|
91
|
+
/**
|
|
92
|
+
* Gets whether the caption editor is visible.
|
|
93
|
+
* @returns True when caption is shown.
|
|
94
|
+
*/
|
|
46
95
|
getShowCaption(): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Gets the current inline image alignment position.
|
|
98
|
+
* @returns Current inline image position.
|
|
99
|
+
*/
|
|
47
100
|
getPosition(): Position;
|
|
101
|
+
/**
|
|
102
|
+
* Updates the stored image dimensions.
|
|
103
|
+
* @param width Next image width.
|
|
104
|
+
* @param height Next image height.
|
|
105
|
+
*/
|
|
106
|
+
setWidthAndHeight(width: 'inherit' | number, height: 'inherit' | number): void;
|
|
107
|
+
/**
|
|
108
|
+
* Updates mutable inline image fields.
|
|
109
|
+
* @param payload Partial inline image update payload.
|
|
110
|
+
*/
|
|
48
111
|
update(payload: UpdateInlineImagePayload): void;
|
|
112
|
+
/**
|
|
113
|
+
* Creates the DOM wrapper for this inline image node.
|
|
114
|
+
* @param config Lexical editor config.
|
|
115
|
+
* @returns Inline image wrapper element.
|
|
116
|
+
*/
|
|
49
117
|
createDOM(config: EditorConfig): HTMLElement;
|
|
118
|
+
/**
|
|
119
|
+
* Updates the DOM wrapper when node state changes.
|
|
120
|
+
* @param prevNode Previous inline image node state.
|
|
121
|
+
* @param dom Existing inline image wrapper element.
|
|
122
|
+
* @param config Lexical editor config.
|
|
123
|
+
* @returns False because the existing DOM element is reused.
|
|
124
|
+
*/
|
|
50
125
|
updateDOM(prevNode: InlineImageNode, dom: HTMLElement, config: EditorConfig): false;
|
|
126
|
+
/**
|
|
127
|
+
* Renders the React decorator for this inline image node.
|
|
128
|
+
* @returns Inline image decorator element.
|
|
129
|
+
*/
|
|
51
130
|
decorate(): React.JSX.Element;
|
|
52
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Creates and inserts a replacement inline image node.
|
|
134
|
+
* @param payload Inline image node creation payload.
|
|
135
|
+
* @returns Created inline image node.
|
|
136
|
+
*/
|
|
53
137
|
export declare function $createInlineImageNode({ altText, caption, height, key, position, showCaption, src, width, }: InlineImagePayload): InlineImageNode;
|
|
138
|
+
/**
|
|
139
|
+
* Checks whether a Lexical node is an InlineImageNode.
|
|
140
|
+
* @param node Node to test.
|
|
141
|
+
* @returns True when the node is an InlineImageNode.
|
|
142
|
+
*/
|
|
54
143
|
export declare function $isInlineImageNode(node: LexicalNode | null | undefined): node is InlineImageNode;
|
|
@@ -2,21 +2,62 @@ import { $applyNodeReplacement, createEditor, DecoratorNode } from 'lexical';
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { Suspense } from 'react';
|
|
4
4
|
const InlineImageComponent = React.lazy(() => import('./InlineImageComponent'));
|
|
5
|
+
/**
|
|
6
|
+
* Gets the inline image position encoded in a wrapper class name.
|
|
7
|
+
* @param className Wrapper class name to inspect.
|
|
8
|
+
* @returns Matching inline image position, or undefined when no position class exists.
|
|
9
|
+
*/
|
|
10
|
+
function getPositionFromClassName(className) {
|
|
11
|
+
if (className.includes('position-left')) {
|
|
12
|
+
return 'left';
|
|
13
|
+
}
|
|
14
|
+
if (className.includes('position-right')) {
|
|
15
|
+
return 'right';
|
|
16
|
+
}
|
|
17
|
+
if (className.includes('position-full')) {
|
|
18
|
+
return 'full';
|
|
19
|
+
}
|
|
20
|
+
if (className.includes('position-center')) {
|
|
21
|
+
return 'center';
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Converts an imported DOM image element into an InlineImageNode.
|
|
27
|
+
* @param domNode DOM node provided by Lexical import.
|
|
28
|
+
* @returns DOM conversion output for inline image nodes, or null for unsupported nodes.
|
|
29
|
+
*/
|
|
5
30
|
function convertInlineImageElement(domNode) {
|
|
31
|
+
var _a;
|
|
6
32
|
if (domNode instanceof HTMLImageElement) {
|
|
7
33
|
const { alt: altText, height, src, width } = domNode;
|
|
8
|
-
const
|
|
34
|
+
const position = getPositionFromClassName(((_a = domNode.parentElement) === null || _a === void 0 ? void 0 : _a.className) || '');
|
|
35
|
+
const node = $createInlineImageNode({ altText, height, position, src, width });
|
|
9
36
|
return { node };
|
|
10
37
|
}
|
|
11
38
|
return null;
|
|
12
39
|
}
|
|
13
40
|
export class InlineImageNode extends DecoratorNode {
|
|
41
|
+
/**
|
|
42
|
+
* Gets the Lexical node type for inline image nodes.
|
|
43
|
+
* @returns Inline image node type.
|
|
44
|
+
*/
|
|
14
45
|
static getType() {
|
|
15
46
|
return 'inline-image';
|
|
16
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Clones an existing inline image node.
|
|
50
|
+
* @param node Inline image node to clone.
|
|
51
|
+
* @returns Cloned inline image node.
|
|
52
|
+
*/
|
|
17
53
|
static clone(node) {
|
|
18
54
|
return new InlineImageNode(node.__src, node.__altText, node.__position, node.__width, node.__height, node.__showCaption, node.__caption, node.__key);
|
|
19
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Imports a serialized inline image node into the editor state.
|
|
58
|
+
* @param serializedNode Serialized inline image node payload.
|
|
59
|
+
* @returns Hydrated inline image node.
|
|
60
|
+
*/
|
|
20
61
|
static importJSON(serializedNode) {
|
|
21
62
|
const { altText, caption, height, position, showCaption, src, width } = serializedNode;
|
|
22
63
|
const node = $createInlineImageNode({
|
|
@@ -34,6 +75,10 @@ export class InlineImageNode extends DecoratorNode {
|
|
|
34
75
|
}
|
|
35
76
|
return node;
|
|
36
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Defines DOM import conversions for inline image elements.
|
|
80
|
+
* @returns DOM conversion map for inline image imports.
|
|
81
|
+
*/
|
|
37
82
|
static importDOM() {
|
|
38
83
|
return {
|
|
39
84
|
img: () => ({
|
|
@@ -42,6 +87,17 @@ export class InlineImageNode extends DecoratorNode {
|
|
|
42
87
|
}),
|
|
43
88
|
};
|
|
44
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Creates an inline image node instance.
|
|
92
|
+
* @param src Image source URL.
|
|
93
|
+
* @param altText Accessible alt text.
|
|
94
|
+
* @param position Inline image alignment position.
|
|
95
|
+
* @param width Initial image width.
|
|
96
|
+
* @param height Initial image height.
|
|
97
|
+
* @param showCaption Whether the caption editor is visible.
|
|
98
|
+
* @param caption Nested caption editor.
|
|
99
|
+
* @param key Optional Lexical node key.
|
|
100
|
+
*/
|
|
45
101
|
constructor(src, altText, position, width, height, showCaption, caption, key) {
|
|
46
102
|
super(key);
|
|
47
103
|
this.__src = src;
|
|
@@ -52,14 +108,25 @@ export class InlineImageNode extends DecoratorNode {
|
|
|
52
108
|
this.__caption = caption || createEditor();
|
|
53
109
|
this.__position = position;
|
|
54
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Exports this inline image node to DOM.
|
|
113
|
+
* @returns DOM export output containing the inline image wrapper.
|
|
114
|
+
*/
|
|
55
115
|
exportDOM() {
|
|
116
|
+
const wrapper = document.createElement('span');
|
|
117
|
+
wrapper.className = `inline-editor-image position-${this.__position || 'center'}`;
|
|
56
118
|
const element = document.createElement('img');
|
|
57
119
|
element.setAttribute('src', this.__src);
|
|
58
120
|
element.setAttribute('alt', this.__altText);
|
|
59
121
|
element.setAttribute('width', this.__width.toString());
|
|
60
122
|
element.setAttribute('height', this.__height.toString());
|
|
61
|
-
|
|
123
|
+
wrapper.appendChild(element);
|
|
124
|
+
return { element: wrapper };
|
|
62
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Serializes this inline image node.
|
|
128
|
+
* @returns Serialized inline image node payload.
|
|
129
|
+
*/
|
|
63
130
|
exportJSON() {
|
|
64
131
|
return {
|
|
65
132
|
altText: this.getAltText(),
|
|
@@ -73,18 +140,48 @@ export class InlineImageNode extends DecoratorNode {
|
|
|
73
140
|
width: this.__width === 'inherit' ? 0 : this.__width,
|
|
74
141
|
};
|
|
75
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* Gets the image source URL.
|
|
145
|
+
* @returns Image source URL.
|
|
146
|
+
*/
|
|
76
147
|
getSrc() {
|
|
77
148
|
return this.__src;
|
|
78
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* Gets the image alt text.
|
|
152
|
+
* @returns Image alt text.
|
|
153
|
+
*/
|
|
79
154
|
getAltText() {
|
|
80
155
|
return this.__altText;
|
|
81
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Gets whether the caption editor is visible.
|
|
159
|
+
* @returns True when caption is shown.
|
|
160
|
+
*/
|
|
82
161
|
getShowCaption() {
|
|
83
162
|
return this.__showCaption;
|
|
84
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* Gets the current inline image alignment position.
|
|
166
|
+
* @returns Current inline image position.
|
|
167
|
+
*/
|
|
85
168
|
getPosition() {
|
|
86
169
|
return this.__position;
|
|
87
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Updates the stored image dimensions.
|
|
173
|
+
* @param width Next image width.
|
|
174
|
+
* @param height Next image height.
|
|
175
|
+
*/
|
|
176
|
+
setWidthAndHeight(width, height) {
|
|
177
|
+
const writable = this.getWritable();
|
|
178
|
+
writable.__width = width;
|
|
179
|
+
writable.__height = height;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Updates mutable inline image fields.
|
|
183
|
+
* @param payload Partial inline image update payload.
|
|
184
|
+
*/
|
|
88
185
|
update(payload) {
|
|
89
186
|
const writable = this.getWritable();
|
|
90
187
|
const { altText, position, showCaption } = payload;
|
|
@@ -99,32 +196,58 @@ export class InlineImageNode extends DecoratorNode {
|
|
|
99
196
|
}
|
|
100
197
|
}
|
|
101
198
|
// View
|
|
199
|
+
/**
|
|
200
|
+
* Creates the DOM wrapper for this inline image node.
|
|
201
|
+
* @param config Lexical editor config.
|
|
202
|
+
* @returns Inline image wrapper element.
|
|
203
|
+
*/
|
|
102
204
|
createDOM(config) {
|
|
103
205
|
const span = document.createElement('span');
|
|
104
|
-
const className = `${config.theme.inlineImage} position-${this.__position}`;
|
|
206
|
+
const className = `${config.theme.inlineImage} position-${this.__position || 'center'}`;
|
|
105
207
|
if (className !== undefined) {
|
|
106
208
|
span.className = className;
|
|
107
209
|
}
|
|
108
210
|
return span;
|
|
109
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* Updates the DOM wrapper when node state changes.
|
|
214
|
+
* @param prevNode Previous inline image node state.
|
|
215
|
+
* @param dom Existing inline image wrapper element.
|
|
216
|
+
* @param config Lexical editor config.
|
|
217
|
+
* @returns False because the existing DOM element is reused.
|
|
218
|
+
*/
|
|
110
219
|
updateDOM(prevNode, dom, config) {
|
|
111
220
|
const position = this.__position;
|
|
112
221
|
if (position !== prevNode.__position) {
|
|
113
|
-
const className = `${config.theme.inlineImage} position-${position}`;
|
|
222
|
+
const className = `${config.theme.inlineImage} position-${position || 'center'}`;
|
|
114
223
|
if (className !== undefined) {
|
|
115
224
|
dom.className = className;
|
|
116
225
|
}
|
|
117
226
|
}
|
|
118
227
|
return false;
|
|
119
228
|
}
|
|
229
|
+
/**
|
|
230
|
+
* Renders the React decorator for this inline image node.
|
|
231
|
+
* @returns Inline image decorator element.
|
|
232
|
+
*/
|
|
120
233
|
decorate() {
|
|
121
234
|
return (React.createElement(Suspense, { fallback: null },
|
|
122
235
|
React.createElement(InlineImageComponent, { altText: this.__altText, caption: this.__caption, height: this.__height, nodeKey: this.getKey(), position: this.__position, showCaption: this.__showCaption, src: this.__src, width: this.__width })));
|
|
123
236
|
}
|
|
124
237
|
}
|
|
238
|
+
/**
|
|
239
|
+
* Creates and inserts a replacement inline image node.
|
|
240
|
+
* @param payload Inline image node creation payload.
|
|
241
|
+
* @returns Created inline image node.
|
|
242
|
+
*/
|
|
125
243
|
export function $createInlineImageNode({ altText, caption, height, key, position, showCaption, src, width, }) {
|
|
126
|
-
return $applyNodeReplacement(new InlineImageNode(src, altText, position, width, height, showCaption, caption, key));
|
|
244
|
+
return $applyNodeReplacement(new InlineImageNode(src, altText, position || 'center', width, height, showCaption, caption, key));
|
|
127
245
|
}
|
|
246
|
+
/**
|
|
247
|
+
* Checks whether a Lexical node is an InlineImageNode.
|
|
248
|
+
* @param node Node to test.
|
|
249
|
+
* @returns True when the node is an InlineImageNode.
|
|
250
|
+
*/
|
|
128
251
|
export function $isInlineImageNode(node) {
|
|
129
252
|
return node instanceof InlineImageNode;
|
|
130
253
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InlineImageNode.js","sourceRoot":"","sources":["../../../../../src/components/TextEditorV2/nodes/InlineImageNode.tsx"],"names":[],"mappings":"AAYA,OAAO,EA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AC;gBAC5B,GAAG,CAAC,SAAS,GAAG,SAAS,CAAA;YAC3B,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAA;IACd,CAAC;IAED;;;OAGG;IACI,QAAQ;QACb,OAAO,CACL,oBAAC,QAAQ,IAAC,QAAQ,EAAE,IAAI;YACtB,oBAAC,oBAAoB,IACnB,OAAO,EAAE,IAAI,CAAC,SAAS,EACvB,OAAO,EAAE,IAAI,CAAC,SAAS,EACvB,MAAM,EAAE,IAAI,CAAC,QAAQ,EACrB,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,EACtB,QAAQ,EAAE,IAAI,CAAC,UAAU,EACzB,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,sBAAsB,CAAC,EACrC,OAAO,EACP,OAAO,EACP,MAAM,EACN,GAAG,EACH,QAAQ,EACR,WAAW,EACX,GAAG,EACH,KAAK,GACc;IACnB,OAAO,qBAAqB,CAC1B,IAAI,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,IAAI,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,CAAC,CAClG,CAAA;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAoC;IACrE,OAAO,IAAI,YAAY,eAAe,CAAA;AACxC,CAAC"}
|
|
@@ -46,6 +46,8 @@ export class MentionNode extends TextNode {
|
|
|
46
46
|
}
|
|
47
47
|
exportDOM() {
|
|
48
48
|
const element = document.createElement('span');
|
|
49
|
+
element.className = 'mention';
|
|
50
|
+
element.style.cssText = mentionStyle;
|
|
49
51
|
element.setAttribute('data-lexical-mention', 'true');
|
|
50
52
|
element.textContent = this.__text;
|
|
51
53
|
return { element };
|