import {
+ $createParagraphNode,
$insertNodes,
$isDecoratorNode, COMMAND_PRIORITY_HIGH, DROP_COMMAND,
LexicalEditor,
import {$insertNewBlockNodesAtSelection, $selectSingleNode} from "../utils/selection";
import {$getNearestBlockNodeForCoords, $htmlToBlockNodes} from "../utils/nodes";
import {Clipboard} from "../../services/clipboard";
-import {$createImageNode} from "../nodes/image";
-import {$createCustomParagraphNode} from "../nodes/custom-paragraph";
+import {$createImageNode} from "@lexical/rich-text/LexicalImageNode";
import {$createLinkNode} from "@lexical/link";
import {EditorImageData, uploadImageFile} from "../utils/images";
import {EditorUiContext} from "../ui/framework/core";
for (const imageFile of images) {
const loadingImage = window.baseUrl('/loading.gif');
const loadingNode = $createImageNode(loadingImage);
- const imageWrap = $createCustomParagraphNode();
+ const imageWrap = $createParagraphNode();
imageWrap.append(loadingNode);
$insertNodes([imageWrap]);
return handled;
}
+function handleImageLinkInsert(data: DataTransfer, context: EditorUiContext): boolean {
+ const regex = /https?:\/\/([^?#]*?)\.(png|jpeg|jpg|gif|webp|bmp|avif)/i
+ const text = data.getData('text/plain');
+ if (text && regex.test(text)) {
+ context.editor.update(() => {
+ const image = $createImageNode(text);
+ $insertNodes([image]);
+ image.select();
+ });
+ return true;
+ }
+
+ return false;
+}
+
function createDropListener(context: EditorUiContext): (event: DragEvent) => boolean {
const editor = context.editor;
return (event: DragEvent): boolean => {
return false;
}
- const handled = handleMediaInsert(event.clipboardData, context);
+ const handled =
+ handleImageLinkInsert(event.clipboardData, context) ||
+ handleMediaInsert(event.clipboardData, context);
+
if (handled) {
event.preventDefault();
}