From d86837ac07fdb5e68b02a57ca6d75fd6047bdfee Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Mon, 29 Jul 2024 21:14:42 +0100 Subject: [PATCH] Lexical: Got working with attachment insert/drop --- resources/js/wysiwyg/drop-handling.ts | 18 +++++++++++++----- resources/js/wysiwyg/todo.md | 4 +--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/resources/js/wysiwyg/drop-handling.ts b/resources/js/wysiwyg/drop-handling.ts index 92dc758d8..5d541365a 100644 --- a/resources/js/wysiwyg/drop-handling.ts +++ b/resources/js/wysiwyg/drop-handling.ts @@ -1,7 +1,4 @@ import { - $getNearestNodeFromDOMNode, - $getRoot, - $insertNodes, $isDecoratorNode, LexicalEditor, LexicalNode @@ -9,7 +6,7 @@ import { import { $getNearestBlockNodeForCoords, $htmlToBlockNodes, - $insertNewBlockNodeAtSelection, $insertNewBlockNodesAtSelection, + $insertNewBlockNodesAtSelection, $selectSingleNode } from "./helpers"; @@ -54,8 +51,19 @@ function createDropListener(editor: LexicalEditor): (event: DragEvent) => void { // Template handling const templateId = event.dataTransfer?.getData('bookstack/template') || ''; if (templateId) { - event.preventDefault(); insertTemplateToEditor(editor, templateId, event); + event.preventDefault(); + return; + } + + // HTML contents drop + const html = event.dataTransfer?.getData('text/html') || ''; + if (html) { + editor.update(() => { + const newNodes = $htmlToBlockNodes(editor, html); + $insertNodesAtEvent(newNodes, event, editor); + }); + event.preventDefault(); return; } }; diff --git a/resources/js/wysiwyg/todo.md b/resources/js/wysiwyg/todo.md index 5d495e7d8..73521df9b 100644 --- a/resources/js/wysiwyg/todo.md +++ b/resources/js/wysiwyg/todo.md @@ -2,7 +2,7 @@ ## In progress -// +- Draft/change management (connect with page editor component) ## Main Todo @@ -11,9 +11,7 @@ - Table features - Image paste upload - Keyboard shortcuts support -- Draft/change management (connect with page editor component) - Add ID support to all block types -- Video attachment drop / insert - Task list render/import from existing format - Link popup menu for cross-content reference - Link heading-based ID reference menu