Skip to content

Commit

Permalink
Merge pull request #3728 from udecode/fix/insertMedia
Browse files Browse the repository at this point in the history
Fix/insert media
  • Loading branch information
felixfeng33 authored Nov 5, 2024
2 parents 20f5459 + 494d9da commit d1f3051
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/serious-spoons-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@udecode/plate-media': patch
---

Fix can't drop
5 changes: 3 additions & 2 deletions packages/media/src/react/placeholder/PlaceholderPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
bindFirst,
getAncestorNode,
getNodeString,
removeNodes,
} from '@udecode/plate-common';
import { findEventRange, toTPlatePlugin } from '@udecode/plate-common/react';

Expand Down Expand Up @@ -117,6 +118,7 @@ export const PlaceholderPlugin = toTPlatePlugin<
handlers: {
onDrop: ({ editor, event, tf }) => {
// using DnD plugin by default
if (!getOption('disabledDndPlugin')) return;

const { files } = event.dataTransfer;

Expand All @@ -126,8 +128,6 @@ export const PlaceholderPlugin = toTPlatePlugin<
event.preventDefault();
event.stopPropagation();

if (!getOption('disabledDndPlugin')) return;

/**
* When we drop a file, the selection won't move automatically to the
* drop location. Find the location from the event and upload the files
Expand Down Expand Up @@ -156,6 +156,7 @@ export const PlaceholderPlugin = toTPlatePlugin<
const [node, path] = ancestor;

if (getNodeString(node).length === 0) {
removeNodes(editor, { at: path });
tf.insert.media(files, path);
inserted = true;
}
Expand Down

0 comments on commit d1f3051

Please sign in to comment.