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 {
$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;
}
};

View File

@ -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