Skip to content

Commit c4a5aae

Browse files
authored
Merge pull request #50 from gambitph/fix/editor-dropzone
fix: reroute file drop to Gutenberg dropzone
2 parents a1406d4 + 14871a6 commit c4a5aae

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/admin/js/media-manager/drop-zone.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const ALLOWED_LOCATIONS = applyFilters( 'cimo.dropZone.allowedLocations', [
2525
'.editor-styles-wrapper', // Allowed to drop in the block editor when adding new image blocks
2626
'.uploader-window', // Allowed to drop in the admin Media > Library grid view
2727
'.uploader-editor', // Allowed to drop in the WooCommerce description editor
28+
'.block-library-utils__media-control', // Allowed to drop in the block editor image block media control
2829
] )
2930

3031
// Add event listener to the Media Manager's drop zone
@@ -140,7 +141,7 @@ function addDropZoneListenerToMediaManager( targetDocument ) {
140141
await saveMetadata( conversionMetadata )
141142

142143
// Find the correct target to dispatch the event to
143-
let target = event.target
144+
let target = event.target.closest( '.components-drop-zone, [data-is-drop-zone="true"]' ) || event.target
144145
// This specifically handles the WooCommerce/classic description editor
145146
if ( event.target?.closest( '.uploader-editor-content' ) ) {
146147
target = event.target.closest( '.uploader-editor-content' )
@@ -154,7 +155,7 @@ function addDropZoneListenerToMediaManager( targetDocument ) {
154155
// inside the DropZoneComponent.
155156
//
156157
// @see https://github.com/WordPress/gutenberg/blob/f8140c4fcc8db2d6078ad76fd433c79df3543860/packages/components/src/drop-zone/index.tsx#L59
157-
if ( target?.classList.contains( 'components-drop-zone' ) || target?.classList.contains( 'uploader-editor-content' ) ) {
158+
if ( target?.classList.contains( 'components-drop-zone' ) || target?.getAttribute( 'data-is-drop-zone' ) === 'true' || target?.classList.contains( 'uploader-editor-content' ) ) {
158159
// Create a drop event with conditional bubbling
159160
// Use bubbles: false when in iframe to prevent doubling, but true for main document
160161
const isInIframe = targetDocument !== document

0 commit comments

Comments
 (0)