Lexical: Got working with attachment insert/drop

This commit is contained in:
Dan Brown 2024-07-29 21:14:42 +01:00
parent 9a7edc6e52
commit d86837ac07
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
2 changed files with 14 additions and 8 deletions

View File

@ -1,7 +1,4 @@
import { import {
$getNearestNodeFromDOMNode,
$getRoot,
$insertNodes,
$isDecoratorNode, $isDecoratorNode,
LexicalEditor, LexicalEditor,
LexicalNode LexicalNode
@ -9,7 +6,7 @@ import {
import { import {
$getNearestBlockNodeForCoords, $getNearestBlockNodeForCoords,
$htmlToBlockNodes, $htmlToBlockNodes,
$insertNewBlockNodeAtSelection, $insertNewBlockNodesAtSelection, $insertNewBlockNodesAtSelection,
$selectSingleNode $selectSingleNode
} from "./helpers"; } from "./helpers";
@ -54,8 +51,19 @@ function createDropListener(editor: LexicalEditor): (event: DragEvent) => void {
// Template handling // Template handling
const templateId = event.dataTransfer?.getData('bookstack/template') || ''; const templateId = event.dataTransfer?.getData('bookstack/template') || '';
if (templateId) { if (templateId) {
event.preventDefault();
insertTemplateToEditor(editor, templateId, event); 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; return;
} }
}; };

View File

@ -2,7 +2,7 @@
## In progress ## In progress
// - Draft/change management (connect with page editor component)
## Main Todo ## Main Todo
@ -11,9 +11,7 @@
- Table features - Table features
- Image paste upload - Image paste upload
- Keyboard shortcuts support - Keyboard shortcuts support
- Draft/change management (connect with page editor component)
- Add ID support to all block types - Add ID support to all block types
- Video attachment drop / insert
- Task list render/import from existing format - Task list render/import from existing format
- Link popup menu for cross-content reference - Link popup menu for cross-content reference
- Link heading-based ID reference menu - Link heading-based ID reference menu